Feature #35679 » 35679-prototype.patch
| app/models/mail_handler.rb | ||
|---|---|---|
| 546 | 546 | |
| 547 | 547 |
# Converts a plain/text email body to text |
| 548 | 548 |
def plain_text_body_to_text(text) |
| 549 |
return nil if MailHandler::EmptyContentPolicy.new(text).suppress? |
|
| 549 | 550 |
# Removes leading spaces that would cause the line to be rendered as |
| 550 | 551 |
# preformatted text with textile |
| 551 | 552 |
text.gsub(/^ +(?![*#])/, '') |
| ... | ... | |
| 644 | 645 |
def find_assignee_from_keyword(keyword, issue) |
| 645 | 646 |
Principal.detect_by_keyword(issue.assignable_users, keyword) |
| 646 | 647 |
end |
| 648 | ||
| 649 |
class EmptyContentPolicy |
|
| 650 |
attr_accessor :text |
|
| 651 | ||
| 652 |
patterns = [ |
|
| 653 |
'\AYour email client does not support HTML messages.\z', |
|
| 654 |
'\AKlicken Sie hier\p{Space}+http\p{Graph}+\p{Space}+für die Online-Version.\z'
|
|
| 655 |
] |
|
| 656 |
EMPTY_CONTENT_RE = Regexp.new(patterns.join('|'), Regexp::IGNORECASE)
|
|
| 657 | ||
| 658 |
def initialize(text) |
|
| 659 |
self.text = text |
|
| 660 |
end |
|
| 661 | ||
| 662 |
def suppress? |
|
| 663 |
return true if text.chomp('') =~ EMPTY_CONTENT_RE
|
|
| 664 | ||
| 665 |
false |
|
| 666 |
end |
|
| 667 |
end |
|
| 647 | 668 |
end |
| test/fixtures/mail_handler/see_html_text_part.eml | ||
|---|---|---|
| 1 |
From JSmith@somenet.foo Fri Mar 22 08:30:28 2013 |
|
| 2 |
From: John Smith <JSmith@somenet.foo> |
|
| 3 |
Content-Type: multipart/mixed; boundary="Apple-Mail=_33C8180A-B097-4B87-A925-441300BDB9C9" |
|
| 4 |
Message-Id: <BB533668-3CC8-41CA-A951-0A5D8EA37FB0@somenet.foo> |
|
| 5 |
Mime-Version: 1.0 (Mac OS X Mail 6.3 \(1503\)) |
|
| 6 |
Subject: Test with an empty text part |
|
| 7 |
Date: Fri, 22 Mar 2013 17:30:20 +0200 |
|
| 8 |
To: redmine@somenet.foo |
|
| 9 |
X-Mailer: Apple Mail (2.1503) |
|
| 10 | ||
| 11 | ||
| 12 | ||
| 13 |
--Apple-Mail=_33C8180A-B097-4B87-A925-441300BDB9C9 |
|
| 14 |
Content-Transfer-Encoding: quoted-printable |
|
| 15 |
Content-Type: text/plain; |
|
| 16 |
charset=us-ascii |
|
| 17 | ||
| 18 |
Your email client does not support HTML messages. |
|
| 19 | ||
| 20 | ||
| 21 |
--Apple-Mail=_33C8180A-B097-4B87-A925-441300BDB9C9 |
|
| 22 |
Content-Type: text/plain; charset=utf-8 |
|
| 23 |
Content-Transfer-Encoding: quoted-printable |
|
| 24 | ||
| 25 |
Klicken Sie hier |
|
| 26 |
https://example.com |
|
| 27 | ||
| 28 |
f=C3=BCr die Online-Version. |
|
| 29 | ||
| 30 |
--Apple-Mail=_33C8180A-B097-4B87-A925-441300BDB9C9 |
|
| 31 |
Content-Transfer-Encoding: quoted-printable |
|
| 32 |
Content-Type: text/html; |
|
| 33 |
charset=us-ascii |
|
| 34 | ||
| 35 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://ww= |
|
| 36 |
w.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
|
| 37 |
<html xmlns=3D"http://www.w3.org/1999/xhtml"> |
|
| 38 |
<head> |
|
| 39 |
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dutf-8" /> |
|
| 40 |
</head> |
|
| 41 |
<body> |
|
| 42 |
<p>The html part.</p> |
|
| 43 |
</body> |
|
| 44 |
</html> |
|
| 45 | ||
| 46 | ||
| 47 |
--Apple-Mail=_33C8180A-B097-4B87-A925-441300BDB9C9-- |
|
| test/unit/mail_handler_test.rb | ||
|---|---|---|
| 713 | 713 |
assert_equal 'The html part.', issue.description |
| 714 | 714 |
end |
| 715 | 715 | |
| 716 |
def test_see_html_text_part_should_not_stop_looking_for_content |
|
| 717 |
issue = submit_email('see_html_text_part.eml', :issue => {:project => 'ecookbook'})
|
|
| 718 |
assert_equal 'The html part.', issue.description |
|
| 719 |
end |
|
| 720 | ||
| 716 | 721 |
def test_empty_text_and_html_part_should_make_an_empty_description |
| 717 | 722 |
issue = submit_email('empty_text_and_html_part.eml', :issue => {:project => 'ecookbook'})
|
| 718 | 723 |
assert_equal '', issue.description |