Ignore emails received from the application emission address to avoid hell cycles (#4139).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3022 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2009-11-08 13:51:53 +00:00
parent d4ccce3c72
commit cc684803ba
3 changed files with 35 additions and 3 deletions

View 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

View File

@ -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.

View 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'