summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGo MAEDA <maeda@farend.jp>2023-02-27 09:43:37 +0000
committerGo MAEDA <maeda@farend.jp>2023-02-27 09:43:37 +0000
commit96a718547d643eacddb09155bad25bfc48457efe (patch)
tree8c0242a2184659c4cf701820e8d8ea2bacfbe7dd
parent1a663ec61713ee37d23f9a53f9e7f1cd21a50f46 (diff)
downloadredmine-96a718547d643eacddb09155bad25bfc48457efe.tar.gz
redmine-96a718547d643eacddb09155bad25bfc48457efe.zip
Try importing journal replies as issue reply where applicable (#38263).
Patch by Felix Schäfer. git-svn-id: https://svn.redmine.org/redmine/trunk@22119 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/models/mail_handler.rb11
-rw-r--r--test/unit/mail_handler_test.rb15
2 files changed, 20 insertions, 6 deletions
diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb
index 6da848124..2fa4de00d 100644
--- a/app/models/mail_handler.rb
+++ b/app/models/mail_handler.rb
@@ -263,15 +263,14 @@ class MailHandler < ActionMailer::Base
# Reply will be added to the issue
def receive_journal_reply(journal_id)
journal = Journal.find_by(:id => journal_id)
- if journal.nil?
- logger&.info "MailHandler: ignoring reply from [#{email.from.first}] to a nonexistent journal"
- return nil
- end
- if journal.journalized_type == 'Issue'
+ if journal && journal.journalized_type == 'Issue'
receive_issue_reply(journal.journalized_id, journal)
+ elsif m = email.subject.to_s.match(ISSUE_REPLY_SUBJECT_RE)
+ 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 from [#{email.from.first}] to a journal whose journalized_type is not Issue"
+ logger&.info "MailHandler: ignoring reply to a nonexistant journal or issue"
return nil
end
end
diff --git a/test/unit/mail_handler_test.rb b/test/unit/mail_handler_test.rb
index bc9439c68..01279a117 100644
--- a/test/unit/mail_handler_test.rb
+++ b/test/unit/mail_handler_test.rb
@@ -1114,6 +1114,21 @@ class MailHandlerTest < ActiveSupport::TestCase
end
end
+ def test_reply_to_a_nonexitent_journal_with_subject_fallback
+ journal_id = Issue.find(2).journals.last.id
+ Journal.destroy(journal_id)
+ assert_no_difference 'Issue.count' do
+ assert_difference 'Journal.count', 1 do
+ journal = submit_email('ticket_reply.eml') do |email|
+ email.sub! %r{^In-Reply-To:.*$}, "In-Reply-To: <redmine.journal-#{journal_id}.20060719210421@osiris>"
+ email.sub! %r{^Subject:.*$}, "Subject: Re: [Feature request #2] Add ingredients categories"
+ end
+ assert_kind_of Journal, journal
+ assert_equal Issue.find(2), journal.journalized
+ end
+ end
+ end
+
def test_reply_to_a_message
m = submit_email('message_reply.eml')
assert m.is_a?(Message)