]> source.dussan.org Git - redmine.git/commitdiff
Ignore emails with Auto-Submitted: auto-replied header (#10607).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 13 Apr 2012 16:55:04 +0000 (16:55 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 13 Apr 2012 16:55:04 +0000 (16:55 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9390 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/mail_handler.rb
test/unit/mail_handler_test.rb

index e0c12f1a0a4233abdfae401a4869218c2016d6ee..e920dbd5f11dd6d85f2681e0f7bdb22909766322 100644 (file)
@@ -42,6 +42,12 @@ class MailHandler < ActionMailer::Base
     super email
   end
 
+  cattr_accessor :ignored_emails_headers
+  @@ignored_emails_headers = {
+    'X-Auto-Response-Suppress' => 'OOF',
+    'Auto-Submitted' => 'auto-replied'
+  }
+
   # Processes incoming emails
   # Returns the created object (eg. an issue, a message) or false
   def receive(email)
@@ -54,12 +60,15 @@ class MailHandler < ActionMailer::Base
       end
       return false
     end
-    # Ignore out-of-office emails
-    if email.header_string("X-Auto-Response-Suppress") == 'OOF'
-      if logger && logger.info
-        logger.info  "MailHandler: ignoring out-of-office email"
+    # Ignore auto generated emails
+    self.class.ignored_emails_headers.each do |key, ignored_value|
+      value = email.header_string(key)
+      if value && value.to_s.downcase == ignored_value.downcase
+        if logger && logger.info
+          logger.info "MailHandler: ignoring email with #{key}:#{value} header"
+        end
+        return false
       end
-      return false
     end
     @user = User.find_by_mail(sender_email) if sender_email.present?
     if @user && !@user.active?
index 645a6f15f416b1c69b214e348561729c7a74166e..73a93088d30453483cd95a1b0004297c2f46ce57 100644 (file)
@@ -359,12 +359,18 @@ class MailHandlerTest < ActiveSupport::TestCase
     end
   end
 
-  def test_should_ignore_oof_emails
-    raw = IO.read(File.join(FIXTURES_PATH, 'ticket_on_given_project.eml'))
-    raw = "X-Auto-Response-Suppress: OOF\n" + raw
-
-    assert_no_difference 'Issue.count' do
-      assert_equal false, MailHandler.receive(raw)
+  def test_should_ignore_auto_replied_emails
+    [
+      "X-Auto-Response-Suppress: OOF",
+      "Auto-Submitted: auto-replied",
+      "Auto-Submitted: Auto-Replied"
+    ].each do |header|
+      raw = IO.read(File.join(FIXTURES_PATH, 'ticket_on_given_project.eml'))
+      raw = header + "\n" + raw
+  
+      assert_no_difference 'Issue.count' do
+        assert_equal false, MailHandler.receive(raw), "email with #{header} header was not ignored"
+      end
     end
   end