]> source.dussan.org Git - redmine.git/commitdiff
Merged r17878 and r17879 from trunk to 4.0-stable (#30785).
authorGo MAEDA <maeda@farend.jp>
Mon, 18 Feb 2019 13:51:26 +0000 (13:51 +0000)
committerGo MAEDA <maeda@farend.jp>
Mon, 18 Feb 2019 13:51:26 +0000 (13:51 +0000)
git-svn-id: http://svn.redmine.org/redmine/branches/4.0-stable@17880 e93f8b46-1217-0410-a6f0-8f06a7374b81

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

index 6586c52bb8160fd83514ff1e1ad520b10ebd5696..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_address) == 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 e6de85906f810a438d20fc04e78eec60903d37c4..e59c48c86c802e811eb1d5bd9104e341032dd0e2 100644 (file)
@@ -228,12 +228,6 @@ class Setting < ActiveRecord::Base
     Object.const_defined?(:OpenID) && self[:openid].to_i > 0
   end
 
-  # Extracts an email address ("joe@example.com") from
-  # Setting.mail_from ("Joe Bloggs <joe@example.com>")
-  def self.mail_from_address
-    self.mail_from.to_s.gsub(/(?:.*<|>.*|\(.*\))/, '').strip
-  end
-
   # Checks if settings have changed since the values were read
   # and clears the cache hash if it's the case
   # Called once per request
index 5c3a570b71319816cd1aac133b4c2d425f6a86cc..246434e3c43179f98bd78978733b733707c98917 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
 
index 2e184f36bf75a7f9b4d85f6e4aa987339133a8c6..b65717dbe5cec0c1bf1b3a00ca46774513c3bebe 100644 (file)
@@ -108,23 +108,6 @@ class SettingTest < ActiveSupport::TestCase
     end
   end
 
-  def test_mail_from_address
-    mail_from_strings = [
-      'joe@example.com',
-      '<joe@example.com>',
-      'Joe Bloggs <joe@example.com>',
-      'display_name@example.com <joe@example.com>',
-      'joe@example.com (Joe Bloggs)',
-      'joe@example.com (display_name@example.com)'
-    ]
-
-    mail_from_strings.each do |from_value|
-      with_settings :mail_from => from_value do
-        assert_equal 'joe@example.com', Setting.mail_from_address
-      end
-    end
-  end
-
   def test_setting_serialied_as_binary_should_be_loaded_as_utf8_encoded_strings
     yaml = <<-YAML
 ---