Support processing of emails with Windows-1258 encoding (fixes #2224)
This commit is contained in:
parent
d9528438bc
commit
fa678f938a
3 changed files with 200 additions and 4 deletions
|
@ -476,11 +476,11 @@ class String
|
||||||
def utf8_encode!(**options)
|
def utf8_encode!(**options)
|
||||||
return force_encoding('utf-8') if dup.force_encoding('utf-8').valid_encoding?
|
return force_encoding('utf-8') if dup.force_encoding('utf-8').valid_encoding?
|
||||||
|
|
||||||
viable_encodings(try_first: options[:from]).each do |e|
|
viable_encodings(try_first: options[:from]).each do |enc|
|
||||||
begin
|
begin
|
||||||
return encode!('utf-8', e)
|
return encode!('utf-8', enc)
|
||||||
rescue Encoding::UndefinedConversionError
|
rescue EncodingError => e
|
||||||
nil
|
Rails.logger.error { e.inspect }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -70,5 +70,15 @@ RSpec.describe Channel::EmailParser, type: :model do
|
||||||
.and include('mail_delivery_failed_data' => a_kind_of(ActiveSupport::TimeWithZone))
|
.and include('mail_delivery_failed_data' => a_kind_of(ActiveSupport::TimeWithZone))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# see https://github.com/zammad/zammad/issues/2224
|
||||||
|
context 'when header specifies Windows-1258 charset (#2224)' do
|
||||||
|
let(:mail_file) { Rails.root.join('test', 'data', 'mail', 'mail072.box') }
|
||||||
|
|
||||||
|
it 'does not raise Encoding::ConverterNotFoundError' do
|
||||||
|
expect { described_class.new.process({}, raw_mail) }
|
||||||
|
.not_to raise_error
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
186
test/data/mail/mail072.box
Normal file
186
test/data/mail/mail072.box
Normal file
|
@ -0,0 +1,186 @@
|
||||||
|
From: =?windows-1258?Q?Val=E9rie_Oury?= <me@example.com>
|
||||||
|
To: "'service@example.com'" <service@example.com>
|
||||||
|
Subject: =?windows-1258?Q?R=E9clamation_commande_n=B0_018255977840?=
|
||||||
|
Thread-Topic: =?windows-1258?Q?R=E9clamation_commande_n=B0_018255977840?=
|
||||||
|
Thread-Index: AdRDjTg4wtjSD1tVQUil+NlifXlcvg==
|
||||||
|
Date: Mon, 3 Sep 2018 14:11:04 +0000
|
||||||
|
Message-ID: <077a50fe57b04807bfa82f909aeacba9@example.com>
|
||||||
|
Accept-Language: fr-FR, en-US
|
||||||
|
Content-Language: en-US
|
||||||
|
X-MS-Has-Attach: yes
|
||||||
|
X-MS-TNEF-Correlator:
|
||||||
|
Content-Type: multipart/related;
|
||||||
|
boundary="_006_077a50fe57b04807bfa82f909aeacba9lexfieldcom_";
|
||||||
|
type="multipart/alternative"
|
||||||
|
MIME-Version: 1.0
|
||||||
|
|
||||||
|
--_006_077a50fe57b04807bfa82f909aeacba9lexfieldcom_
|
||||||
|
Content-Type: multipart/alternative;
|
||||||
|
boundary="_000_077a50fe57b04807bfa82f909aeacba9lexfieldcom_"
|
||||||
|
|
||||||
|
--_000_077a50fe57b04807bfa82f909aeacba9lexfieldcom_
|
||||||
|
Content-Type: text/plain; charset="windows-1258"
|
||||||
|
Content-Transfer-Encoding: quoted-printable
|
||||||
|
|
||||||
|
Bonjour,
|
||||||
|
|
||||||
|
Je vous contacte suite =E0 ma commande du 14 ao=FBt 2018 r=E9f=E9renc=E9e c=
|
||||||
|
i-dessus.
|
||||||
|
|
||||||
|
Cordialement,
|
||||||
|
|
||||||
|
[XXXX]
|
||||||
|
|
||||||
|
|
||||||
|
--_000_077a50fe57b04807bfa82f909aeacba9lexfieldcom_
|
||||||
|
Content-Type: text/html; charset="windows-1258"
|
||||||
|
Content-Transfer-Encoding: quoted-printable
|
||||||
|
|
||||||
|
<html xmlns:v=3D"urn:schemas-microsoft-com:vml" xmlns:o=3D"urn:schemas-micr=
|
||||||
|
osoft-com:office:office" xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
|
||||||
|
xmlns:m=3D"http://schemas.microsoft.com/office/2004/12/omml" xmlns=3D"http:=
|
||||||
|
//www.w3.org/TR/REC-html40">
|
||||||
|
<head>
|
||||||
|
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dwindows-1=
|
||||||
|
258">
|
||||||
|
<meta name=3D"Generator" content=3D"Microsoft Word 15 (filtered medium)">
|
||||||
|
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
|
||||||
|
o\:* {behavior:url(#default#VML);}
|
||||||
|
w\:* {behavior:url(#default#VML);}
|
||||||
|
.shape {behavior:url(#default#VML);}
|
||||||
|
</style><![endif]--><style><!--
|
||||||
|
/* Font Definitions */
|
||||||
|
@font-face
|
||||||
|
{font-family:"Cambria Math";
|
||||||
|
panose-1:2 4 5 3 5 4 6 3 2 4;}
|
||||||
|
@font-face
|
||||||
|
{font-family:Calibri;
|
||||||
|
panose-1:2 15 5 2 2 2 4 3 2 4;}
|
||||||
|
/* Style Definitions */
|
||||||
|
p.MsoNormal, li.MsoNormal, div.MsoNormal
|
||||||
|
{margin:0cm;
|
||||||
|
margin-bottom:.0001pt;
|
||||||
|
font-size:11.0pt;
|
||||||
|
font-family:"Calibri",sans-serif;
|
||||||
|
mso-fareast-language:EN-US;}
|
||||||
|
a:link, span.MsoHyperlink
|
||||||
|
{mso-style-priority:99;
|
||||||
|
color:#0563C1;
|
||||||
|
text-decoration:underline;}
|
||||||
|
a:visited, span.MsoHyperlinkFollowed
|
||||||
|
{mso-style-priority:99;
|
||||||
|
color:#954F72;
|
||||||
|
text-decoration:underline;}
|
||||||
|
span.EmailStyle17
|
||||||
|
{mso-style-type:personal-compose;
|
||||||
|
font-family:"Arial",sans-serif;
|
||||||
|
color:windowtext;}
|
||||||
|
.MsoChpDefault
|
||||||
|
{mso-style-type:export-only;
|
||||||
|
font-family:"Calibri",sans-serif;
|
||||||
|
mso-fareast-language:EN-US;}
|
||||||
|
@page WordSection1
|
||||||
|
{size:612.0pt 792.0pt;
|
||||||
|
margin:70.85pt 70.85pt 70.85pt 70.85pt;}
|
||||||
|
div.WordSection1
|
||||||
|
{page:WordSection1;}
|
||||||
|
--></style><!--[if gte mso 9]><xml>
|
||||||
|
<o:shapedefaults v:ext=3D"edit" spidmax=3D"1026" />
|
||||||
|
</xml><![endif]--><!--[if gte mso 9]><xml>
|
||||||
|
<o:shapelayout v:ext=3D"edit">
|
||||||
|
<o:idmap v:ext=3D"edit" data=3D"1" />
|
||||||
|
</o:shapelayout></xml><![endif]-->
|
||||||
|
</head>
|
||||||
|
<body lang=3D"FR-BE" link=3D"#0563C1" vlink=3D"#954F72">
|
||||||
|
<div class=3D"WordSection1">
|
||||||
|
<p class=3D"MsoNormal"><span style=3D"font-size:10.0pt;font-family:"Ar=
|
||||||
|
ial",sans-serif">Bonjour,
|
||||||
|
<o:p></o:p></span></p>
|
||||||
|
<p class=3D"MsoNormal"><span style=3D"font-size:10.0pt;font-family:"Ar=
|
||||||
|
ial",sans-serif"><o:p> </o:p></span></p>
|
||||||
|
<p class=3D"MsoNormal"><span style=3D"font-size:10.0pt;font-family:"Ar=
|
||||||
|
ial",sans-serif">Je vous contacte suite =E0 ma commande du 14 ao=FBt 2=
|
||||||
|
018 r=E9f=E9renc=E9e ci-dessus.<o:p></o:p></span></p>
|
||||||
|
<p class=3D"MsoNormal"><span style=3D"font-size:10.0pt;font-family:"Ar=
|
||||||
|
ial",sans-serif"><o:p> </o:p></span></p>
|
||||||
|
<p class=3D"MsoNormal"><span style=3D"font-size:10.0pt;font-family:"Ar=
|
||||||
|
ial",sans-serif">  =
|
||||||
|
; &n=
|
||||||
|
bsp;  =
|
||||||
|
; &n=
|
||||||
|
bsp;  =
|
||||||
|
; &n=
|
||||||
|
bsp;  =
|
||||||
|
; &n=
|
||||||
|
bsp;  =
|
||||||
|
; &n=
|
||||||
|
bsp;  =
|
||||||
|
; &n=
|
||||||
|
bsp;
|
||||||
|
<o:p></o:p></span></p>
|
||||||
|
<p class=3D"MsoNormal"><span style=3D"font-size:12.0pt;font-family:"Ti=
|
||||||
|
mes New Roman",serif;mso-fareast-language:FR-BE"><o:p> </o:p></sp=
|
||||||
|
an></p>
|
||||||
|
<p class=3D"MsoNormal"><span style=3D"font-size:10.0pt;font-family:"Ar=
|
||||||
|
ial",sans-serif">Je vous remercie d=92avance.<o:p></o:p></span></p>
|
||||||
|
<p class=3D"MsoNormal"><span style=3D"font-size:10.0pt;font-family:"Ar=
|
||||||
|
ial",sans-serif"><o:p> </o:p></span></p>
|
||||||
|
<p class=3D"MsoNormal"><span style=3D"font-size:10.0pt;font-family:"Ar=
|
||||||
|
ial",sans-serif">Cordialement,<o:p></o:p></span></p>
|
||||||
|
<p class=3D"MsoNormal"><span style=3D"font-size:10.0pt;font-family:"Ar=
|
||||||
|
ial",sans-serif"><o:p> </o:p></span></p>
|
||||||
|
<p class=3D"MsoNormal"><span style=3D"font-size:10.0pt;font-family:"Ar=
|
||||||
|
ial",sans-serif"><o:p> </o:p></span></p>
|
||||||
|
<table class=3D"MsoNormalTable" border=3D"1" cellspacing=3D"0" cellpadding=
|
||||||
|
=3D"0" style=3D"border:none;border-bottom:solid #A41A15 2.25pt">
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td width=3D"200" nowrap=3D"" valign=3D"top" style=3D"width:150.0pt;border:=
|
||||||
|
none;padding:0cm 0cm 0cm 0cm">
|
||||||
|
<p class=3D"MsoNormal" style=3D"line-height:13.5pt"><span style=3D"font-siz=
|
||||||
|
e:9.0pt;font-family:"Arial",sans-serif;color:#676B68;mso-fareast-=
|
||||||
|
language:FR-BE"><br>
|
||||||
|
</span><b><span style=3D"font-size:10.5pt;font-family:"Arial",san=
|
||||||
|
s-serif;color:#88271B;mso-fareast-language:FR-BE">Val=E9rie Smith</span></b>=
|
||||||
|
<span style=3D"font-size:9.0pt;font-family:"Arial",sans-serif;col=
|
||||||
|
or:#676B68;mso-fareast-language:FR-BE"><br>
|
||||||
|
<a href=3D"mailto:me@example.com"><span style=3D"color:#676B68;text-dec=
|
||||||
|
oration:none">me@example.com
|
||||||
|
</span></a><br>
|
||||||
|
</td>
|
||||||
|
<td width=3D"18" nowrap=3D"" valign=3D"top" style=3D"width:7.5pt;border:non=
|
||||||
|
e;padding:0cm 0cm 0cm 0cm">
|
||||||
|
<p class=3D"MsoNormal" style=3D"line-height:13.5pt"><span style=3D"font-siz=
|
||||||
|
e:9.0pt;font-family:"Arial",sans-serif;color:#676B68;mso-fareast-=
|
||||||
|
language:FR-BE"> <o:p></o:p></span></p>
|
||||||
|
</td>
|
||||||
|
<td width=3D"120" nowrap=3D"" valign=3D"top" style=3D"width:90.0pt;border:n=
|
||||||
|
one;padding:0cm 0cm 0cm 0cm">
|
||||||
|
<p class=3D"MsoNormal" style=3D"margin-bottom:12.0pt;line-height:13.5pt"><s=
|
||||||
|
pan style=3D"font-size:9.0pt;font-family:"Arial",sans-serif;color=
|
||||||
|
:#676B68;mso-fareast-language:FR-BE"><br>
|
||||||
|
<b>XXXX S.a=CC r.l.</b><br>
|
||||||
|
12, Somewhere<br>
|
||||||
|
</span></a></b><o:p></o:p></span></p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<p class=3D"MsoNormal" style=3D"margin-bottom:12.0pt"><span style=3D"font-s=
|
||||||
|
ize:12.0pt;font-family:"Times New Roman",serif;mso-fareast-langua=
|
||||||
|
ge:FR-BE"><br>
|
||||||
|
<table class=3D"MsoNormalTable" border=3D"0" cellspacing=3D"0" cellpadding=
|
||||||
|
=3D"0">
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td style=3D"padding:0cm 0cm 0cm 0cm">
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<p class=3D"MsoNormal"><span lang=3D"EN-US"><o:p> </o:p></span></p>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
||||||
|
--_006_077a50fe57b04807bfa82f909aeacba9lexfieldcom_--
|
Loading…
Reference in a new issue