Project

General

Profile

Defect #30785 » 30785-fix-v2.patch

Go MAEDA, 2019-02-17 06:01

View differences:

app/models/mail_handler.rb
91 91
    @handler_options = options
92 92
    sender_email = email.from.to_a.first.to_s.strip
93 93
    # Ignore emails received from the application emission address to avoid hell cycles
94
    if sender_email.casecmp(Setting.mail_from.to_s.strip) == 0
94
    emission_address = Setting.mail_from.to_s.gsub(/(?:.*<|>.*|\(.*\))/, '').strip
95
    if sender_email.casecmp(emission_address) == 0
95 96
      if logger
96 97
        logger.info  "MailHandler: ignoring email from Redmine emission address [#{sender_email}]"
97 98
      end
test/unit/mail_handler_test.rb
765 765
  end
766 766

  
767 767
  def test_should_ignore_emails_from_emission_address
768
    emission_addresses = [
769
      'redmine@example.net',
770
      'Redmine <redmine@example.net>',
771
      'redmine@example.net (Redmine)'
772
    ]
768 773
    Role.anonymous.add_permission!(:add_issues)
769
    assert_no_difference 'User.count' do
770
      assert_equal false,
771
                   submit_email(
772
                     'ticket_from_emission_address.eml',
773
                     :issue => {:project => 'ecookbook'},
774
                     :unknown_user => 'create'
775
                   )
774
    emission_addresses.each do |addr|
775
      with_settings :mail_from => addr do
776
        assert_no_difference 'User.count' do
777
          assert_equal false,
778
                      submit_email(
779
                        'ticket_from_emission_address.eml',
780
                        :issue => {:project => 'ecookbook'},
781
                        :unknown_user => 'create'
782
                      )
783
        end
784
      end
776 785
    end
777 786
  end
778 787

  
(2-2/2)