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
def plain_text_body
return @plain_text_body unless @plain_text_body.nil?
# check if we have any plain-text parts with content
@plain_text_body = email_parts_to_text(email.all_parts.select {|p| p.mime_type == 'text/plain'}).presence
# if not, we try to parse the body from the HTML-parts
@plain_text_body ||= email_parts_to_text(email.all_parts.select {|p| p.mime_type == 'text/html'}).presence
@plain_text_body ||= email_parts_to_text([email])
# If there is still no body found, and there are no mime-parts defined,
# we use the whole raw mail body
@plain_text_body ||= email_parts_to_text([email]).presence if email.all_parts.empty?
@plain_text_body
# As a fallback we return an empty plain text body (e.g. if we have only
# empty text parts but a non-text attachment)
@plain_text_body ||= ""
end
def email_parts_to_text(parts)
test/unit/mail_handler_test.rb
assert_equal 'The html part.', issue.description
end
def test_empty_text_and_html_part_should_make_an_empty_description
issue = submit_email('empty_text_and_html_part.eml', :issue => {:project => 'ecookbook'})
assert_equal '', issue.description
end
def test_attachment_text_part_should_be_added_as_issue_attachment
issue = submit_email('multiple_text_parts.eml', :issue => {:project => 'ecookbook'})
assert_not_include 'Plain text attachment', issue.description
(1-1/2)