Index: test/unit/mailer_test.rb =================================================================== --- test/unit/mailer_test.rb (revision 2837) +++ test/unit/mailer_test.rb (working copy) @@ -238,4 +238,18 @@ 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 Index: app/models/mailer.rb =================================================================== --- app/models/mailer.rb (revision 2837) +++ app/models/mailer.rb (working copy) @@ -248,6 +248,14 @@ 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 Index: app/views/mailer/notify_incoming_error.text.plain.rhtml =================================================================== --- app/views/mailer/notify_incoming_error.text.plain.rhtml (revision 0) +++ app/views/mailer/notify_incoming_error.text.plain.rhtml (revision 0) @@ -0,0 +1,7 @@ +This email was received by redmine and could not be processed. + +From: <%= @original_mail.from %> +Subject: <%= @original_mail.subject %> +------ BEGIN ------- +<%= @original_mail.body %> +------ END ------- Index: lib/redmine/imap.rb =================================================================== --- lib/redmine/imap.rb (revision 2837) +++ lib/redmine/imap.rb (working copy) @@ -21,6 +21,7 @@ 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? @@ -41,10 +42,15 @@ 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 Index: lib/tasks/email.rake =================================================================== --- lib/tasks/email.rake (revision 2837) +++ lib/tasks/email.rake (working copy) @@ -91,6 +91,7 @@ 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: @@ -117,7 +118,8 @@ :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] }