Browse Source

Fixes #4152 - Unable to process email with invalid Resent-Date header

Tobias Schäfer 2 years ago
parent
commit
be59f7161d
2 changed files with 17 additions and 0 deletions
  1. 4 0
      app/models/channel/email_parser.rb
  2. 13 0
      spec/models/channel/email_parser_spec.rb

+ 4 - 0
app/models/channel/email_parser.rb

@@ -578,6 +578,10 @@ process unprocessable_mails (tmp/unprocessable_mail/*.eml) again
 
         f.value = try_iso88591
         value = f.decoded.to_utf8
+      rescue Date::Error => e
+        raise e if !f.name.eql?('Resent-Date')
+
+        f.value = ''
       rescue
         value = f.decoded.to_utf8(fallback: :read_as_sanitized_binary)
       end

+ 13 - 0
spec/models/channel/email_parser_spec.rb

@@ -78,6 +78,19 @@ RSpec.describe Channel::EmailParser, type: :model do
       it { expect(parsed['body']).to eq '<div>このアドレスへのメルマガを解除してください。</div>' }
       it { expect(parsed['subject']).to eq 'メルマガ解除' }
     end
+
+    describe "invalid 'Resent-Date' header field" do
+      it 'is ignored' do
+        expect(described_class.new.parse(<<~RAW)['resent_date']).to be_nil
+          From: me@example.com
+          To: to@example.com
+          Subject: 123
+          Resent-Date: 6/29/2022 11:57:13 AM
+
+          body 123
+        RAW
+      end
+    end
   end
 
   describe '#process' do