diff --git a/lib/core_ext/string.rb b/lib/core_ext/string.rb index f8699cd52..3b11bce6a 100644 --- a/lib/core_ext/string.rb +++ b/lib/core_ext/string.rb @@ -476,11 +476,11 @@ class String def utf8_encode!(**options) 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 - return encode!('utf-8', e) - rescue Encoding::UndefinedConversionError - nil + return encode!('utf-8', enc) + rescue EncodingError => e + Rails.logger.error { e.inspect } end end diff --git a/spec/models/channel/email_parser_spec.rb b/spec/models/channel/email_parser_spec.rb index 78fd86898..2c2609afe 100644 --- a/spec/models/channel/email_parser_spec.rb +++ b/spec/models/channel/email_parser_spec.rb @@ -70,5 +70,15 @@ RSpec.describe Channel::EmailParser, type: :model do .and include('mail_delivery_failed_data' => a_kind_of(ActiveSupport::TimeWithZone)) 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 diff --git a/test/data/mail/mail072.box b/test/data/mail/mail072.box new file mode 100644 index 000000000..06adac0d4 --- /dev/null +++ b/test/data/mail/mail072.box @@ -0,0 +1,186 @@ +From: =?windows-1258?Q?Val=E9rie_Oury?= +To: "'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 + + + + + + + + +
+

Bonjour, +

+

 

+

Je vous contacte suite =E0 ma commande du 14 ao=FBt 2= +018 r=E9f=E9renc=E9e ci-dessus.

+

 

+

         = +;            &n= +bsp;            = +;            &n= +bsp;            = +;            &n= +bsp;            = +;            &n= +bsp;            = +;            &n= +bsp;            = +;            &n= +bsp;       +

+

 

+

Je vous remercie d=92avance.

+

 

+

Cordialement,

+

 

+

 

+ + + + + + + + +
+


+
Val=E9rie Smith= +
+me@example.com +
+

+

      

+
+


+XXXX S.a=CC r.l.
+12, Somewhere
+

+
+


+ + + + + + +
+
+

 

+
+ + + +--_006_077a50fe57b04807bfa82f909aeacba9lexfieldcom_--