Fixes #3697 - Mix of binary encoded ISO-8859-1 data in header fields (e.g. to) fails mail processing
This commit is contained in:
parent
2d6d15f9be
commit
8b5596647a
3 changed files with 34 additions and 6 deletions
|
@ -563,17 +563,20 @@ process unprocessable_mails (tmp/unprocessable_mail/*.eml) again
|
||||||
imported_fields = mail.header.fields.map do |f|
|
imported_fields = mail.header.fields.map do |f|
|
||||||
begin
|
begin
|
||||||
value = if f.value.match?(ISO2022JP_REGEXP)
|
value = if f.value.match?(ISO2022JP_REGEXP)
|
||||||
header_field_unpack_japanese(f)
|
value = header_field_unpack_japanese(f)
|
||||||
else
|
else
|
||||||
f.to_utf8
|
f.decoded.to_utf8
|
||||||
end
|
|
||||||
|
|
||||||
if value.blank?
|
|
||||||
value = f.decoded.to_utf8
|
|
||||||
end
|
end
|
||||||
# fields that cannot be cleanly parsed fallback to the empty string
|
# fields that cannot be cleanly parsed fallback to the empty string
|
||||||
rescue Mail::Field::IncompleteParseError
|
rescue Mail::Field::IncompleteParseError
|
||||||
value = ''
|
value = ''
|
||||||
|
rescue Encoding::CompatibilityError => e
|
||||||
|
try_iso88591 = f.value.force_encoding('iso-8859-1').encode('utf-8')
|
||||||
|
|
||||||
|
raise e if !try_iso88591.is_utf8?
|
||||||
|
|
||||||
|
f.value = try_iso88591
|
||||||
|
value = f.decoded.to_utf8
|
||||||
rescue
|
rescue
|
||||||
value = f.decoded.to_utf8(fallback: :read_as_sanitized_binary)
|
value = f.decoded.to_utf8(fallback: :read_as_sanitized_binary)
|
||||||
end
|
end
|
||||||
|
|
16
test/data/mail/mail105.box
Normal file
16
test/data/mail/mail105.box
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
From: Martin Edenhofer <martin@example.com>
|
||||||
|
Content-Transfer-Encoding: quoted-printable
|
||||||
|
Subject: =?iso-8859-1?Q?aa=E4=F6=FC=DFad_asd?=
|
||||||
|
X-Universally-Unique-Identifier: d12c15d2-e6d6-4ccd-86c7-abc2c3d0a2a2
|
||||||
|
Date: Fri, 4 May 2012 14:01:03 +0200
|
||||||
|
Message-Id: <BC182994-03FA-4DC5-8202-98CBFACA0887@example.com>
|
||||||
|
To: metest@znuny.com, "=?iso-8859-1?Q?G=FCnther_John_=7C_Example_GmbH?=" <k.günther@example.com>
|
||||||
|
Mime-Version: 1.0 (Apple Message framework v1257)
|
||||||
|
Content-Type: multipart/mixed; boundary="----_=_NextPart_000_03BED81D.6103DF93"
|
||||||
|
|
||||||
|
=E4=F6=FC=DF ad asd
|
||||||
|
|
||||||
|
-Martin
|
||||||
|
|
||||||
|
--
|
||||||
|
Old programmers never die. They just branch to a new address.
|
9
test/data/mail/mail105.yml
Normal file
9
test/data/mail/mail105.yml
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
--- !ruby/hash:ActiveSupport::HashWithIndifferentAccess
|
||||||
|
from: Martin Edenhofer <martin@example.com>
|
||||||
|
from_email: martin@example.com
|
||||||
|
from_display_name: Martin Edenhofer
|
||||||
|
to: metest@znuny.com, "Günther John | Example GmbH" <k.günther@example.com>
|
||||||
|
subject: aaäöüßad asd
|
||||||
|
body: no visible content
|
||||||
|
content_type: text/plain
|
||||||
|
attachments: []
|
Loading…
Reference in a new issue