diff --git a/app/models/channel/email_parser.rb b/app/models/channel/email_parser.rb index 4ec022d3f..98d3edddd 100644 --- a/app/models/channel/email_parser.rb +++ b/app/models/channel/email_parser.rb @@ -98,14 +98,24 @@ class Channel::EmailParser data[field.to_sym] = '' } - # get sender + # get sender with @ / email address from = nil ['from', 'reply-to', 'return-path'].each { |item| next if data[item.to_sym].blank? + next if data[item.to_sym] !~ /@/ from = data[item.to_sym] 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 data['x-any-recipient'.to_sym] = '' ['to', 'cc', 'delivered-to', 'x-original-to', 'envelope-to'].each { |item| diff --git a/test/unit/email_parser_test.rb b/test/unit/email_parser_test.rb index 121b6e5db..08b472ba4 100644 --- a/test/unit/email_parser_test.rb +++ b/test/unit/email_parser_test.rb @@ -499,7 +499,7 @@ Managing Director: Martin Edenhofer body_md5: '6021dd92d8e7844e6bb9b5bb7a4adfb8', params: { from: '"我" <>', - from_email: '"我" <>', + from_email: 'vipyiming@126.com', from_display_name: '', subject: '《欧美简讯》', to: '377861373 <377861373@qq.com>', diff --git a/test/unit/email_process_test.rb b/test/unit/email_process_test.rb index 96658dcc9..e2ecb83d7 100644 --- a/test/unit/email_process_test.rb +++ b/test/unit/email_process_test.rb @@ -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\" + +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 To: Alexander Ha ,