Commit 9ef67fbc authored by jplang's avatar jplang

Emails with no text or html Content not handled properly (#25269, #25256).

Patch by Felix Schäfer.

git-svn-id: e93f8b46-1217-0410-a6f0-8f06a7374b81
parent e6b936e5
......@@ -445,13 +445,19 @@ class MailHandler < ActionMailer::Base
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( {|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( {|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?
# 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 ||= ""
def email_parts_to_text(parts)
From Fri Mar 22 08:30:28 2013
From: John Smith <>
Content-Type: multipart/mixed; boundary="Apple-Mail=_33C8180A-B097-4B87-A925-441300BDB9C9"
Message-Id: <>
Mime-Version: 1.0 (Mac OS X Mail 6.3 \(1503\))
Subject: Test with an empty text part
Date: Fri, 22 Mar 2013 17:30:20 +0200
X-Mailer: Apple Mail (2.1503)
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://ww=">
<html xmlns=3D"">
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dutf-8" />
......@@ -628,6 +628,11 @@ class MailHandlerTest < ActiveSupport::TestCase
assert_equal 'The html part.', issue.description
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
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
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment