From 570e3c981a78e4a74e9e7042a7907a420dd28590 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Wed, 23 Nov 2016 15:28:12 +0100 Subject: [PATCH] Improved detection of auto generated emails / prevent auto responder. --- app/models/channel/email_build.rb | 4 +-- .../channel/filter/auto_response_check.rb | 9 +++++ test/unit/email_process_auto_response_test.rb | 33 +++++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/app/models/channel/email_build.rb b/app/models/channel/email_build.rb index 540ae4763..31eb5f60d 100644 --- a/app/models/channel/email_build.rb +++ b/app/models/channel/email_build.rb @@ -32,8 +32,8 @@ module Channel::EmailBuild attr['X-Auto-Response-Suppress'] = 'All' end - #attr['X-Powered-BY'] = 'Zammad - Support/Helpdesk (http://www.zammad.org/)' - attr['X-Mailer'] = 'Zammad Mail Service (1.x)' + attr['X-Powered-By'] = 'Zammad - Helpdesk/Support (https://zammad.org/)' + attr['X-Mailer'] = 'Zammad Mail Service' # set headers attr.each do |key, value| diff --git a/app/models/channel/filter/auto_response_check.rb b/app/models/channel/filter/auto_response_check.rb index c6481beca..588094802 100644 --- a/app/models/channel/filter/auto_response_check.rb +++ b/app/models/channel/filter/auto_response_check.rb @@ -14,11 +14,20 @@ module Channel::Filter::AutoResponseCheck mail[ 'x-zammad-article-preferences'.to_sym ]['send-auto-response'] = false mail[ 'x-zammad-article-preferences'.to_sym ]['is-auto-response'] = true + # do not send an auto respondse if one of the following headers exists + return if mail[ 'list-unsubscribe'.to_sym ] && mail[ 'list-unsubscribe'.to_sym ] =~ /.../ 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|list|junk)/i return if mail[ 'auto-submitted'.to_sym ] && mail[ 'auto-submitted'.to_sym ] =~ /auto-(generated|replied)/i return if mail[ 'x-auto-response-suppress'.to_sym ] && mail[ 'x-auto-response-suppress'.to_sym ] =~ /all/i + # do not send an auto respondse if sender is system it self + message_id = mail[ 'message_id'.to_sym ] + if message_id + fqdn = Setting.get('fqdn') + return if message_id =~ /@#{Regexp.quote(fqdn)}/i + end + mail[ 'x-zammad-send-auto-response'.to_sym ] = true mail[ 'x-zammad-is-auto-response'.to_sym ] = false diff --git a/test/unit/email_process_auto_response_test.rb b/test/unit/email_process_auto_response_test.rb index a0b37e928..1d81118f6 100644 --- a/test/unit/email_process_auto_response_test.rb +++ b/test/unit/email_process_auto_response_test.rb @@ -105,6 +105,39 @@ Some Text" Scheduler.worker(true) assert_equal(1, article_p.ticket.articles.count) + email_raw_string = "From: me@example.com +To: customer@example.com +Subject: some new subject +List-Unsubscribe: + +Some Text" + + fqdn = Setting.get('fqdn') + email_raw_string = "From: me@example.com +To: customer@example.com +Subject: some new subject +Message-ID: <1234@#{fqdn}> + +Some Text" + + ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string) + assert_equal(false, mail['x-zammad-send-auto-response'.to_sym]) + Scheduler.worker(true) + assert_equal(1, article_p.ticket.articles.count) + + fqdn = Setting.get('fqdn') + email_raw_string = "From: me@example.com +To: customer@example.com +Subject: some new subject +Message-ID: <1234@not_matching.#{fqdn}> + +Some Text" + + ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string) + assert_equal(true, mail['x-zammad-send-auto-response'.to_sym]) + Scheduler.worker(true) + assert_equal(2, article_p.ticket.articles.count) + email_raw_string = "Return-Path: X-Original-To: sales@znuny.com Received: from mail-qk0-f170.example.com (mail-qk0-f170.example.com [209.1.1.1])