From: Go MAEDA Date: Sun, 26 Mar 2023 05:11:26 +0000 (+0000) Subject: Add MissingContainer exception to MailHandler (#38273). X-Git-Tag: 5.1.0~201 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=79f0c64e29791b7b4084e1c35c3a889be7ff06ba;p=redmine.git Add MissingContainer exception to MailHandler (#38273). Patch by Felix Schäfer. git-svn-id: https://svn.redmine.org/redmine/trunk@22158 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb index 5925608bd..738feb30e 100644 --- a/app/models/mail_handler.rb +++ b/app/models/mail_handler.rb @@ -25,6 +25,7 @@ class MailHandler < ActionMailer::Base class NotAllowedInProject < UnauthorizedAction; end class InsufficientPermissions < UnauthorizedAction; end class MissingInformation < StandardError; end + class MissingContainer < StandardError; end attr_reader :email, :user, :handler_options @@ -172,6 +173,9 @@ class MailHandler < ActionMailer::Base rescue MissingInformation => e logger&.error "MailHandler: missing information from #{user}: #{e.message}" false + rescue MissingContainer => e + logger&.error "MailHandler: reply to nonexistant object from #{user}: #{e.message}" + false rescue UnauthorizedAction => e logger&.error "MailHandler: unauthorized attempt from #{user}: #{e.message}" false @@ -225,8 +229,7 @@ class MailHandler < ActionMailer::Base def receive_issue_reply(issue_id, from_journal=nil) issue = Issue.find_by(:id => issue_id) if issue.nil? - logger&.info "MailHandler: ignoring reply from [#{email.from.first}] to a nonexistent issue" - return nil + raise MissingContainer, "reply to nonexistant issue [##{issue_id}]" end # Never receive emails to projects where adding issue notes is not possible @@ -270,8 +273,7 @@ class MailHandler < ActionMailer::Base logger&.info "MailHandler: reply to a nonexistant journal, calling receive_issue_reply with issue from subject" receive_issue_reply(m[1].to_i) else - logger&.info "MailHandler: ignoring reply to a nonexistant journal or issue" - return nil + raise MissingContainer, "reply to nonexistant journal [#{journal_id}]" end end @@ -279,8 +281,7 @@ class MailHandler < ActionMailer::Base def receive_message_reply(message_id) message = Message.find_by(:id => message_id)&.root if message.nil? - logger&.info "MailHandler: ignoring reply from [#{email.from.first}] to a nonexistent message" - return nil + raise MissingContainer, "reply to nonexistant message [#{message_id}]" end # Never receive emails to projects where adding messages is not possible diff --git a/test/unit/mail_handler_test.rb b/test/unit/mail_handler_test.rb index 01279a117..a038d59b1 100644 --- a/test/unit/mail_handler_test.rb +++ b/test/unit/mail_handler_test.rb @@ -1084,7 +1084,7 @@ class MailHandlerTest < ActiveSupport::TestCase assert_no_difference 'Issue.count' do assert_no_difference 'Journal.count' do journal = submit_email('ticket_reply_with_status.eml') - assert_nil journal + assert_not journal end end end @@ -1109,7 +1109,7 @@ class MailHandlerTest < ActiveSupport::TestCase journal = submit_email('ticket_reply.eml') do |email| email.sub! %r{^In-Reply-To:.*$}, "In-Reply-To: " end - assert_nil journal + assert_not journal end end end @@ -1163,7 +1163,7 @@ class MailHandlerTest < ActiveSupport::TestCase Message.find(2).destroy assert_no_difference('Message.count') do m = submit_email('message_reply_by_subject.eml') - assert_nil m + assert_not m end end