diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb index 7cffe209..d801c35f 100644 --- a/app/models/mail_handler.rb +++ b/app/models/mail_handler.rb @@ -106,6 +106,7 @@ class MailHandler < ActionMailer::Base false rescue MissingInformation => e logger.error "MailHandler: missing information from #{user}: #{e.message}" if logger + Mailer.deliver_mail_handler_missing_information(user, email.subject.to_s, e.message) if Setting.mail_handler_confirmation_on_failure false rescue UnauthorizedAction => e logger.error "MailHandler: unauthorized attempt from #{user}" if logger diff --git a/app/models/mailer.rb b/app/models/mailer.rb index 609f8fc8..92bb526c 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -316,6 +316,13 @@ class Mailer < ActionMailer::Base render_multipart('mail_handler_unauthorized_action', body) end + def mail_handler_missing_information(user, email_subject, error_message) + recipients user.mail + subject l(:label_mail_handler_failure, :subject => email_subject) + body({:errors => error_message.to_s}) + render_multipart('mail_handler_missing_information', body) + end + def test(user) redmine_headers 'Type' => "Test" set_language_if_valid(user.language) diff --git a/app/views/mailer/mail_handler_missing_information.text.html.rhtml b/app/views/mailer/mail_handler_missing_information.text.html.rhtml new file mode 100644 index 00000000..639e2aa6 --- /dev/null +++ b/app/views/mailer/mail_handler_missing_information.text.html.rhtml @@ -0,0 +1,3 @@ +

<%= l(:label_mail_handler_errors_with_submission) %>

+ +

<%= h(@errors) %>

diff --git a/app/views/mailer/mail_handler_missing_information.text.plain.rhtml b/app/views/mailer/mail_handler_missing_information.text.plain.rhtml new file mode 100644 index 00000000..458f515d --- /dev/null +++ b/app/views/mailer/mail_handler_missing_information.text.plain.rhtml @@ -0,0 +1,3 @@ +<%= l(:label_mail_handler_errors_with_submission) %> + +<%= h(@errors) %> diff --git a/config/locales/en.yml b/config/locales/en.yml index fde53c82..dd1f3b61 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -821,7 +821,8 @@ en: label_toc: "Contents" label_mail_handler_confirmation: "Confirmation of email submission: %{subject}" label_mail_handler_failure: "Failed email submission: %{subject}" - + label_mail_handler_errors_with_submission: "There were errors with your email submission:" + button_login: Login button_submit: Submit button_save: Save diff --git a/test/unit/mail_handler_test.rb b/test/unit/mail_handler_test.rb index 1f054910..97ff167c 100644 --- a/test/unit/mail_handler_test.rb +++ b/test/unit/mail_handler_test.rb @@ -476,12 +476,29 @@ class MailHandlerTest < ActiveSupport::TestCase assert_equal 1, ActionMailer::Base.deliveries.size mail = ActionMailer::Base.deliveries.last assert_not_nil mail - assert mail.bcc.include?('jsmith@somenet.foo') + assert mail.to.include?('jsmith@somenet.foo') assert mail.subject.include?('Failed email submission: Re: Add ingredients categories') assert mail.body.include?('You are not authorized to perform this action') end end + context "with an email that is missing required information" do + should "deliver an email error confirmation to the sender for a missing project" do + ActionMailer::Base.deliveries.clear + issue = submit_email('ticket_with_attachment.eml') # No project set + assert_equal false, issue + + assert_equal 1, ActionMailer::Base.deliveries.size + mail = ActionMailer::Base.deliveries.last + assert_not_nil mail + assert mail.to.include?('jsmith@somenet.foo') + assert mail.subject.include?('Failed email submission: Ticket created by email with attachment') + assert mail.body.include?('There were errors with your email submission') + assert mail.body.include?('Unable to determine target project') + + end + end + context "#receive_issue" do should "deliver an email confirmation when configured" do ActionMailer::Base.deliveries.clear