Skip to content

Commit c05387f

Browse files
committed
merge
2 parents f960af1 + 4361c4e commit c05387f

3 files changed

Lines changed: 37 additions & 1 deletion

File tree

lib/email_reply_parser.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,16 @@ def initialize
6060
#
6161
# Returns this same Email instance.
6262
def read(text)
63+
# Check for multi-line reply headers. Some clients break up
64+
# the "On DATE, NAME <EMAIL> wrote:" line into multiple lines.
65+
if text =~ /^(On(.+)wrote:)$/m
66+
# Remove all new lines from the reply header.
67+
text.gsub! $1, $1.gsub("\n", " ")
68+
end
69+
6370
# The text is reversed initially due to the way we check for hidden
6471
# fragments.
65-
text.reverse!
72+
text = text.reverse
6673

6774
# This determines if any 'visible' Fragment has been found. Once any
6875
# visible Fragment is found, stop looking for hidden ones.

test/email_reply_parser_test.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,20 @@ def test_reads_email_with_correct_signature
8787
assert_match /^-- \nrick/, reply.fragments[1].to_s
8888
end
8989

90+
def test_deals_with_multiline_reply_headers
91+
reply = email :email_1_6
92+
93+
assert_match /^I get/, reply.fragments[0].to_s
94+
assert_match /^On/, reply.fragments[1].to_s
95+
assert_match /Was this/, reply.fragments[1].to_s
96+
end
97+
98+
def test_does_not_modify_input_string
99+
original = "The Quick Brown Fox Jumps Over The Lazy Dog"
100+
EmailReplyParser.read original
101+
assert_equal "The Quick Brown Fox Jumps Over The Lazy Dog", original
102+
end
103+
90104
def email(name)
91105
body = IO.read EMAIL_FIXTURE_PATH.join("#{name}.txt").to_s
92106
EmailReplyParser.read body

test/emails/email_1_6.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
I get proper rendering as well.
2+
3+
Sent from a magnificent torch of pixels
4+
5+
On Dec 16, 2011, at 12:47 PM, Corey Donohoe
6+
<reply@reply.github.com>
7+
wrote:
8+
9+
> Was this caching related or fixed already? I get proper rendering here.
10+
>
11+
> ![](https://img.skitch.com/20111216-m9munqjsy112yqap5cjee5wr6c.jpg)
12+
>
13+
> ---
14+
> Reply to this email directly or view it on GitHub:
15+
> https://github.com/github/github/issues/2278#issuecomment-3182418

0 commit comments

Comments
 (0)