From 4df414f785360a08a76c731d14228cc63d27b4cb Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Tue, 22 Dec 2015 15:09:36 +0100 Subject: [PATCH] For auto response emails without T# in subject, find follow up by references header. --- .../channel/filter/auto_response_check.rb | 4 +- app/models/channel/filter/bounce_check.rb | 2 +- app/models/channel/filter/follow_up_check.rb | 4 +- .../channel/filter/out_of_office_check.rb | 2 +- app/models/channel/filter/trusted.rb | 4 +- test/unit/email_process_follow_up_test.rb | 54 +++++++++++++++++-- test/unit/email_process_out_of_office_test.rb | 31 +++++------ 7 files changed, 73 insertions(+), 28 deletions(-) diff --git a/app/models/channel/filter/auto_response_check.rb b/app/models/channel/filter/auto_response_check.rb index 25fd23add..ef12d599e 100644 --- a/app/models/channel/filter/auto_response_check.rb +++ b/app/models/channel/filter/auto_response_check.rb @@ -2,10 +2,11 @@ module Channel::Filter::AutoResponseCheck - def self.run( _channel, mail ) + def self.run(_channel, mail) # if header is available, do not generate auto response mail[ 'x-zammad-send-auto-response'.to_sym ] = false + mail[ 'x-zammad-is-auto-response'.to_sym ] = true return if mail[ 'x-loop'.to_sym ] && mail[ 'x-loop'.to_sym ] =~ /(yes|true)/i return if mail[ 'precedence'.to_sym ] && mail[ 'precedence'.to_sym ] =~ /bulk/i @@ -13,6 +14,7 @@ module Channel::Filter::AutoResponseCheck return if mail[ 'x-auto-response-suppress'.to_sym ] && mail[ 'x-auto-response-suppress'.to_sym ] =~ /all/i mail[ 'x-zammad-send-auto-response'.to_sym ] = true + mail[ 'x-zammad-is-auto-response'.to_sym ] = false end end diff --git a/app/models/channel/filter/bounce_check.rb b/app/models/channel/filter/bounce_check.rb index c6cacaece..80c988ae4 100644 --- a/app/models/channel/filter/bounce_check.rb +++ b/app/models/channel/filter/bounce_check.rb @@ -2,7 +2,7 @@ module Channel::Filter::BounceCheck - def self.run( _channel, mail ) + def self.run(_channel, mail) return if !mail[:mail_instance] return if !mail[:mail_instance].bounced? diff --git a/app/models/channel/filter/follow_up_check.rb b/app/models/channel/filter/follow_up_check.rb index d310978f2..94a7dca93 100644 --- a/app/models/channel/filter/follow_up_check.rb +++ b/app/models/channel/filter/follow_up_check.rb @@ -2,7 +2,7 @@ module Channel::Filter::FollowUpCheck - def self.run( _channel, mail ) + def self.run(_channel, mail) return if mail[ 'x-zammad-ticket-id'.to_sym ] @@ -39,7 +39,7 @@ module Channel::Filter::FollowUpCheck end # get ticket# from references - if setting.include?('references') + if setting.include?('references') || mail[ 'x-zammad-is-auto-response'.to_sym ] == true # get all references 'References' + 'In-Reply-To' references = '' diff --git a/app/models/channel/filter/out_of_office_check.rb b/app/models/channel/filter/out_of_office_check.rb index 4fed2f13b..2956127e8 100644 --- a/app/models/channel/filter/out_of_office_check.rb +++ b/app/models/channel/filter/out_of_office_check.rb @@ -2,7 +2,7 @@ module Channel::Filter::OutOfOfficeCheck - def self.run( _channel, mail ) + def self.run(_channel, mail) mail[ 'x-zammad-out-of-office'.to_sym ] = false diff --git a/app/models/channel/filter/trusted.rb b/app/models/channel/filter/trusted.rb index 131b3371a..66b60ead9 100644 --- a/app/models/channel/filter/trusted.rb +++ b/app/models/channel/filter/trusted.rb @@ -3,14 +3,12 @@ # delete all X-Zammad header if channel is not trusted module Channel::Filter::Trusted - def self.run( channel, mail ) + def self.run(channel, mail) # check if trust x-headers if !channel[:trusted] mail.each {|key, _value| - next if key !~ /^x-zammad/i - mail.delete(key) } end diff --git a/test/unit/email_process_follow_up_test.rb b/test/unit/email_process_follow_up_test.rb index e2488d0ee..353c6d8e4 100644 --- a/test/unit/email_process_follow_up_test.rb +++ b/test/unit/email_process_follow_up_test.rb @@ -7,10 +7,10 @@ class EmailProcessFollowUpTest < ActiveSupport::TestCase ticket = Ticket.create( title: 'follow up check', - group: Group.lookup( name: 'Users'), + group: Group.lookup(name: 'Users'), customer_id: 2, - state: Ticket::State.lookup( name: 'new' ), - priority: Ticket::Priority.lookup( name: '2 normal' ), + state: Ticket::State.lookup(name: 'new'), + priority: Ticket::Priority.lookup(name: '2 normal'), updated_by_id: 1, created_by_id: 1, ) @@ -22,8 +22,8 @@ class EmailProcessFollowUpTest < ActiveSupport::TestCase message_id: '<20150830145601.30.608882@edenhofer.zammad.com>', body: 'some message article', internal: false, - sender: Ticket::Article::Sender.where(name: 'Agent').first, - type: Ticket::Article::Type.where(name: 'email').first, + sender: Ticket::Article::Sender.lookup(name: 'Agent'), + type: Ticket::Article::Type.lookup(name: 'email'), updated_by_id: 1, created_by_id: 1, ) @@ -127,4 +127,48 @@ no reference " assert_not_equal(ticket.id, ticket_p.id) end + test 'process with follow up check - with auto responses and no T# in subject_build' do + + ticket = Ticket.create( + title: 'follow up - with references follow up check', + group: Group.lookup(name: 'Users'), + customer_id: 2, + state: Ticket::State.lookup(name: 'closed'), + priority: Ticket::Priority.lookup(name: '2 normal'), + updated_by_id: 1, + created_by_id: 1, + ) + article = Ticket::Article.create( + ticket_id: ticket.id, + from: 'some_sender@example.com', + to: 'some_recipient@example.com', + subject: 'follow up with references follow up check', + message_id: '<20151222145601.30.608881@edenhofer.zammad.com>', + body: 'some message with references follow up check', + internal: false, + sender: Ticket::Article::Sender.lookup(name: 'Agent'), + type: Ticket::Article::Type.lookup(name: 'email'), + updated_by_id: 1, + created_by_id: 1, + ) + sleep 1 + + # auto response without T# in subject, find follow up by references header + email_raw_string = "From: bob@example.com +To: customer@example.com +Subject: =?ISO-8859-1?Q?AUTO=3A_Bob_Smith_ist_au=DFer_Haus=2E_=2F_is_out_of?= + =?ISO-8859-1?Q?_office=2E_=28R=FCckkehr_am_28=2E12=2E2015=29?= +In-Reply-To: <20251222081758.116249.983698@portal.znuny.com> +References: <20151222145601.30.608881@edenhofer.zammad.com> <20251222081758.116249.983698@portal.znuny.com> +Message-ID: +Auto-Submitted: auto-replied + +Some Text" + + ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process( {}, email_raw_string) + ticket = Ticket.find(ticket.id) + assert_equal(ticket.id, ticket_p.id) + assert_equal('open', ticket.state.name) + end + end diff --git a/test/unit/email_process_out_of_office_test.rb b/test/unit/email_process_out_of_office_test.rb index 4a4b52573..60d634643 100644 --- a/test/unit/email_process_out_of_office_test.rb +++ b/test/unit/email_process_out_of_office_test.rb @@ -7,10 +7,10 @@ class EmailProcessOutOfOfficeTest < ActiveSupport::TestCase ticket = Ticket.create( title: 'ooo check - ms', - group: Group.lookup( name: 'Users'), + group: Group.lookup(name: 'Users'), customer_id: 2, - state: Ticket::State.lookup( name: 'closed' ), - priority: Ticket::Priority.lookup( name: '2 normal' ), + state: Ticket::State.lookup(name: 'closed'), + priority: Ticket::Priority.lookup(name: '2 normal'), updated_by_id: 1, created_by_id: 1, ) @@ -22,8 +22,8 @@ class EmailProcessOutOfOfficeTest < ActiveSupport::TestCase message_id: '<20150830145601.30.608881@edenhofer.zammad.com>', body: 'some message bounce check', internal: false, - sender: Ticket::Article::Sender.where(name: 'Agent').first, - type: Ticket::Article::Type.where(name: 'email').first, + sender: Ticket::Article::Sender.lookup(name: 'Agent'), + type: Ticket::Article::Type.lookup(name: 'email'), updated_by_id: 1, created_by_id: 1, ) @@ -93,10 +93,10 @@ Some Text" ticket = Ticket.create( title: 'ooo check - zimbra', - group: Group.lookup( name: 'Users'), + group: Group.lookup(name: 'Users'), customer_id: 2, - state: Ticket::State.lookup( name: 'closed' ), - priority: Ticket::Priority.lookup( name: '2 normal' ), + state: Ticket::State.lookup(name: 'closed'), + priority: Ticket::Priority.lookup(name: '2 normal'), updated_by_id: 1, created_by_id: 1, ) @@ -108,8 +108,8 @@ Some Text" message_id: '<20150830145601.30.608881@edenhofer.zammad.com>', body: 'some message bounce check', internal: false, - sender: Ticket::Article::Sender.where(name: 'Agent').first, - type: Ticket::Article::Type.where(name: 'email').first, + sender: Ticket::Article::Sender.lookup(name: 'Agent'), + type: Ticket::Article::Type.lookup(name: 'email'), updated_by_id: 1, created_by_id: 1, ) @@ -171,10 +171,10 @@ Some Text" ticket = Ticket.create( title: 'ooo check - cloud', - group: Group.lookup( name: 'Users'), + group: Group.lookup(name: 'Users'), customer_id: 2, - state: Ticket::State.lookup( name: 'closed' ), - priority: Ticket::Priority.lookup( name: '2 normal' ), + state: Ticket::State.lookup(name: 'closed'), + priority: Ticket::Priority.lookup(name: '2 normal'), updated_by_id: 1, created_by_id: 1, ) @@ -186,8 +186,8 @@ Some Text" message_id: '<20150830145601.30.608881@edenhofer.zammad.com>', body: 'some message bounce check', internal: false, - sender: Ticket::Article::Sender.where(name: 'Agent').first, - type: Ticket::Article::Type.where(name: 'email').first, + sender: Ticket::Article::Sender.lookup(name: 'Agent'), + type: Ticket::Article::Type.lookup(name: 'email'), updated_by_id: 1, created_by_id: 1, ) @@ -239,4 +239,5 @@ Some Text" assert_equal('closed', ticket.state.name) end + end