Project

General

Profile

Feature #38263 » 38263-with_test.patch

Felix Schäfer, 2023-02-15 19:57

View differences:

app/models/mail_handler.rb
263 263
  # Reply will be added to the issue
264 264
  def receive_journal_reply(journal_id)
265 265
    journal = Journal.find_by(:id => journal_id)
266
    if journal.nil?
267
      logger&.info "MailHandler: ignoring reply from [#{email.from.first}] to a nonexistent journal"
268
      return nil
269
    end
270 266

  
271
    if journal.journalized_type == 'Issue'
267
    if journal && journal.journalized_type == 'Issue'
272 268
      receive_issue_reply(journal.journalized_id, journal)
269
    elsif m = email.subject.to_s.match(ISSUE_REPLY_SUBJECT_RE)
270
      logger&.info "MailHandler: reply to a nonexistant journal, calling receive_issue_reply with issue from subject"
271
      receive_issue_reply(m[1].to_i)
273 272
    else
274
      logger&.info "MailHandler: ignoring reply from [#{email.from.first}] to a journal whose journalized_type is not Issue"
273
      logger&.info "MailHandler: ignoring reply to a nonexistant journal or issue"
275 274
      return nil
276 275
    end
277 276
  end
test/unit/mail_handler_test.rb
1114 1114
    end
1115 1115
  end
1116 1116

  
1117
  def test_reply_to_a_nonexitent_journal_with_subject_fallback
1118
    journal_id = Issue.find(2).journals.last.id
1119
    Journal.destroy(journal_id)
1120
    assert_no_difference 'Issue.count' do
1121
      assert_difference 'Journal.count', 1 do
1122
        journal = submit_email('ticket_reply.eml') do |email|
1123
          email.sub! %r{^In-Reply-To:.*$}, "In-Reply-To: <redmine.journal-#{journal_id}.20060719210421@osiris>"
1124
          email.sub! %r{^Subject:.*$}, "Subject: Re: [Feature request #2] Add ingredients categories"
1125
        end
1126
        puts journal.inspect
1127
        assert_kind_of Journal, journal
1128
        assert_equal Issue.find(2), journal.journalized
1129
      end
1130
    end
1131
  end
1132

  
1117 1133
  def test_reply_to_a_message
1118 1134
    m = submit_email('message_reply.eml')
1119 1135
    assert m.is_a?(Message)
(2-2/2)