From 19dc568355c47266383b2185c932aad81cac913d Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Fri, 19 Aug 2016 11:15:19 +0200 Subject: [PATCH] Added check if sender is system address (show sender as agent in ticket zoom). --- .../filter/sender_is_system_address.rb | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 app/models/channel/filter/sender_is_system_address.rb diff --git a/app/models/channel/filter/sender_is_system_address.rb b/app/models/channel/filter/sender_is_system_address.rb new file mode 100644 index 000000000..e34602732 --- /dev/null +++ b/app/models/channel/filter/sender_is_system_address.rb @@ -0,0 +1,32 @@ +# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ + +module Channel::Filter::SenderIsSystemAddress + + def self.run(_channel, mail) + + # if attributes already set by header + return if mail[ 'x-zammad-ticket-create-article-sender'.to_sym ] + return if mail[ 'x-zammad-article-sender'.to_sym ] + + # check if sender addesss is system + form = 'raw-from'.to_sym + return if !mail[form] + return if !mail[:to] + + # in case, set sender + begin + return if !mail[form].addrs + items = mail[form].addrs + items.each { |item| + next if !EmailAddress.find_by(email: item.address.downcase) + mail[ 'x-zammad-ticket-create-article-sender'.to_sym ] = 'Agent' + mail[ 'x-zammad-article-sender'.to_sym ] = 'Agent' + return true + } + rescue => e + Rails.logger.error 'ERROR: SenderIsSystemAddress: ' + e.inspect + end + + true + end +end