Project

General

Profile

Feature #35679 » 35679-prototype.patch

Felix Schäfer, 2021-08-03 22:09

View differences:

app/models/mail_handler.rb
# Converts a plain/text email body to text
def plain_text_body_to_text(text)
return nil if MailHandler::EmptyContentPolicy.new(text).suppress?
# Removes leading spaces that would cause the line to be rendered as
# preformatted text with textile
text.gsub(/^ +(?![*#])/, '')
......
def find_assignee_from_keyword(keyword, issue)
Principal.detect_by_keyword(issue.assignable_users, keyword)
end
class EmptyContentPolicy
attr_accessor :text
patterns = [
'\AYour email client does not support HTML messages.\z',
'\AKlicken Sie hier\p{Space}+http\p{Graph}+\p{Space}+für die Online-Version.\z'
]
EMPTY_CONTENT_RE = Regexp.new(patterns.join('|'), Regexp::IGNORECASE)
def initialize(text)
self.text = text
end
def suppress?
return true if text.chomp('') =~ EMPTY_CONTENT_RE
false
end
end
end
test/fixtures/mail_handler/see_html_text_part.eml
From JSmith@somenet.foo Fri Mar 22 08:30:28 2013
From: John Smith <JSmith@somenet.foo>
Content-Type: multipart/mixed; boundary="Apple-Mail=_33C8180A-B097-4B87-A925-441300BDB9C9"
Message-Id: <BB533668-3CC8-41CA-A951-0A5D8EA37FB0@somenet.foo>
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
To: redmine@somenet.foo
X-Mailer: Apple Mail (2.1503)
--Apple-Mail=_33C8180A-B097-4B87-A925-441300BDB9C9
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
charset=us-ascii
Your email client does not support HTML messages.
--Apple-Mail=_33C8180A-B097-4B87-A925-441300BDB9C9
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
Klicken Sie hier
https://example.com
f=C3=BCr die Online-Version.
--Apple-Mail=_33C8180A-B097-4B87-A925-441300BDB9C9
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html;
charset=us-ascii
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://ww=
w.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=3D"http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dutf-8" />
</head>
<body>
<p>The html part.</p>
</body>
</html>
--Apple-Mail=_33C8180A-B097-4B87-A925-441300BDB9C9--
test/unit/mail_handler_test.rb
assert_equal 'The html part.', issue.description
end
def test_see_html_text_part_should_not_stop_looking_for_content
issue = submit_email('see_html_text_part.eml', :issue => {:project => 'ecookbook'})
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
    (1-1/1)