diff --git a/app/models/channel/filter/identify_sender.rb b/app/models/channel/filter/identify_sender.rb index 7818f251f..9b271c556 100644 --- a/app/models/channel/filter/identify_sender.rb +++ b/app/models/channel/filter/identify_sender.rb @@ -95,16 +95,19 @@ module Channel::Filter::IdentifySender max_count = 40 current_count = 0 ['raw-to', 'raw-cc'].each do |item| - next if !mail[item.to_sym] + next if mail[item.to_sym].blank? begin - next if !mail[item.to_sym].addrs items = mail[item.to_sym].addrs + next if items.blank? items.each do |address_data| - next if address_data.address.blank? + email_address = address_data.address + next if email_address.blank? + next if email_address !~ /@/ + next if email_address.match?(/\s/) user_create( firstname: address_data.display_name, lastname: '', - email: address_data.address, + email: email_address, ) current_count += 1 return false if current_count == max_count @@ -126,6 +129,8 @@ module Channel::Filter::IdentifySender display_name = $1 end next if address.blank? + next if address !~ /@/ + next if address.match?(/\s/) user_create( firstname: display_name, lastname: '', @@ -176,7 +181,7 @@ module Channel::Filter::IdentifySender data[:updated_by_id] = 1 data[:created_by_id] = 1 - user = User.create(data) + user = User.create!(data) user.update!( updated_by_id: user.id, created_by_id: user.id, diff --git a/test/unit/email_process_test.rb b/test/unit/email_process_test.rb index b945e0737..a16cbd090 100644 --- a/test/unit/email_process_test.rb +++ b/test/unit/email_process_test.rb @@ -203,6 +203,74 @@ Some Text", ], }, }, + { + data: "From: sender@example.com +To: some_new_customer423@example.com +Cc: some recipient , max +Subject: abc some subject2 + +Some Text", + success: true, + result: { + 0 => { + priority: '2 normal', + title: 'abc some subject2', + }, + 1 => { + body: 'Some Text', + sender: 'Customer', + type: 'email', + internal: false, + }, + }, + verify: { + users: [ + { + firstname: 'max', + lastname: '', + fullname: 'max', + email: 'somebody_else@example.com', + }, + { + firstname: '', + lastname: '', + fullname: 'some_new_customer423@example.com', + email: 'some_new_customer423@example.com', + }, + ], + }, + }, + { + data: "From: sender@example.com +To: some_new_customer424@example.com +Subject: abc some subject3 +Reply-To: some user + +Some Text", + success: true, + result: { + 0 => { + priority: '2 normal', + title: 'abc some subject3', + }, + 1 => { + body: 'Some Text', + sender: 'Customer', + type: 'email', + internal: false, + }, + }, + verify: { + users: [ + { + firstname: '', + lastname: '', + fullname: 'some_new_customer424@example.com', + email: 'some_new_customer424@example.com', + }, + ], + }, + }, { data: "From: me@example.com To: Alexander Ha , @@ -2812,9 +2880,9 @@ Some Text', # verify if users are created if file[:verify][:users] file[:verify][:users].each { |user_result| - user = User.where(email: user_result[:email]).first + user = User.where(email: user_result[:email].downcase).first if !user - assert(false, "No user '#{user_result[:email]}' found!") + assert(false, "No user '#{user_result[:email].downcase}' found!") return end user_result.each { |key, value|