From 9a7118123dc993cd52bec4b5ad81d4e85b72e86f Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Thu, 20 Sep 2018 18:54:54 +0200 Subject: [PATCH] Fixed issue #2245 - Unable to process spam mail with invalid date field. --- app/models/channel/email_parser.rb | 8 ++++++-- test/data/mail/mail074.box | 15 +++++++++++++++ test/data/mail/mail074.yml | 16 ++++++++++++++++ 3 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 test/data/mail/mail074.box create mode 100644 test/data/mail/mail074.yml diff --git a/app/models/channel/email_parser.rb b/app/models/channel/email_parser.rb index 1d498ed6c..049f5fb02 100644 --- a/app/models/channel/email_parser.rb +++ b/app/models/channel/email_parser.rb @@ -495,9 +495,13 @@ process unprocessable_mails (tmp/unprocessable_mail/*.eml) again .transform_values { |v| v.match?(EMAIL_REGEX) ? v : '' }) h['x-any-recipient'] = h.values.select(&:present?).join(', ') - h['date'] = Time.zone.parse(mail.date.to_s) || imported_fields['date'] h['message_id'] = imported_fields['message-id'] - h['subject'] = imported_fields['subject']&.sub(/^=\?us-ascii\?Q\?(.+)\?=$/, '\1') + h['subject'] = imported_fields['subject']&.sub(/^=\?us-ascii\?Q\?(.+)\s*\?=\s*$/, '\1') + begin + h['date'] = Time.zone.parse(mail.date.to_s) || imported_fields['date'] + rescue + h['date'] = nil + end end [imported_fields, raw_fields, custom_fields].reduce({}.with_indifferent_access, &:merge) diff --git a/test/data/mail/mail074.box b/test/data/mail/mail074.box new file mode 100644 index 000000000..b117a3dbe --- /dev/null +++ b/test/data/mail/mail074.box @@ -0,0 +1,15 @@ +From: Martin Edenhofer +Subject: Test with different content type file name options +Date: Wed, 05 Sep 2018 29:24:05 +0700 +Message-Id: <4C4ECFBF-BA12-46D9-A407-8E873F20DEF3X@example.de> +To: me@example.de +Content-Transfer-Encoding: 7bit +Content-Type: text/plain; + charset=us-ascii + +Enjoy! + +-Martin + +-- +Old programmers never die. They just branch to a new address. diff --git a/test/data/mail/mail074.yml b/test/data/mail/mail074.yml new file mode 100644 index 000000000..20e061b6a --- /dev/null +++ b/test/data/mail/mail074.yml @@ -0,0 +1,16 @@ +--- !ruby/hash:ActiveSupport::HashWithIndifferentAccess +from: Martin Edenhofer +from_email: martin@example.de +from_display_name: Martin Edenhofer +date: +to: me@example.de +subject: Test with different content type file name options +body: | + Enjoy! + + -Martin + + -- + Old programmers never die. They just branch to a new address. +content_type: text/plain +attachments: []