From dc541597ec3d4cf6e13739a518b661e0f20c40a3 Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Tue, 8 Feb 2011 11:30:01 -0800 Subject: [PATCH] [#792] Send email from mail_handler for emails which are missing required information --- app/models/mail_handler.rb | 1 + ...et_on_project_with_missing_information.eml | 23 +++++++++++++++++++ test/unit/mail_handler_test.rb | 19 +++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 test/fixtures/mail_handler/ticket_on_project_with_missing_information.eml diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb index d801c35f..e1b10991 100644 --- a/app/models/mail_handler.rb +++ b/app/models/mail_handler.rb @@ -103,6 +103,7 @@ class MailHandler < ActionMailer::Base rescue ActiveRecord::RecordInvalid => e # TODO: send a email to the user logger.error 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 MissingInformation => e logger.error "MailHandler: missing information from #{user}: #{e.message}" if logger diff --git a/test/fixtures/mail_handler/ticket_on_project_with_missing_information.eml b/test/fixtures/mail_handler/ticket_on_project_with_missing_information.eml new file mode 100644 index 00000000..798bb03a --- /dev/null +++ b/test/fixtures/mail_handler/ticket_on_project_with_missing_information.eml @@ -0,0 +1,23 @@ +Return-Path: +Received: from osiris ([127.0.0.1]) + by OSIRIS + with hMailServer ; Sun, 22 Jun 2008 12:28:07 +0200 +Message-ID: <000501c8d452$a95cd7e0$0a00a8c0@osiris> +From: "John Smith" +To: +Subject: New ticket on a given project +Date: Sun, 22 Jun 2008 12:28:07 +0200 +MIME-Version: 1.0 +Content-Type: text/plain; + format=flowed; + charset="iso-8859-1"; + reply-type=original +Content-Transfer-Encoding: 7bit +X-Priority: 3 +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook Express 6.00.2900.2869 +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869 + +Test with missing information + +Project: onlinestore diff --git a/test/unit/mail_handler_test.rb b/test/unit/mail_handler_test.rb index 97ff167c..0386da11 100644 --- a/test/unit/mail_handler_test.rb +++ b/test/unit/mail_handler_test.rb @@ -497,6 +497,25 @@ class MailHandlerTest < ActiveSupport::TestCase assert mail.body.include?('Unable to determine target project') end + + should "deliver an email error confirmation to the sender for a missing other attributes" do + # Add a required custom field to simulate the error + project = Project.find('onlinestore') + project.issue_custom_fields << IssueCustomField.generate(:name => 'Required Custom Field0', :is_required => true, :trackers => project.trackers) + project.save + + ActionMailer::Base.deliveries.clear + issue = submit_email('ticket_on_project_with_missing_information.eml') + assert_equal false, issue + + 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.subject.include?('Failed email submission: New ticket on a given project') + assert mail.body.include?('There were errors with your email submission') + assert mail.body.include?('Required Custom Field0 can\'t be blank') + end end context "#receive_issue" do