Added guess routine for not parseable (not RfC conform) email headers like "To: Max Kohl | [example.com] <kohl@example.com>".

This commit is contained in:
Martin Edenhofer 2016-05-29 22:07:17 +02:00
parent 9e52358d57
commit 7a5f73c79a
4 changed files with 99 additions and 12 deletions

View file

@ -44,6 +44,7 @@ module Channel::Filter::IdentifySender
def self.create_recipients(mail) def self.create_recipients(mail)
['raw-to', 'raw-cc'].each { |item| ['raw-to', 'raw-cc'].each { |item|
next if !mail[item.to_sym] next if !mail[item.to_sym]
begin
next if !mail[item.to_sym].addrs next if !mail[item.to_sym].addrs
items = mail[item.to_sym].addrs items = mail[item.to_sym].addrs
items.each {|address_data| items.each {|address_data|
@ -53,6 +54,30 @@ module Channel::Filter::IdentifySender
email: address_data.address, email: address_data.address,
) )
} }
rescue => e
# parse not parseable fields by mail gem like
# - Max Kohl | [example.com] <kohl@example.com>
Rails.logger.error 'ERROR: ' + e.inspect
Rails.logger.error 'ERROR: try it by my self'
recipients = mail[item.to_sym].to_s.split(',')
recipients.each {|recipient|
address = nil
display_name = nil
if recipient =~ /<(.+?)>/
address = $1
end
if recipient =~ /^(.+?)<(.+?)>/
display_name = ($1).strip
end
next if address.empty?
user_create(
firstname: display_name,
lastname: '',
email: address,
)
}
end
} }
end end

13
test/fixtures/mail37.box vendored Normal file
View file

@ -0,0 +1,13 @@
To: Max Kohl | [example.com] <kohl@example.com>
Cc: Ingo Best <iw@example.com>
From: Example <info@example.com>
Subject: Example: Java 8 Neuerungen
Message-ID: <566694F5.2070300@example.com>
Date: Tue, 8 Dec 2015 09:29:41 +0100
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101
Thunderbird/38.3.0
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Tag Max / Ingo!

View file

@ -720,6 +720,19 @@ Um noch vertrauter zu werden, kannst Du mit einen externen E-Mail Account (z. B.
[1] http://web.de', [1] http://web.de',
}, },
}, },
{
data: IO.binread('test/fixtures/mail37.box'),
body_md5: 'dd67e5037a740c053c2bf91f67be072f',
params: {
from: 'Example <info@example.com>',
from_email: 'info@example.com',
from_display_name: 'Example',
subject: 'Example: Java 8 Neuerungen',
to: 'Max Kohl | [example.com] <kohl@example.com>',
cc: 'Ingo Best <iw@example.com>',
body: "Tag Max / Ingo!\n",
},
},
] ]
count = 0 count = 0

View file

@ -1985,6 +1985,42 @@ Some Text',
], ],
} }
}, },
{
data: IO.binread('test/fixtures/mail37.box'),
success: true,
result: {
0 => {
priority: '2 normal',
title: 'Example: Java 8 Neuerungen',
},
1 => {
sender: 'Customer',
type: 'email',
},
},
verify: {
users: [
{
firstname: 'Example',
lastname: '',
fullname: 'Example',
email: 'info@example.com',
},
{
firstname: 'Ingo',
lastname: 'Best',
fullname: 'Ingo Best',
email: 'iw@example.com',
},
{
firstname: 'Max',
lastname: 'Kohl | [example.com]',
fullname: 'Max Kohl | [example.com]',
email: 'kohl@example.com',
},
],
}
},
] ]
process(files) process(files)
end end