Project

General

Profile

Feature #30838 » 30838-preferred-part-multipart-email-without-gui.patch

Use configuration.yml instead of adding a new setting to the admin page - Go MAEDA, 2019-02-26 03:03

View differences:

app/models/mail_handler.rb
end
end
# Returns the text/plain part of the email
# If not found (eg. HTML-only email), returns the body with tags removed
# Returns text content of the email. If the value of
# mail_handler_preferred_body_part in configuration.yml is 'html' and the
# email has text/html part, it returns Textile or Markdown converted from
# text/html part. Otherwise, it returns text/plain part.
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
multipart_parse_order =
if Redmine::Configuration['mail_handler_preferred_body_part'].to_s.casecmp('html') == 0
['text/html', 'text/plain']
else
['text/plain', 'text/html']
end
multipart_parse_order.each do |mime_type|
@plain_text_body ||= email_parts_to_text(email.all_parts.select {|p| p.mime_type == mime_type}).presence
return @plain_text_body unless @plain_text_body.nil?
end
# If there is still no body found, and there are no mime-parts defined,
# we use the whole raw mail body
config/configuration.yml.example
autologin_cookie_path:
autologin_cookie_secure:
# Configuration of email receiving.
#
# Configures which type of part in a multipart email should be parsed first
# when receiving emails if the email has both text/plain and text/html part.
# Possible values are 'plain' (default) and 'html'.
# Examples:
# mail_handler_preferred_body_part: html
# mail_handler_preferred_body_part: plain
mail_handler_preferred_body_part:
# Configuration of SCM executable command.
#
# Absolute path (e.g. /usr/local/bin/hg) or command name (e.g. hg.exe, bzr.exe)
test/unit/mail_handler_test.rb
assert_equal '', issue.description
end
def test_preferred_body_part_configuration
Redmine::Configuration.stubs(:[]).with('mail_handler_preferred_body_part').returns('plain')
issue = submit_email('text_and_html_part.eml', :issue => {:project => 'ecookbook'})
assert_equal 'The text part.', issue.description
Redmine::Configuration.stubs(:[]).with('mail_handler_preferred_body_part').returns('html')
issue = submit_email('text_and_html_part.eml', :issue => {:project => 'ecookbook'})
assert_equal 'The html part.', 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
(3-3/3)