Improved error handling of email processing with invalid email addresses.
This commit is contained in:
parent
aef865a916
commit
e9f4b5af08
2 changed files with 80 additions and 7 deletions
|
@ -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,
|
||||
|
|
|
@ -203,6 +203,74 @@ Some Text",
|
|||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
data: "From: sender@example.com
|
||||
To: some_new_customer423@example.com
|
||||
Cc: some recipient <some with invalid@example.com>, max <somebody_else@example.com>
|
||||
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 <no-reply-with invalid-spaces@example.com>
|
||||
|
||||
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 <service-d1@example.com>,
|
||||
|
@ -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|
|
||||
|
|
Loading…
Reference in a new issue