]> source.dussan.org Git - redmine.git/commitdiff
Mail handler does not ignore emails sent from emission email address if Setting.mail_...
authorGo MAEDA <maeda@farend.jp>
Mon, 18 Feb 2019 13:21:18 +0000 (13:21 +0000)
committerGo MAEDA <maeda@farend.jp>
Mon, 18 Feb 2019 13:21:18 +0000 (13:21 +0000)
Patch by Go MAEDA.

git-svn-id: http://svn.redmine.org/redmine/trunk@17879 e93f8b46-1217-0410-a6f0-8f06a7374b81

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

index 9298e1b12b4fdbb28fba16ef94f45db0606fa547..be4b363b1de3d3590c31be9e817fc97b6e8653ac 100755 (executable)
@@ -91,7 +91,8 @@ class MailHandler < ActionMailer::Base
     @handler_options = options
     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.casecmp(Setting.mail_from.to_s.strip) == 0
+    emission_address = Setting.mail_from.to_s.gsub(/(?:.*<|>.*|\(.*\))/, '').strip
+    if sender_email.casecmp(emission_address) == 0
       if logger
         logger.info  "MailHandler: ignoring email from Redmine emission address [#{sender_email}]"
       end
index 0feb23d90f89e6b4cf18d530e8fecf8f7f40dc56..9d7fd6d129d8cdc9ec5adbdabffe5f0f27ae683e 100644 (file)
@@ -765,14 +765,23 @@ class MailHandlerTest < ActiveSupport::TestCase
   end
 
   def test_should_ignore_emails_from_emission_address
+    emission_addresses = [
+      'redmine@example.net',
+      'Redmine <redmine@example.net>',
+      'redmine@example.net (Redmine)'
+    ]
     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'
-                   )
+    emission_addresses.each do |addr|
+      with_settings :mail_from => addr do
+        assert_no_difference 'User.count' do
+          assert_equal false,
+                      submit_email(
+                        'ticket_from_emission_address.eml',
+                        :issue => {:project => 'ecookbook'},
+                        :unknown_user => 'create'
+                      )
+        end
+      end
     end
   end