From 8104d7756a9daa94aecfd5e00345d7ca4aa8ec8b Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Thu, 18 Jan 2018 11:13:10 +0100 Subject: [PATCH] Improved email processing with corrupt from headers. --- app/models/channel/email_parser.rb | 2 +- test/unit/email_process_test.rb | 51 ++++++++++++++++++++++++++++-- 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/app/models/channel/email_parser.rb b/app/models/channel/email_parser.rb index d440f8e38..0f858c353 100644 --- a/app/models/channel/email_parser.rb +++ b/app/models/channel/email_parser.rb @@ -752,7 +752,7 @@ returns end # do extra decoding because we needed to use field.value - data[:from_display_name] = Mail::Field.new('X-From', data[:from_display_name]).to_s + data[:from_display_name] = Mail::Field.new('X-From', Encode.conv('utf8', data[:from_display_name])).to_s data[:from_display_name].delete!('"') data[:from_display_name].strip! data[:from_display_name].gsub!(/^'/, '') diff --git a/test/unit/email_process_test.rb b/test/unit/email_process_test.rb index f289d618c..8c2a0a227 100644 --- a/test/unit/email_process_test.rb +++ b/test/unit/email_process_test.rb @@ -2700,7 +2700,23 @@ Some Text', }, }, { - data: IO.binread('test/fixtures/mail65.box'), + data: 'From: =?iso-8859-1?Q?B=FCrling,=20Andreas?= +Content-Type: text/plain; + charset=iso-8859-1 +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: +To: metest@znuny.com +Mime-Version: 1.0 (Apple Message framework v1257) + +=E4=F6=FC=DF ad asd + +-Martin + +-- +Old programmers never die. They just branch to a new address.', success: true, result: { 0 => { @@ -2716,8 +2732,7 @@ Some Text', -Martin -- -Old programmers never die. They just branch to a new address. -', +Old programmers never die. They just branch to a new address.', }, }, verify: { @@ -2731,6 +2746,36 @@ Old programmers never die. They just branch to a new address. ], }, }, + { + data: 'From: =?windows-1258?B?VmFuZHJvbW1lLCBGculk6XJpYw==?= +To: Example +Subject: some subject 3 + +Some Text', + success: true, + result: { + 0 => { + priority: '2 normal', + title: 'some subject 3', + }, + 1 => { + from: '=?windows-1258?B?VmFuZHJvbW1lLCBGculk6XJpYw==?= ', + sender: 'Customer', + type: 'email', + body: 'Some Text', + }, + }, + verify: { + users: [ + { + firstname: 'Frédéric', + lastname: 'Vandromme', + fullname: 'Frédéric Vandromme', + email: 'fvandromme@example.com', + }, + ], + }, + }, ] assert_process(files) end