From 925ff560661bdfd39672d896b8fabad512d812bb Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Fri, 31 Aug 2018 17:17:59 +0200 Subject: [PATCH] Private me issue2219 reopen delivery delay message --- .../bounce_delivery_temporary_failed.rb | 17 +++ ...00001_setting_delivery_temporary_failed.rb | 19 +++ db/seeds/settings.rb | 9 ++ ...s_bounce_delivery_permanent_failed_test.rb | 12 +- ...s_bounce_delivery_temporary_failed_test.rb | 110 ++++++++++++++++++ 5 files changed, 161 insertions(+), 6 deletions(-) create mode 100644 app/models/channel/filter/bounce_delivery_temporary_failed.rb create mode 100644 db/migrate/20180830000001_setting_delivery_temporary_failed.rb create mode 100644 test/unit/email_process_bounce_delivery_temporary_failed_test.rb diff --git a/app/models/channel/filter/bounce_delivery_temporary_failed.rb b/app/models/channel/filter/bounce_delivery_temporary_failed.rb new file mode 100644 index 000000000..9d07b6cb4 --- /dev/null +++ b/app/models/channel/filter/bounce_delivery_temporary_failed.rb @@ -0,0 +1,17 @@ +# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ + +module Channel::Filter::BounceDeliveryTemporaryFailed + + def self.run(_channel, mail) + return if !mail[:mail_instance] + return if !mail[:attachments] + return if mail[:mail_instance].action != 'delayed' + return if mail[:mail_instance].retryable? != true + return if mail[:mail_instance].error_status != '4.4.1' + + # if header is available, do change current ticket state + mail['x-zammad-out-of-office'.to_sym] = true + + true + end +end diff --git a/db/migrate/20180830000001_setting_delivery_temporary_failed.rb b/db/migrate/20180830000001_setting_delivery_temporary_failed.rb new file mode 100644 index 000000000..e1ed92dab --- /dev/null +++ b/db/migrate/20180830000001_setting_delivery_temporary_failed.rb @@ -0,0 +1,19 @@ +class SettingDeliveryTemporaryFailed < ActiveRecord::Migration[5.1] + def up + + # return if it's a new setup + return if !Setting.find_by(name: 'system_init_done') + + Setting.create_if_not_exists( + title: 'Defines postmaster filter.', + name: '0955_postmaster_filter_bounce_delivery_temporary_failed', + area: 'Postmaster::PreFilter', + description: 'Defines postmaster filter to identify postmaster bounced - reopen ticket on permanent temporary failed.', + options: {}, + state: 'Channel::Filter::BounceDeliveryTemporaryFailed', + frontend: false + ) + + end + +end diff --git a/db/seeds/settings.rb b/db/seeds/settings.rb index 42eeed444..c34d669bc 100644 --- a/db/seeds/settings.rb +++ b/db/seeds/settings.rb @@ -3211,6 +3211,15 @@ Setting.create_if_not_exists( state: 'Channel::Filter::BounceDeliveryPermanentFailed', frontend: false ) +Setting.create_if_not_exists( + title: 'Defines postmaster filter.', + name: '0955_postmaster_filter_bounce_delivery_temporary_failed', + area: 'Postmaster::PreFilter', + description: 'Defines postmaster filter to identify postmaster bounced - reopen ticket on permanent temporary failed.', + options: {}, + state: 'Channel::Filter::BounceDeliveryTemporaryFailed', + frontend: false +) Setting.create_if_not_exists( title: 'Defines postmaster filter.', name: '1000_postmaster_filter_database_check', diff --git a/test/unit/email_process_bounce_delivery_permanent_failed_test.rb b/test/unit/email_process_bounce_delivery_permanent_failed_test.rb index 3bf543dff..27297f096 100644 --- a/test/unit/email_process_bounce_delivery_permanent_failed_test.rb +++ b/test/unit/email_process_bounce_delivery_permanent_failed_test.rb @@ -57,7 +57,7 @@ class EmailProcessBounceDeliveryPermanentFailedTest < ActiveSupport::TestCase updated_by_id: 1, ) - ticket = Ticket.create( + ticket = Ticket.create!( title: 'bounce check', group: Group.lookup(name: 'Users'), customer: customer1, @@ -66,7 +66,7 @@ class EmailProcessBounceDeliveryPermanentFailedTest < ActiveSupport::TestCase updated_by_id: 1, created_by_id: 1, ) - article = Ticket::Article.create( + article = Ticket::Article.create!( ticket_id: ticket.id, from: 'some_sender@example.com', to: 'some_recipient@example.com', @@ -83,7 +83,7 @@ class EmailProcessBounceDeliveryPermanentFailedTest < ActiveSupport::TestCase assert_equal('new', ticket.state.name) assert_equal(2, ticket.articles.count) - article = Ticket::Article.create( + article = Ticket::Article.create!( ticket_id: ticket.id, from: 'some_sender@example.com', to: customer1.email, @@ -164,7 +164,7 @@ class EmailProcessBounceDeliveryPermanentFailedTest < ActiveSupport::TestCase updated_by_id: 1, ) - ticket = Ticket.create( + ticket = Ticket.create!( title: 'bounce check', group: Group.lookup(name: 'Users'), customer: customer2, @@ -173,7 +173,7 @@ class EmailProcessBounceDeliveryPermanentFailedTest < ActiveSupport::TestCase updated_by_id: 1, created_by_id: 1, ) - article = Ticket::Article.create( + article = Ticket::Article.create!( ticket_id: ticket.id, from: 'some_sender@example.com', to: 'some_recipient@example.com', @@ -190,7 +190,7 @@ class EmailProcessBounceDeliveryPermanentFailedTest < ActiveSupport::TestCase assert_equal('new', ticket.state.name) assert_equal(2, ticket.articles.count) - article = Ticket::Article.create( + article = Ticket::Article.create!( ticket_id: ticket.id, from: 'some_sender@example.com', to: 'some_recipient@example.com', diff --git a/test/unit/email_process_bounce_delivery_temporary_failed_test.rb b/test/unit/email_process_bounce_delivery_temporary_failed_test.rb new file mode 100644 index 000000000..90ffd657f --- /dev/null +++ b/test/unit/email_process_bounce_delivery_temporary_failed_test.rb @@ -0,0 +1,110 @@ + +require 'test_helper' + +class EmailProcessBounceDeliveryTemporaryFailed < ActiveSupport::TestCase + + test 'process with temp faild bounce email' do + + ticket = Ticket.create!( + title: 'temp failed check - ms', + 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: 'temp failed 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, + ) + travel 1.second + + # temp faild bounce email + email_raw_string = "Content-Type: multipart/report; boundary=\"000000000000ca4a1a057417a375\"; report-type=delivery-status +From: Mail Delivery Subsystem +To: service@example.de +Auto-Submitted: auto-replied +Subject: Delivery Status Notification (Delay) +References: #{article.message_id} +In-Reply-To: #{article.message_id} +Message-ID: <5b7e8af4.1c69fb81.3ac1b.e296.GMRIR@mx.example.com> +Date: Thu, 23 Aug 2018 03:22:44 -0700 (PDT) + +--000000000000ca4a1a057417a375 +Content-Type: multipart/related; boundary=\"000000000000ca53d4057417a37c\" + +--000000000000ca53d4057417a37c +Content-Type: multipart/alternative; boundary=\"000000000000ca53de057417a37d\" + +--000000000000ca53de057417a37d +Content-Type: text/plain; charset=\"UTF-8\" +Content-Transfer-Encoding: quoted-printable + + +** Zustellung nicht abgeschlossen ** + +Bei der Zustellung Ihrer Nachricht an bob.smith@example.d= +e ist ein vor=C3=BCbergehendes Problem aufgetreten. Gmail versucht noch wei= +tere 46=C2=A0Stunden, die Nachricht zuzustellen. Sie werden benachrichtigt,= + falls die Zustellung dauerhaft fehlschl=C3=A4gt. + +Hier erfahren Sie mehr: https://support.example.com/mail/answer/7720 + +Antwort: + +The recipient server did not accept our requests to connect. Learn more at = +https://support.example.com/mail/answer/7720=20 +[example.de 00:00:00:c00::13: timed out] +[example.de 127.0.0.17: timed out] + +--000000000000ca4a1a057417a375 +Content-Type: message/delivery-status + +Reporting-MTA: dns; example.com +Received-From-MTA: dns; service@example.de +Arrival-Date: Wed, 22 Aug 2018 02:00:03 -0700 (PDT) +X-Original-Message-ID: #{article.message_id} + +Final-Recipient: rfc822; bob.smith@example.de +Action: delayed +Status: 4.4.1 +Diagnostic-Code: smtp; The recipient server did not accept our requests to connect. Learn more at https://support.example.com/mail/answer/7720 + [example.de 00:00:00:c00::13: timed out] + [example.de 127.0.0.17: timed out] + Last-Attempt-Date: Thu, 23 Aug 2018 03:22:44 -0700 (PDT) +Will-Retry-Until: Sat, 25 Aug 2018 02:00:04 -0700 (PDT) + +--000000000000ca4a1a057417a375 +Content-Type: message/rfc822 + +Date: Wed, 22 Aug 2018 11:00:03 +0200 +From: example Helpdesk +To: bob.smith@example.de +Message-ID: #{article.message_id} +Subject: Ihre Anfrage () [Ticket#638810] +Content-Type: text/plain; charset=UTF-8 + +ABC + +--000000000000ca4a1a057417a375-- +" + + 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) + + end + +end