0001-Log-info-messages-when-MailHandler-ignored-a-reply-t.patch

Go MAEDA, 2019-09-14 06:21

Download (5.09 KB)

View differences:

app/models/mail_handler.rb
217 217

  
218 218
  # Adds a note to an existing issue
219 219
  def receive_issue_reply(issue_id, from_journal=nil)
220
    issue = Issue.find_by_id(issue_id)
221
    return unless issue
220
    issue = Issue.find_by(:id => issue_id)
221
    if issue.nil?
222
      logger&.info "MailHandler: ignoring reply from [#{email.from.first}] to a nonexistent issue"
223
      return nil
224
    end
225

  
222 226
    # check permission
223 227
    unless handler_options[:no_permission_check]
224 228
      unless user.allowed_to?(:add_issue_notes, issue.project) ||
......
249 253

  
250 254
  # Reply will be added to the issue
251 255
  def receive_journal_reply(journal_id)
252
    journal = Journal.find_by_id(journal_id)
253
    if journal && journal.journalized_type == 'Issue'
256
    journal = Journal.find_by(:id => journal_id)
257
    if journal.nil?
258
      logger&.info "MailHandler: ignoring reply from [#{email.from.first}] to a nonexistent journal"
259
      return nil
260
    end
261

  
262
    if journal.journalized_type == 'Issue'
254 263
      receive_issue_reply(journal.journalized_id, journal)
264
    else
265
      logger&.info "MailHandler: ignoring reply from [#{email.from.first}] to a journal whose journalized_type is not Issue"
266
      return nil
255 267
    end
256 268
  end
257 269

  
258 270
  # Receives a reply to a forum message
259 271
  def receive_message_reply(message_id)
260
    message = Message.find_by_id(message_id)
261
    if message
262
      message = message.root
272
    message = Message.find_by(:id => message_id)&.root
273
    if message.nil?
274
      logger&.info "MailHandler: ignoring reply from [#{email.from.first}] to a nonexistent message"
275
      return nil
276
    end
263 277

  
264
      unless handler_options[:no_permission_check]
265
        raise UnauthorizedAction, "not allowed to add messages to project [#{project.name}]" unless user.allowed_to?(:add_messages, message.project)
266
      end
278
    unless handler_options[:no_permission_check]
279
      raise UnauthorizedAction, "not allowed to add messages to project [#{project.name}]" unless user.allowed_to?(:add_messages, message.project)
280
    end
267 281

  
268
      if !message.locked?
269
        reply = Message.new(:subject => cleaned_up_subject.gsub(%r{^.*msg\d+\]}, '').strip,
270
                            :content => cleaned_up_text_body)
271
        reply.author = user
272
        reply.board = message.board
273
        message.children << reply
274
        add_attachments(reply)
275
        reply
276
      else
277
        logger&.info "MailHandler: ignoring reply from [#{email.from.first}] to a locked topic"
278
      end
282
    if !message.locked?
283
      reply = Message.new(:subject => cleaned_up_subject.gsub(%r{^.*msg\d+\]}, '').strip,
284
                          :content => cleaned_up_text_body)
285
      reply.author = user
286
      reply.board = message.board
287
      message.children << reply
288
      add_attachments(reply)
289
      reply
290
    else
291
      logger&.info "MailHandler: ignoring reply from [#{email.from.first}] to a locked topic"
279 292
    end
280 293
  end
281 294

  
test/unit/mail_handler_test.rb
985 985
    end
986 986
  end
987 987

  
988
  def test_reply_to_a_nonexistent_issue
989
    Issue.find(2).destroy
990
    assert_no_difference 'Issue.count' do
991
      assert_no_difference 'Journal.count' do
992
        journal = submit_email('ticket_reply_with_status.eml')
993
        assert_nil journal
994
      end
995
    end
996
  end
997

  
998
  def test_reply_to_a_nonexitent_journal
999
    journal_id = Issue.find(2).journals.last.id
1000
    Journal.destroy(journal_id)
1001
    assert_no_difference 'Issue.count' do
1002
      assert_no_difference 'Journal.count' do
1003
        journal = submit_email('ticket_reply.eml') do |email|
1004
          email.sub! %r{^In-Reply-To:.*$}, "In-Reply-To: <redmine.journal-#{journal_id}.20060719210421@osiris>"
1005
        end
1006
        assert_nil journal
1007
      end
1008
    end
1009
  end
1010

  
988 1011
  def test_reply_to_a_message
989 1012
    m = submit_email('message_reply.eml')
990 1013
    assert m.is_a?(Message)
......
1015 1038
    end
1016 1039
  end
1017 1040

  
1041
  def test_reply_to_a_nonexistent_topic
1042
    Message.find(2).destroy
1043
    assert_no_difference('Message.count') do
1044
      m = submit_email('message_reply_by_subject.eml')
1045
      assert_nil m
1046
    end
1047
  end
1048

  
1018 1049
  def test_should_convert_tags_of_html_only_emails
1019 1050
    with_settings :text_formatting => 'textile' do
1020 1051
      issue = submit_email('ticket_html_only.eml', :issue => {:project => 'ecookbook'})
1021
-