Browse Source

Improved detection of auto generated emails / prevent auto responder.

Martin Edenhofer 8 years ago
parent
commit
570e3c981a

+ 2 - 2
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|

+ 9 - 0
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
 

+ 33 - 0
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: <mailto:somebody@example.com>
+
+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: <XX@XX.XX>
 X-Original-To: sales@znuny.com
 Received: from mail-qk0-f170.example.com (mail-qk0-f170.example.com [209.1.1.1])