From 9edcf47edb6f4256c2fe5895babcad30e751c4b1 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Tue, 23 Aug 2016 11:50:36 +0200 Subject: [PATCH] Also detect gmail vacation emails based on "vacation" in subject. Fixes issue#193. --- .../channel/filter/out_of_office_check.rb | 5 ++ test/unit/email_process_out_of_office_test.rb | 56 +++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/app/models/channel/filter/out_of_office_check.rb b/app/models/channel/filter/out_of_office_check.rb index 2956127e8..b8746f5ab 100644 --- a/app/models/channel/filter/out_of_office_check.rb +++ b/app/models/channel/filter/out_of_office_check.rb @@ -27,6 +27,11 @@ module Channel::Filter::OutOfOfficeCheck mail[ 'x-zammad-out-of-office'.to_sym ] = true end + # gmail check out of office characteristics + if mail[ 'auto-submitted'.to_sym ] =~ /auto-replied/i && mail[ 'subject'.to_sym ] =~ /vacation/i + mail[ 'x-zammad-out-of-office'.to_sym ] = true + end + return end diff --git a/test/unit/email_process_out_of_office_test.rb b/test/unit/email_process_out_of_office_test.rb index 9aaebab69..0b5ee0633 100644 --- a/test/unit/email_process_out_of_office_test.rb +++ b/test/unit/email_process_out_of_office_test.rb @@ -240,4 +240,60 @@ Some Text" end + test 'process with out of office check - gmail' do + + ticket = Ticket.create( + title: 'ooo check - gmail', + 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: 'ooo check', + message_id: '<20150830145601.30.608881@edenhofer.zammad.com>', + body: 'some message bounce 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 + + # gmail out of office example #1 + email_raw_string = "From: me@example.com +To: customer@example.com +Subject: vacation: #{ticket.subject_build('some new subject 1')} +Precedence: bulk +X-Autoreply: yes +Auto-Submitted: auto-replied + +Some Text" + + ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string) + assert_equal(true, mail['x-zammad-out-of-office'.to_sym]) + ticket = Ticket.find(ticket.id) + assert_equal(ticket.id, ticket_p.id) + assert_equal('closed', ticket.state.name) + + # normal follow up + email_raw_string = "From: me@example.com +To: customer@example.com +Subject: #{ticket.subject_build('some new subject - none')} + +Some Text 2" + + ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string) + assert_equal(false, mail['x-zammad-out-of-office'.to_sym]) + ticket = Ticket.find(ticket.id) + assert_equal(ticket.id, ticket_p.id) + assert_equal('open', ticket_p.state.name) + end + end