Improved email parsing, skip sender if no @ is containing (try reply-to or return-path if existing).

This commit is contained in:
Martin Edenhofer 2017-08-15 09:46:21 +02:00
parent 279478025e
commit c6fec78bf9
3 changed files with 43 additions and 2 deletions

View file

@ -98,14 +98,24 @@ class Channel::EmailParser
data[field.to_sym] = '' data[field.to_sym] = ''
} }
# get sender # get sender with @ / email address
from = nil from = nil
['from', 'reply-to', 'return-path'].each { |item| ['from', 'reply-to', 'return-path'].each { |item|
next if data[item.to_sym].blank? next if data[item.to_sym].blank?
next if data[item.to_sym] !~ /@/
from = data[item.to_sym] from = data[item.to_sym]
break if from break if from
} }
# in case of no sender with email address - get sender
if !from
['from', 'reply-to', 'return-path'].each { |item|
next if data[item.to_sym].blank?
from = data[item.to_sym]
break if from
}
end
# set x-any-recipient # set x-any-recipient
data['x-any-recipient'.to_sym] = '' data['x-any-recipient'.to_sym] = ''
['to', 'cc', 'delivered-to', 'x-original-to', 'envelope-to'].each { |item| ['to', 'cc', 'delivered-to', 'x-original-to', 'envelope-to'].each { |item|

View file

@ -499,7 +499,7 @@ Managing Director: Martin Edenhofer
body_md5: '6021dd92d8e7844e6bb9b5bb7a4adfb8', body_md5: '6021dd92d8e7844e6bb9b5bb7a4adfb8',
params: { params: {
from: '"我" <>', from: '"我" <>',
from_email: '"我" <>', from_email: 'vipyiming@126.com',
from_display_name: '', from_display_name: '',
subject: '《欧美简讯》', subject: '《欧美简讯》',
to: '377861373 <377861373@qq.com>', to: '377861373 <377861373@qq.com>',

View file

@ -134,6 +134,37 @@ Some Textäöü".encode('ISO-8859-1'),
}, },
}, },
}, },
{
data: "From: Realname
To: customer@example.com
Subject: abc some subject
Reply-To: \"no-reply-without-from-email@example.com\" <no-reply-without-from-email@example.com>
Some Text",
success: true,
result: {
0 => {
priority: '2 normal',
title: 'abc some subject',
},
1 => {
body: 'Some Text',
sender: 'Customer',
type: 'email',
internal: false,
},
},
verify: {
users: [
{
firstname: 'no-reply-without-from-email@example.com',
lastname: '',
fullname: 'no-reply-without-from-email@example.com',
email: 'no-reply-without-from-email@example.com',
},
],
},
},
{ {
data: "From: me@example.com data: "From: me@example.com
To: Alexander Ha <service-d1@example.com>, To: Alexander Ha <service-d1@example.com>,