0001-Output-log-entry-when-MailHandler-ignored-a-reply-to.patch

Go MAEDA, 2019-08-25 10:18

Download (4.21 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
    unless (issue = Issue.find_by(:id => issue_id))
221
      logger&.info "MailHandler: ignoring reply from [#{email.from.first}] to a nonexistent issue"
222
      return nil
223
    end
224

  
222 225
    # check permission
223 226
    unless handler_options[:no_permission_check]
224 227
      unless user.allowed_to?(:add_issue_notes, issue.project) ||
......
231 234
    handler_options[:issue] = {}
232 235

  
233 236
    journal = issue.init_journal(user)
234
    if from_journal && from_journal.private_notes?
237
    if from_journal&.private_notes?
235 238
      # If the received email was a reply to a private note, make the added note private
236 239
      issue.private_notes = true
237 240
    end
......
257 260

  
258 261
  # Receives a reply to a forum message
259 262
  def receive_message_reply(message_id)
260
    message = Message.find_by_id(message_id)
261
    if message
262
      message = message.root
263
    unless (message = Message.find_by(:id => message_id))
264
      logger&.info "MailHandler: ignoring reply from [#{email.from.first}] to a nonexistent message"
265
      return
266
    end
263 267

  
264
      unless handler_options[:no_permission_check]
265
        raise UnauthorizedAction unless user.allowed_to?(:add_messages, message.project)
266
      end
268
    message = message.root
267 269

  
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
270
    unless handler_options[:no_permission_check]
271
      raise UnauthorizedAction unless user.allowed_to?(:add_messages, message.project)
272
    end
273

  
274
    if !message.locked?
275
      reply = Message.new(:subject => cleaned_up_subject.gsub(/^.*msg\d+\]/, '').strip,
276
                          :content => cleaned_up_text_body)
277
      reply.author = user
278
      reply.board = message.board
279
      message.children << reply
280
      add_attachments(reply)
281
      reply
282
    else
283
      logger&.info "MailHandler: ignoring reply from [#{email.from.first}] to a locked topic"
279 284
    end
280 285
  end
281 286

  
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

  
988 998
  def test_reply_to_a_message
989 999
    m = submit_email('message_reply.eml')
990 1000
    assert m.is_a?(Message)
......
1015 1025
    end
1016 1026
  end
1017 1027

  
1028
  def test_reply_to_a_nonexistent_topic
1029
    Message.find(2).destroy
1030
    assert_no_difference('Message.count') do
1031
      m = submit_email('message_reply_by_subject.eml')
1032
      assert_nil m
1033
    end
1034
  end
1035

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