Project

General

Profile

Defect #25269 » 25269-intentionaly_blank_emails.patch

Felix Schäfer, 2017-03-06 17:52

View differences:

app/models/mail_handler.rb
445 445
  def plain_text_body
446 446
    return @plain_text_body unless @plain_text_body.nil?
447 447

  
448
    # check if we have any plain-text parts with content
448 449
    @plain_text_body = email_parts_to_text(email.all_parts.select {|p| p.mime_type == 'text/plain'}).presence
449 450

  
451
    # if not, we try to parse the body from the HTML-parts
450 452
    @plain_text_body ||= email_parts_to_text(email.all_parts.select {|p| p.mime_type == 'text/html'}).presence
451 453

  
452
    @plain_text_body ||= email_parts_to_text([email])
454
    # If there is still no body found, and there are no mime-parts defined,
455
    # we use the whole raw mail body
456
    @plain_text_body ||= email_parts_to_text([email]).presence if email.all_parts.empty?
453 457

  
454
    @plain_text_body
458
    # As a fallback we return an empty plain text body (e.g. if we have only
459
    # empty text parts but a non-text attachment)
460
    @plain_text_body ||= ""
455 461
  end
456 462

  
457 463
  def email_parts_to_text(parts)
test/unit/mail_handler_test.rb
628 628
    assert_equal 'The html part.', issue.description
629 629
  end
630 630

  
631
  def test_empty_text_and_html_part_should_make_an_empty_description
632
    issue = submit_email('empty_text_and_html_part.eml', :issue => {:project => 'ecookbook'})
633
    assert_equal '', issue.description
634
  end
635

  
631 636
  def test_attachment_text_part_should_be_added_as_issue_attachment
632 637
    issue = submit_email('multiple_text_parts.eml', :issue => {:project => 'ecookbook'})
633 638
    assert_not_include 'Plain text attachment', issue.description
(1-1/2)