Browse Source

Fixed issue #2808 - Unprocessable mail if follow up search is enabled for attachments with contains invalid charsets (postmaster_follow_up_search_in with attachment).

Martin Edenhofer 5 years ago
parent
commit
2b92d28b89

+ 6 - 1
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'])

+ 12 - 0
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

+ 80 - 0
test/data/mail/mail085.box

@@ -0,0 +1,80 @@
+Return-Path: <bob.smith@example.com>
+From: Bob Smith <bob.smith@example.com>
+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" <kaufs@example.com>
+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: <kaufs@example.com>
+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
+
+<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html; =
+charset=2Dutf-8"></head><body>
+<div>_____________________________________</div><div><br =
+class=3D"">11111 Someware<br class=3D""><br class=3D"">Telefon: +49.(0) =
+30.1234<br class=3D"">Fax: +49.(0) 30.1234<br class=3D"">
+HRB 12345 B<br class=3D""><br class=3D"">Gesch=C3=A4ftsf=C3=BChrung: =
+Bob Smith</div></div></div>
+</div>
+<div><br class=3D""><blockquote type=3D"cite" class=3D"">
+<div class=3D"">
+    <div class=3D"">
+    <table border=3D"0" cellspacing=3D"0" cellpadding=3D"0" width=3D"600" =
+class=3D"">
+        <tbody class=3D""><tr class=3D"">
+        <tr class=3D"">
+            <td style=3D"font-family: Arial, Helvetica, =
+sans-serif;font-size: 12px;line-height:18px;color:#333" class=3D""><div =
+Antworte  einfach auf diese E-Mail und schildere kurz, was passiert ist, =
+damit wir uns verbessern k=C3=B6nnen!<br class=3D"">
+<br class=3D"">
+Dann w=C3=BCrden wir uns unheimlich freuen, wenn Du Dir <strong =
+class=3D"">
+            </td>
+        </tr>
+    </tbody></table>
+    </div>
+
+</div></blockquote></div><br class=3D""></div></body></html>=
+
+--Apple-Mail=_E53D4560-0E2F-48BE-B7E3-427332B2933C--
+
+--Apple-Mail=_E59F63A4-B0CE-4985-BD59-45DAA0F6596C--