]> source.dussan.org Git - redmine.git/commitdiff
Ignore emails received from the application emission address to avoid hell cycles...
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 8 Nov 2009 13:51:53 +0000 (13:51 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 8 Nov 2009 13:51:53 +0000 (13:51 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3022 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/mail_handler.rb
test/fixtures/mail_handler/ticket_from_emission_address.eml [new file with mode: 0644]
test/unit/mail_handler_test.rb

index 8686c6b016e28bfef640bb1054ae87bd0b5b3721..23a51d83a001d6dabc8853ae65c1f7af83f28ed5 100644 (file)
@@ -41,7 +41,13 @@ class MailHandler < ActionMailer::Base
   # Returns the created object (eg. an issue, a message) or false
   def receive(email)
     @email = email
-    @user = User.find_by_mail(email.from.to_a.first.to_s.strip)
+    sender_email = email.from.to_a.first.to_s.strip
+    # Ignore emails received from the application emission address to avoid hell cycles
+    if sender_email.downcase == Setting.mail_from.to_s.strip.downcase
+      logger.info  "MailHandler: ignoring email from Redmine emission address [#{sender_email}]" if logger && logger.info
+      return false
+    end
+    @user = User.find_by_mail(sender_email)
     if @user && !@user.active?
       logger.info  "MailHandler: ignoring email from non-active user [#{@user.login}]" if logger && logger.info
       return false
@@ -57,12 +63,12 @@ class MailHandler < ActionMailer::Base
           logger.info "MailHandler: [#{@user.login}] account created" if logger && logger.info
           Mailer.deliver_account_information(@user, @user.password)
         else
-          logger.error "MailHandler: could not create account for [#{email.from.first}]" if logger && logger.error
+          logger.error "MailHandler: could not create account for [#{sender_email}]" if logger && logger.error
           return false
         end
       else
         # Default behaviour, emails from unknown users are ignored
-        logger.info  "MailHandler: ignoring email from unknown user [#{email.from.first}]" if logger && logger.info
+        logger.info  "MailHandler: ignoring email from unknown user [#{sender_email}]" if logger && logger.info
         return false
       end
     end
diff --git a/test/fixtures/mail_handler/ticket_from_emission_address.eml b/test/fixtures/mail_handler/ticket_from_emission_address.eml
new file mode 100644 (file)
index 0000000..bdb2d21
--- /dev/null
@@ -0,0 +1,19 @@
+Return-Path: <redmine@somenet.foo>
+Received: from osiris ([127.0.0.1])
+       by OSIRIS
+       with hMailServer ; Sun, 22 Jun 2008 12:28:07 +0200
+Message-ID: <000501c8d452$a95cd7e0$0a00a8c0@osiris>
+From: "John Doe" <Redmine@example.net>
+To: <redmine@somenet.foo>
+Subject: Ticket with the Redmine emission address
+Date: Sun, 22 Jun 2008 12:28:07 +0200
+MIME-Version: 1.0
+Content-Type: text/plain;
+       format=flowed;
+       charset="iso-8859-1";
+       reply-type=original
+Content-Transfer-Encoding: 7bit
+
+This is a ticket submitted with the Redmine emission address.
+It should be ignored.
+
index 9b6c28ba3d4dc1c83b08bcb5e3747c7ba2b05551..7e7dfa0c83749c6128530587564a3eef31f1b3a5 100644 (file)
@@ -185,6 +185,13 @@ class MailHandlerTest < ActiveSupport::TestCase
     assert_equal false, submit_email('ticket_without_from_header.eml')
   end
 
+  def test_should_ignore_emails_from_emission_address
+    Role.anonymous.add_permission!(:add_issues)
+    assert_no_difference 'User.count' do
+      assert_equal false, submit_email('ticket_from_emission_address.eml', :issue => {:project => 'ecookbook'}, :unknown_user => 'create')
+    end
+  end
+
   def test_add_issue_should_send_email_notification
     ActionMailer::Base.deliveries.clear
     # This email contains: 'Project: onlinestore'