From 2b92d28b8966f3f93fe814768d63098cc8990118 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Mon, 18 Nov 2019 16:16:49 +0100 Subject: [PATCH] Fixed issue #2808 - Unprocessable mail if follow up search is enabled for attachments with contains invalid charsets (postmaster_follow_up_search_in with attachment). --- app/models/channel/filter/follow_up_check.rb | 7 +- spec/models/channel/email_parser_spec.rb | 12 +++ test/data/mail/mail085.box | 80 ++++++++++++++++++++ 3 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 test/data/mail/mail085.box diff --git a/app/models/channel/filter/follow_up_check.rb b/app/models/channel/filter/follow_up_check.rb index 14a6ed6a1..f0c048549 100644 --- a/app/models/channel/filter/follow_up_check.rb +++ b/app/models/channel/filter/follow_up_check.rb @@ -34,7 +34,12 @@ module Channel::Filter::FollowUpCheck next if attachment[:preferences]['Mime-Type'].blank? if %r{text/html}i.match?(attachment[:preferences]['Mime-Type']) - ticket = Ticket::Number.check(attachment[:data].html2text) + begin + text = attachment[:data].html2text + ticket = Ticket::Number.check(text) + rescue => e + Rails.logger.error e + end end if %r{text/plain}i.match?(attachment[:preferences]['Mime-Type']) diff --git a/spec/models/channel/email_parser_spec.rb b/spec/models/channel/email_parser_spec.rb index eae580e7c..32a2acdf5 100644 --- a/spec/models/channel/email_parser_spec.rb +++ b/spec/models/channel/email_parser_spec.rb @@ -943,6 +943,18 @@ RSpec.describe Channel::EmailParser, type: :model do .not_to raise_error end end + + context 'when attachment for follow up check contains invalid charsets (#2808)' do + let(:mail_file) { Rails.root.join('test', 'data', 'mail', 'mail085.box') } + + before { Setting.set('postmaster_follow_up_search_in', %w[attachment body]) } + + it 'does not raise Encoding::CompatibilityError:' do + expect { described_class.new.process({}, raw_mail) } + .not_to raise_error + end + end + end describe 'attachment handling' do diff --git a/test/data/mail/mail085.box b/test/data/mail/mail085.box new file mode 100644 index 000000000..4f491da8e --- /dev/null +++ b/test/data/mail/mail085.box @@ -0,0 +1,80 @@ +Return-Path: +From: Bob Smith +Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) +Content-Type: multipart/alternative; + boundary="Apple-Mail=_E59F63A4-B0CE-4985-BD59-45DAA0F6596C" +X-Priority: 3 +Subject: =?utf-8?Q?Re=3A_buy_-_Wir_freuen_uns_=C3=BCber_Deine_kurze_Be?= + =?utf-8?Q?wertung!_=231XXXX9?= +Date: Wed, 13 Nov 2019 12:11:56 +0100 +References: <01cf9cbc1a5d1b6f2bd07b26a2bbb896@www.example.com> +To: "Support GmbH" +In-Reply-To: <01cf9cbc1a5d1b6f2bd07b26a2bbb896@www.example.com> +Message-Id: <4A8DD423-FC24-4CC5-8996-4E27A57BA774@example.com> +X-Mailer: Apple Mail (2.3445.104.11) +Envelope-To: +X-Spam-Flag: NO + + +--Apple-Mail=_E59F63A4-B0CE-4985-BD59-45DAA0F6596C +Content-Transfer-Encoding: quoted-printable +Content-Type: text/plain; + charset=utf-8 + +Liebes Team, + +Mit freundlichen Gr=C3=BC=C3=9Fen +_____________________________________ + +Office Management =20 + + +--Apple-Mail=_E59F63A4-B0CE-4985-BD59-45DAA0F6596C +Content-Type: multipart/mixed; + boundary="Apple-Mail=_E53D4560-0E2F-48BE-B7E3-427332B2933C" + + +--Apple-Mail=_E53D4560-0E2F-48BE-B7E3-427332B2933C +Content-Transfer-Encoding: quoted-printable +Content-Type: text/html; + charset=utf-8 + +123 + +--Apple-Mail=_E53D4560-0E2F-48BE-B7E3-427332B2933C +Content-Transfer-Encoding: quoted-printable +Content-Type: text/html; + charset=utf-8 + + +
_____________________________________

11111 Someware

Telefon: +49.(0) = +30.1234
Fax: +49.(0) 30.1234
+HRB 12345 B

Gesch=C3=A4ftsf=C3=BChrung: = +Bob Smith
+ +

+
+
+ + + + + +
+
+Dann w=C3=BCrden wir uns unheimlich freuen, wenn Du Dir +
+
+ +

= + +--Apple-Mail=_E53D4560-0E2F-48BE-B7E3-427332B2933C-- + +--Apple-Mail=_E59F63A4-B0CE-4985-BD59-45DAA0F6596C--