From 91bdf9f81446528aa159d96fec6c87d67a33f836 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Mon, 14 May 2018 10:50:18 +0200 Subject: [PATCH] Allow to access origin sender if postmaster_sender_based_on_reply_to is used (is available in mail['origin_from_*']). --- .../channel/filter/reply_to_based_sender.rb | 12 ++++++ test/unit/email_process_reply_to_test.rb | 41 ++++++++++++++++--- 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/app/models/channel/filter/reply_to_based_sender.rb b/app/models/channel/filter/reply_to_based_sender.rb index bf2fb3751..a4c3939f6 100644 --- a/app/models/channel/filter/reply_to_based_sender.rb +++ b/app/models/channel/filter/reply_to_based_sender.rb @@ -10,10 +10,20 @@ module Channel::Filter::ReplyToBasedSender setting = Setting.get('postmaster_sender_based_on_reply_to') 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 result = Channel::EmailParser.sender_properties(reply_to) if setting == 'as_sender_of_email' + + # set new sender mail['raw-from'.to_sym] = mail['raw-reply-to'.to_sym] mail[:from] = reply_to mail[:from_email] = result[:from_email] @@ -24,6 +34,8 @@ module Channel::Filter::ReplyToBasedSender end if setting == 'as_sender_of_email_use_from_realname' + + # set new sender mail['raw-from'.to_sym] = mail['raw-reply-to'.to_sym] mail[:from] = reply_to mail[:from_email] = result[:from_email] diff --git a/test/unit/email_process_reply_to_test.rb b/test/unit/email_process_reply_to_test.rb index b4f698604..99d72fc1d 100644 --- a/test/unit/email_process_reply_to_test.rb +++ b/test/unit/email_process_reply_to_test.rb @@ -13,7 +13,7 @@ Reply-To: replay_to_customer_process1@example.com 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('email', article_p.type.name) assert_equal('Bob Smith ', article_p.from) @@ -21,6 +21,12 @@ Some Text" assert_equal('marketing_tool@example.com', ticket_p.customer.email) assert_equal('Bob', ticket_p.customer.firstname) 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 test 'normal processing - take reply to as customer' do @@ -33,7 +39,7 @@ Reply-To: replay_to_customer_process2@example.com 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.reply_to) 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('Some', ticket_p.customer.firstname) assert_equal('Name', ticket_p.customer.lastname) + assert_equal('Bob Smith ', mail['raw-origin_from'.to_sym].to_s) + assert_equal('Bob Smith ', 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 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" - 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.reply_to) assert_equal('replay_to_customer_process3@example.com', ticket_p.customer.email) assert_equal('Bob', ticket_p.customer.firstname) assert_equal('Smith', ticket_p.customer.lastname) + assert_equal('Bob Smith ', mail['raw-origin_from'.to_sym].to_s) + assert_equal('Bob Smith ', 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 To: zammad@example.com @@ -81,7 +99,7 @@ Reply-To: Some Name 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('email', article_p.type.name) assert_equal('Some Name ', article_p.from) @@ -89,6 +107,12 @@ Some Text" assert_equal('replay_to_customer_process3-1@example.com', ticket_p.customer.email) assert_equal('Bob', ticket_p.customer.firstname) assert_equal('Smith', ticket_p.customer.lastname) + assert_equal('Bob Smith ', mail['raw-origin_from'.to_sym].to_s) + assert_equal('Bob Smith ', 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 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" - 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('email', article_p.type.name) 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('', ticket_p.customer.firstname) assert_equal('', ticket_p.customer.lastname) - + assert_equal('Marketing Tool ', mail['raw-origin_from'.to_sym].to_s) + assert_equal('Marketing Tool ', 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