Skip to content

Commit 4361c4e

Browse files
committed
Merge pull request #5 from defunkt/condensed-reply-headers
Condense multiline reply headers to a single line.
2 parents 074ea4f + a1b29a6 commit 4361c4e

3 files changed

Lines changed: 30 additions & 0 deletions

File tree

lib/email_reply_parser.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ 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.
6572
text = text.reverse

test/email_reply_parser_test.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ def test_recognizes_date_string_above_quote
7171
assert_match /Loader/, reply.fragments[1].to_s
7272
end
7373

74+
def test_deals_with_multiline_reply_headers
75+
reply = email :email_1_5
76+
77+
assert_match /^I get/, reply.fragments[0].to_s
78+
assert_match /^On/, reply.fragments[1].to_s
79+
assert_match /Was this/, reply.fragments[1].to_s
80+
end
81+
7482
def test_does_not_modify_input_string
7583
original = "The Quick Brown Fox Jumps Over The Lazy Dog"
7684
EmailReplyParser.read original

test/emails/email_1_5.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)