# 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
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
--- /dev/null
+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.
+
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'