Patch #3732 » patch_incoming_mail_notify_error_with_test.diff
| test/unit/mailer_test.rb (working copy) | ||
|---|---|---|
|
assert mail.bcc.include?('dlopper@somenet.foo')
|
||
|
assert mail.body.include?('Bug #3: Error 281 when updating a recipe')
|
||
|
end
|
||
|
|
||
|
def test_notify_incoming_error
|
||
|
ActionMailer::Base.deliveries.clear
|
||
|
raw = IO.read(File.join("test/fixtures/mail_handler/ticket_with_attributes.eml"))
|
||
|
Mailer.deliver_notify_incoming_error(raw)
|
||
|
assert_equal 1, ActionMailer::Base.deliveries.size
|
||
|
mail = ActionMailer::Base.deliveries.last
|
||
|
assert mail.bcc.include?('admin@somenet.foo')
|
||
|
assert mail.subject.eql?('Incoming mail error notification')
|
||
|
assert mail.body.include?('This email was received by redmine and could not be processed.')
|
||
|
assert mail.body.include?('Lorem ipsum')
|
||
|
assert mail.body.include?('From: jsmith@somenet.foo')
|
||
|
assert mail.body.include?('Subject: New ticket on a given project')
|
||
|
end
|
||
|
end
|
||
| app/models/mailer.rb (working copy) | ||
|---|---|---|
|
subject 'Redmine test'
|
||
|
body :url => url_for(:controller => 'welcome')
|
||
|
end
|
||
|
|
||
|
def notify_incoming_error(raw_email)
|
||
|
recipients User.active.find(:all, :conditions => {:admin => true}).collect { |u| u.mail }.compact
|
||
|
subject 'Incoming mail error notification'
|
||
|
orignal_mail = TMail::Mail.parse(raw_email)
|
||
|
orignal_mail.base64_decode
|
||
|
body :original_mail =>orignal_mail;
|
||
|
end
|
||
|
# Overrides default deliver! method to prevent from sending an email
|
||
|
# with no recipient, cc or bcc
|
||
| app/views/mailer/notify_incoming_error.text.plain.rhtml (revision 0) | ||
|---|---|---|
|
This email was received by redmine and could not be processed.
|
||
|
From: <%= @original_mail.from %>
|
||
|
Subject: <%= @original_mail.subject %>
|
||
|
------ BEGIN -------
|
||
|
<%= @original_mail.body %>
|
||
|
------ END -------
|
||
| lib/redmine/imap.rb (working copy) | ||
|---|---|---|
|
module IMAP
|
||
|
class << self
|
||
|
def check(imap_options={}, options={})
|
||
|
logger.debug "Checking messages" if logger && logger.debug?
|
||
|
host = imap_options[:host] || '127.0.0.1'
|
||
|
port = imap_options[:port] || '143'
|
||
|
ssl = !imap_options[:ssl].nil?
|
||
| ... | ... | |
|
else
|
||
|
logger.debug "Message #{message_id} can not be processed" if logger && logger.debug?
|
||
|
imap.store(message_id, "+FLAGS", [:Seen])
|
||
|
if imap_options[:notify_on_failure]
|
||
|
logger.debug "Notify for failure" if logger && logger.debug?
|
||
|
Mailer.deliver_notify_incoming_error(msg)
|
||
|
end
|
||
|
if imap_options[:move_on_failure]
|
||
|
imap.copy(message_id, imap_options[:move_on_failure])
|
||
|
imap.store(message_id, "+FLAGS", [:Deleted])
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
imap.expunge
|
||
| lib/tasks/email.rake (working copy) | ||
|---|---|---|
|
move_on_success=MAILBOX move emails that were successfully received
|
||
|
to MAILBOX instead of deleting them
|
||
|
move_on_failure=MAILBOX move emails that were ignored to MAILBOX
|
||
|
notify_on_failure notify redmine administrators when an error occurs
|
||
|
|
||
|
Examples:
|
||
|
# No project specified. Emails MUST contain the 'Project' keyword:
|
||
| ... | ... | |
|
:password => ENV['password'],
|
||
|
:folder => ENV['folder'],
|
||
|
:move_on_success => ENV['move_on_success'],
|
||
|
:move_on_failure => ENV['move_on_failure']}
|
||
|
:move_on_failure => ENV['move_on_failure'],
|
||
|
:notify_on_failure => ENV['notify_on_failure']}
|
||
|
|
||
|
options = { :issue => {} }
|
||
|
%w(project status tracker category priority).each { |a| options[:issue][a.to_sym] = ENV[a] if ENV[a] }
|
||