Allow to access origin sender if postmaster_sender_based_on_reply_to is used (is available in mail['origin_from_*']).
This commit is contained in:
parent
f2c7ced74d
commit
91bdf9f814
2 changed files with 47 additions and 6 deletions
|
@ -10,10 +10,20 @@ module Channel::Filter::ReplyToBasedSender
|
||||||
setting = Setting.get('postmaster_sender_based_on_reply_to')
|
setting = Setting.get('postmaster_sender_based_on_reply_to')
|
||||||
return if setting.blank?
|
return if setting.blank?
|
||||||
|
|
||||||
|
# remember original sender
|
||||||
|
mail['raw-origin_from'.to_sym] = mail['raw-from'.to_sym]
|
||||||
|
mail['origin_from'.to_sym] = mail[:from]
|
||||||
|
mail['origin_from_email'.to_sym] = mail[:from_email]
|
||||||
|
mail['origin_from_local'.to_sym] = mail[:from_local]
|
||||||
|
mail['origin_from_domain'.to_sym] = mail[:from_domain]
|
||||||
|
mail['origin_from_display_name'.to_sym] = mail[:from_display_name]
|
||||||
|
|
||||||
# get properties of reply-to header
|
# get properties of reply-to header
|
||||||
result = Channel::EmailParser.sender_properties(reply_to)
|
result = Channel::EmailParser.sender_properties(reply_to)
|
||||||
|
|
||||||
if setting == 'as_sender_of_email'
|
if setting == 'as_sender_of_email'
|
||||||
|
|
||||||
|
# set new sender
|
||||||
mail['raw-from'.to_sym] = mail['raw-reply-to'.to_sym]
|
mail['raw-from'.to_sym] = mail['raw-reply-to'.to_sym]
|
||||||
mail[:from] = reply_to
|
mail[:from] = reply_to
|
||||||
mail[:from_email] = result[:from_email]
|
mail[:from_email] = result[:from_email]
|
||||||
|
@ -24,6 +34,8 @@ module Channel::Filter::ReplyToBasedSender
|
||||||
end
|
end
|
||||||
|
|
||||||
if setting == 'as_sender_of_email_use_from_realname'
|
if setting == 'as_sender_of_email_use_from_realname'
|
||||||
|
|
||||||
|
# set new sender
|
||||||
mail['raw-from'.to_sym] = mail['raw-reply-to'.to_sym]
|
mail['raw-from'.to_sym] = mail['raw-reply-to'.to_sym]
|
||||||
mail[:from] = reply_to
|
mail[:from] = reply_to
|
||||||
mail[:from_email] = result[:from_email]
|
mail[:from_email] = result[:from_email]
|
||||||
|
|
|
@ -13,7 +13,7 @@ Reply-To: replay_to_customer_process1@example.com
|
||||||
|
|
||||||
Some Text"
|
Some Text"
|
||||||
|
|
||||||
ticket_p, article_p, user_p = Channel::EmailParser.new.process({}, email)
|
ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email)
|
||||||
assert_equal('Customer', article_p.sender.name)
|
assert_equal('Customer', article_p.sender.name)
|
||||||
assert_equal('email', article_p.type.name)
|
assert_equal('email', article_p.type.name)
|
||||||
assert_equal('Bob Smith <marketing_tool@example.com>', article_p.from)
|
assert_equal('Bob Smith <marketing_tool@example.com>', article_p.from)
|
||||||
|
@ -21,6 +21,12 @@ Some Text"
|
||||||
assert_equal('marketing_tool@example.com', ticket_p.customer.email)
|
assert_equal('marketing_tool@example.com', ticket_p.customer.email)
|
||||||
assert_equal('Bob', ticket_p.customer.firstname)
|
assert_equal('Bob', ticket_p.customer.firstname)
|
||||||
assert_equal('Smith', ticket_p.customer.lastname)
|
assert_equal('Smith', ticket_p.customer.lastname)
|
||||||
|
assert_nil(mail['raw-origin_from'.to_sym])
|
||||||
|
assert_nil(mail['origin_from'.to_sym])
|
||||||
|
assert_nil(mail['origin_from_email'.to_sym])
|
||||||
|
assert_nil(mail['origin_from_local'.to_sym])
|
||||||
|
assert_nil(mail['origin_from_domain'.to_sym])
|
||||||
|
assert_nil(mail['origin_from_display_name'.to_sym])
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'normal processing - take reply to as customer' do
|
test 'normal processing - take reply to as customer' do
|
||||||
|
@ -33,7 +39,7 @@ Reply-To: replay_to_customer_process2@example.com
|
||||||
|
|
||||||
Some Text"
|
Some Text"
|
||||||
|
|
||||||
ticket_p, article_p, user_p = Channel::EmailParser.new.process({}, email)
|
ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email)
|
||||||
assert_equal('replay_to_customer_process2@example.com', article_p.from)
|
assert_equal('replay_to_customer_process2@example.com', article_p.from)
|
||||||
assert_equal('replay_to_customer_process2@example.com', article_p.reply_to)
|
assert_equal('replay_to_customer_process2@example.com', article_p.reply_to)
|
||||||
assert_equal('replay_to_customer_process2@example.com', ticket_p.customer.email)
|
assert_equal('replay_to_customer_process2@example.com', ticket_p.customer.email)
|
||||||
|
@ -55,6 +61,12 @@ Some Text"
|
||||||
assert_equal('replay_to_customer_process2-1@example.com', ticket_p.customer.email)
|
assert_equal('replay_to_customer_process2-1@example.com', ticket_p.customer.email)
|
||||||
assert_equal('Some', ticket_p.customer.firstname)
|
assert_equal('Some', ticket_p.customer.firstname)
|
||||||
assert_equal('Name', ticket_p.customer.lastname)
|
assert_equal('Name', ticket_p.customer.lastname)
|
||||||
|
assert_equal('Bob Smith <marketing_tool@example.com>', mail['raw-origin_from'.to_sym].to_s)
|
||||||
|
assert_equal('Bob Smith <marketing_tool@example.com>', mail['origin_from'.to_sym])
|
||||||
|
assert_equal('marketing_tool@example.com', mail['origin_from_email'.to_sym])
|
||||||
|
assert_equal('marketing_tool', mail['origin_from_local'.to_sym])
|
||||||
|
assert_equal('example.com', mail['origin_from_domain'.to_sym])
|
||||||
|
assert_equal('Bob Smith', mail['origin_from_display_name'.to_sym])
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'normal processing - take reply to as customer and use from as realname' do
|
test 'normal processing - take reply to as customer and use from as realname' do
|
||||||
|
@ -67,12 +79,18 @@ Reply-To: replay_to_customer_process3@example.com
|
||||||
|
|
||||||
Some Text"
|
Some Text"
|
||||||
|
|
||||||
ticket_p, article_p, user_p = Channel::EmailParser.new.process({}, email)
|
ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email)
|
||||||
assert_equal('replay_to_customer_process3@example.com', article_p.from)
|
assert_equal('replay_to_customer_process3@example.com', article_p.from)
|
||||||
assert_equal('replay_to_customer_process3@example.com', article_p.reply_to)
|
assert_equal('replay_to_customer_process3@example.com', article_p.reply_to)
|
||||||
assert_equal('replay_to_customer_process3@example.com', ticket_p.customer.email)
|
assert_equal('replay_to_customer_process3@example.com', ticket_p.customer.email)
|
||||||
assert_equal('Bob', ticket_p.customer.firstname)
|
assert_equal('Bob', ticket_p.customer.firstname)
|
||||||
assert_equal('Smith', ticket_p.customer.lastname)
|
assert_equal('Smith', ticket_p.customer.lastname)
|
||||||
|
assert_equal('Bob Smith <marketing_tool@example.com>', mail['raw-origin_from'.to_sym].to_s)
|
||||||
|
assert_equal('Bob Smith <marketing_tool@example.com>', mail['origin_from'.to_sym])
|
||||||
|
assert_equal('marketing_tool@example.com', mail['origin_from_email'.to_sym])
|
||||||
|
assert_equal('marketing_tool', mail['origin_from_local'.to_sym])
|
||||||
|
assert_equal('example.com', mail['origin_from_domain'.to_sym])
|
||||||
|
assert_equal('Bob Smith', mail['origin_from_display_name'.to_sym])
|
||||||
|
|
||||||
email = "From: Bob Smith <marketing_tool@example.com>
|
email = "From: Bob Smith <marketing_tool@example.com>
|
||||||
To: zammad@example.com
|
To: zammad@example.com
|
||||||
|
@ -81,7 +99,7 @@ Reply-To: Some Name <replay_to_customer_process3-1@example.com>
|
||||||
|
|
||||||
Some Text"
|
Some Text"
|
||||||
|
|
||||||
ticket_p, article_p, user_p = Channel::EmailParser.new.process({}, email)
|
ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email)
|
||||||
assert_equal('Customer', article_p.sender.name)
|
assert_equal('Customer', article_p.sender.name)
|
||||||
assert_equal('email', article_p.type.name)
|
assert_equal('email', article_p.type.name)
|
||||||
assert_equal('Some Name <replay_to_customer_process3-1@example.com>', article_p.from)
|
assert_equal('Some Name <replay_to_customer_process3-1@example.com>', article_p.from)
|
||||||
|
@ -89,6 +107,12 @@ Some Text"
|
||||||
assert_equal('replay_to_customer_process3-1@example.com', ticket_p.customer.email)
|
assert_equal('replay_to_customer_process3-1@example.com', ticket_p.customer.email)
|
||||||
assert_equal('Bob', ticket_p.customer.firstname)
|
assert_equal('Bob', ticket_p.customer.firstname)
|
||||||
assert_equal('Smith', ticket_p.customer.lastname)
|
assert_equal('Smith', ticket_p.customer.lastname)
|
||||||
|
assert_equal('Bob Smith <marketing_tool@example.com>', mail['raw-origin_from'.to_sym].to_s)
|
||||||
|
assert_equal('Bob Smith <marketing_tool@example.com>', mail['origin_from'.to_sym])
|
||||||
|
assert_equal('marketing_tool@example.com', mail['origin_from_email'.to_sym])
|
||||||
|
assert_equal('marketing_tool', mail['origin_from_local'.to_sym])
|
||||||
|
assert_equal('example.com', mail['origin_from_domain'.to_sym])
|
||||||
|
assert_equal('Bob Smith', mail['origin_from_display_name'.to_sym])
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'normal processing - take reply to as customer and sender is system address' do
|
test 'normal processing - take reply to as customer and sender is system address' do
|
||||||
|
@ -110,7 +134,7 @@ Reply-To: replay_to_customer_process2@example.com
|
||||||
|
|
||||||
Some Text"
|
Some Text"
|
||||||
|
|
||||||
ticket_p, article_p, user_p = Channel::EmailParser.new.process({}, email)
|
ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email)
|
||||||
assert_equal('Customer', article_p.sender.name)
|
assert_equal('Customer', article_p.sender.name)
|
||||||
assert_equal('email', article_p.type.name)
|
assert_equal('email', article_p.type.name)
|
||||||
assert_equal('replay_to_customer_process2@example.com', article_p.from)
|
assert_equal('replay_to_customer_process2@example.com', article_p.from)
|
||||||
|
@ -118,7 +142,12 @@ Some Text"
|
||||||
assert_equal('replay_to_customer_process2@example.com', ticket_p.customer.email)
|
assert_equal('replay_to_customer_process2@example.com', ticket_p.customer.email)
|
||||||
assert_equal('', ticket_p.customer.firstname)
|
assert_equal('', ticket_p.customer.firstname)
|
||||||
assert_equal('', ticket_p.customer.lastname)
|
assert_equal('', ticket_p.customer.lastname)
|
||||||
|
assert_equal('Marketing Tool <marketing_tool@example.com>', mail['raw-origin_from'.to_sym].to_s)
|
||||||
|
assert_equal('Marketing Tool <marketing_tool@example.com>', mail['origin_from'.to_sym])
|
||||||
|
assert_equal('marketing_tool@example.com', mail['origin_from_email'.to_sym])
|
||||||
|
assert_equal('marketing_tool', mail['origin_from_local'.to_sym])
|
||||||
|
assert_equal('example.com', mail['origin_from_domain'.to_sym])
|
||||||
|
assert_equal('Marketing Tool', mail['origin_from_display_name'.to_sym])
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue