@@ -0,0 +1,19 | |||||
|
1 | Return-Path: <redmine@somenet.foo> | |||
|
2 | Received: from osiris ([127.0.0.1]) | |||
|
3 | by OSIRIS | |||
|
4 | with hMailServer ; Sun, 22 Jun 2008 12:28:07 +0200 | |||
|
5 | Message-ID: <000501c8d452$a95cd7e0$0a00a8c0@osiris> | |||
|
6 | From: "John Doe" <Redmine@example.net> | |||
|
7 | To: <redmine@somenet.foo> | |||
|
8 | Subject: Ticket with the Redmine emission address | |||
|
9 | Date: Sun, 22 Jun 2008 12:28:07 +0200 | |||
|
10 | MIME-Version: 1.0 | |||
|
11 | Content-Type: text/plain; | |||
|
12 | format=flowed; | |||
|
13 | charset="iso-8859-1"; | |||
|
14 | reply-type=original | |||
|
15 | Content-Transfer-Encoding: 7bit | |||
|
16 | ||||
|
17 | This is a ticket submitted with the Redmine emission address. | |||
|
18 | It should be ignored. | |||
|
19 |
@@ -41,7 +41,13 class MailHandler < ActionMailer::Base | |||||
41 | # Returns the created object (eg. an issue, a message) or false |
|
41 | # Returns the created object (eg. an issue, a message) or false | |
42 | def receive(email) |
|
42 | def receive(email) | |
43 | @email = email |
|
43 | @email = email | |
44 |
|
|
44 | sender_email = email.from.to_a.first.to_s.strip | |
|
45 | # Ignore emails received from the application emission address to avoid hell cycles | |||
|
46 | if sender_email.downcase == Setting.mail_from.to_s.strip.downcase | |||
|
47 | logger.info "MailHandler: ignoring email from Redmine emission address [#{sender_email}]" if logger && logger.info | |||
|
48 | return false | |||
|
49 | end | |||
|
50 | @user = User.find_by_mail(sender_email) | |||
45 | if @user && !@user.active? |
|
51 | if @user && !@user.active? | |
46 | logger.info "MailHandler: ignoring email from non-active user [#{@user.login}]" if logger && logger.info |
|
52 | logger.info "MailHandler: ignoring email from non-active user [#{@user.login}]" if logger && logger.info | |
47 | return false |
|
53 | return false | |
@@ -57,12 +63,12 class MailHandler < ActionMailer::Base | |||||
57 | logger.info "MailHandler: [#{@user.login}] account created" if logger && logger.info |
|
63 | logger.info "MailHandler: [#{@user.login}] account created" if logger && logger.info | |
58 | Mailer.deliver_account_information(@user, @user.password) |
|
64 | Mailer.deliver_account_information(@user, @user.password) | |
59 | else |
|
65 | else | |
60 |
logger.error "MailHandler: could not create account for [#{email |
|
66 | logger.error "MailHandler: could not create account for [#{sender_email}]" if logger && logger.error | |
61 | return false |
|
67 | return false | |
62 | end |
|
68 | end | |
63 | else |
|
69 | else | |
64 | # Default behaviour, emails from unknown users are ignored |
|
70 | # Default behaviour, emails from unknown users are ignored | |
65 |
logger.info "MailHandler: ignoring email from unknown user [#{email |
|
71 | logger.info "MailHandler: ignoring email from unknown user [#{sender_email}]" if logger && logger.info | |
66 | return false |
|
72 | return false | |
67 | end |
|
73 | end | |
68 | end |
|
74 | end |
@@ -185,6 +185,13 class MailHandlerTest < ActiveSupport::TestCase | |||||
185 | assert_equal false, submit_email('ticket_without_from_header.eml') |
|
185 | assert_equal false, submit_email('ticket_without_from_header.eml') | |
186 | end |
|
186 | end | |
187 |
|
187 | |||
|
188 | def test_should_ignore_emails_from_emission_address | |||
|
189 | Role.anonymous.add_permission!(:add_issues) | |||
|
190 | assert_no_difference 'User.count' do | |||
|
191 | assert_equal false, submit_email('ticket_from_emission_address.eml', :issue => {:project => 'ecookbook'}, :unknown_user => 'create') | |||
|
192 | end | |||
|
193 | end | |||
|
194 | ||||
188 | def test_add_issue_should_send_email_notification |
|
195 | def test_add_issue_should_send_email_notification | |
189 | ActionMailer::Base.deliveries.clear |
|
196 | ActionMailer::Base.deliveries.clear | |
190 | # This email contains: 'Project: onlinestore' |
|
197 | # This email contains: 'Project: onlinestore' |
General Comments 0
You need to be logged in to leave comments.
Login now