Patch #3732 » patch_incoming_mail_notify_error_with_test.diff
| test/unit/mailer_test.rb (working copy) | ||
|---|---|---|
| 238 | 238 |
assert mail.bcc.include?('dlopper@somenet.foo')
|
| 239 | 239 |
assert mail.body.include?('Bug #3: Error 281 when updating a recipe')
|
| 240 | 240 |
end |
| 241 |
|
|
| 242 |
def test_notify_incoming_error |
|
| 243 |
ActionMailer::Base.deliveries.clear |
|
| 244 |
raw = IO.read(File.join("test/fixtures/mail_handler/ticket_with_attributes.eml"))
|
|
| 245 |
Mailer.deliver_notify_incoming_error(raw) |
|
| 246 |
assert_equal 1, ActionMailer::Base.deliveries.size |
|
| 247 |
mail = ActionMailer::Base.deliveries.last |
|
| 248 |
assert mail.bcc.include?('admin@somenet.foo')
|
|
| 249 |
assert mail.subject.eql?('Incoming mail error notification')
|
|
| 250 |
assert mail.body.include?('This email was received by redmine and could not be processed.')
|
|
| 251 |
assert mail.body.include?('Lorem ipsum')
|
|
| 252 |
assert mail.body.include?('From: jsmith@somenet.foo')
|
|
| 253 |
assert mail.body.include?('Subject: New ticket on a given project')
|
|
| 254 |
end |
|
| 241 | 255 |
end |
| app/models/mailer.rb (working copy) | ||
|---|---|---|
| 248 | 248 |
subject 'Redmine test' |
| 249 | 249 |
body :url => url_for(:controller => 'welcome') |
| 250 | 250 |
end |
| 251 |
|
|
| 252 |
def notify_incoming_error(raw_email) |
|
| 253 |
recipients User.active.find(:all, :conditions => {:admin => true}).collect { |u| u.mail }.compact
|
|
| 254 |
subject 'Incoming mail error notification' |
|
| 255 |
orignal_mail = TMail::Mail.parse(raw_email) |
|
| 256 |
orignal_mail.base64_decode |
|
| 257 |
body :original_mail =>orignal_mail; |
|
| 258 |
end |
|
| 251 | 259 | |
| 252 | 260 |
# Overrides default deliver! method to prevent from sending an email |
| 253 | 261 |
# with no recipient, cc or bcc |
| app/views/mailer/notify_incoming_error.text.plain.rhtml (revision 0) | ||
|---|---|---|
| 1 |
This email was received by redmine and could not be processed. |
|
| 2 | ||
| 3 |
From: <%= @original_mail.from %> |
|
| 4 |
Subject: <%= @original_mail.subject %> |
|
| 5 |
------ BEGIN ------- |
|
| 6 |
<%= @original_mail.body %> |
|
| 7 |
------ END ------- |
|
| lib/redmine/imap.rb (working copy) | ||
|---|---|---|
| 21 | 21 |
module IMAP |
| 22 | 22 |
class << self |
| 23 | 23 |
def check(imap_options={}, options={})
|
| 24 |
logger.debug "Checking messages" if logger && logger.debug? |
|
| 24 | 25 |
host = imap_options[:host] || '127.0.0.1' |
| 25 | 26 |
port = imap_options[:port] || '143' |
| 26 | 27 |
ssl = !imap_options[:ssl].nil? |
| ... | ... | |
| 41 | 42 |
else |
| 42 | 43 |
logger.debug "Message #{message_id} can not be processed" if logger && logger.debug?
|
| 43 | 44 |
imap.store(message_id, "+FLAGS", [:Seen]) |
| 45 |
if imap_options[:notify_on_failure] |
|
| 46 |
logger.debug "Notify for failure" if logger && logger.debug? |
|
| 47 |
Mailer.deliver_notify_incoming_error(msg) |
|
| 48 |
end |
|
| 44 | 49 |
if imap_options[:move_on_failure] |
| 45 | 50 |
imap.copy(message_id, imap_options[:move_on_failure]) |
| 46 | 51 |
imap.store(message_id, "+FLAGS", [:Deleted]) |
| 47 | 52 |
end |
| 53 | ||
| 48 | 54 |
end |
| 49 | 55 |
end |
| 50 | 56 |
imap.expunge |
| lib/tasks/email.rake (working copy) | ||
|---|---|---|
| 91 | 91 |
move_on_success=MAILBOX move emails that were successfully received |
| 92 | 92 |
to MAILBOX instead of deleting them |
| 93 | 93 |
move_on_failure=MAILBOX move emails that were ignored to MAILBOX |
| 94 |
notify_on_failure notify redmine administrators when an error occurs |
|
| 94 | 95 |
|
| 95 | 96 |
Examples: |
| 96 | 97 |
# No project specified. Emails MUST contain the 'Project' keyword: |
| ... | ... | |
| 117 | 118 |
:password => ENV['password'], |
| 118 | 119 |
:folder => ENV['folder'], |
| 119 | 120 |
:move_on_success => ENV['move_on_success'], |
| 120 |
:move_on_failure => ENV['move_on_failure']} |
|
| 121 |
:move_on_failure => ENV['move_on_failure'], |
|
| 122 |
:notify_on_failure => ENV['notify_on_failure']} |
|
| 121 | 123 |
|
| 122 | 124 |
options = { :issue => {} }
|
| 123 | 125 |
%w(project status tracker category priority).each { |a| options[:issue][a.to_sym] = ENV[a] if ENV[a] }
|