Ignore emails with Auto-Submitted: auto-replied header (#10607).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9390 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
dd8d8e0560
commit
4edc30d157
|
@ -42,6 +42,12 @@ class MailHandler < ActionMailer::Base
|
||||||
super email
|
super email
|
||||||
end
|
end
|
||||||
|
|
||||||
|
cattr_accessor :ignored_emails_headers
|
||||||
|
@@ignored_emails_headers = {
|
||||||
|
'X-Auto-Response-Suppress' => 'OOF',
|
||||||
|
'Auto-Submitted' => 'auto-replied'
|
||||||
|
}
|
||||||
|
|
||||||
# Processes incoming emails
|
# Processes incoming emails
|
||||||
# Returns the created object (eg. an issue, a message) or false
|
# Returns the created object (eg. an issue, a message) or false
|
||||||
def receive(email)
|
def receive(email)
|
||||||
|
@ -54,12 +60,15 @@ class MailHandler < ActionMailer::Base
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
# Ignore out-of-office emails
|
# Ignore auto generated emails
|
||||||
if email.header_string("X-Auto-Response-Suppress") == 'OOF'
|
self.class.ignored_emails_headers.each do |key, ignored_value|
|
||||||
if logger && logger.info
|
value = email.header_string(key)
|
||||||
logger.info "MailHandler: ignoring out-of-office email"
|
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
|
end
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
@user = User.find_by_mail(sender_email) if sender_email.present?
|
@user = User.find_by_mail(sender_email) if sender_email.present?
|
||||||
if @user && !@user.active?
|
if @user && !@user.active?
|
||||||
|
|
|
@ -359,12 +359,18 @@ class MailHandlerTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_should_ignore_oof_emails
|
def test_should_ignore_auto_replied_emails
|
||||||
raw = IO.read(File.join(FIXTURES_PATH, 'ticket_on_given_project.eml'))
|
[
|
||||||
raw = "X-Auto-Response-Suppress: OOF\n" + raw
|
"X-Auto-Response-Suppress: OOF",
|
||||||
|
"Auto-Submitted: auto-replied",
|
||||||
assert_no_difference 'Issue.count' do
|
"Auto-Submitted: Auto-Replied"
|
||||||
assert_equal false, MailHandler.receive(raw)
|
].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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue