Skip to content

Commit 49c62f9

Browse files
committed
Ensure that all lines of underscores have at least two preceding newlines
1 parent 01c6953 commit 49c62f9

3 files changed

Lines changed: 21 additions & 0 deletions

File tree

lib/email_reply_parser.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ def read(text)
8383
text.gsub! $1, $1.gsub("\n", " ")
8484
end
8585

86+
# Some users may reply directly above a line of underscores.
87+
# In order to ensure that these fragments are split correctly,
88+
# make sure that all lines of underscores are preceded by
89+
# at least two newline characters.
90+
text.gsub!(/([^\n])(?=\n_{7}_+)$/m, "\\1\n")
91+
8692
# The text is reversed initially due to the way we check for hidden
8793
# fragments.
8894
text = text.reverse

test/email_reply_parser_test.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ def test_parse_out_just_top_for_outlook_reply
111111
assert_equal "Outlook with a reply", EmailReplyParser.parse_reply(body)
112112
end
113113

114+
def test_parse_out_just_top_for_outlook_with_reply_directly_above_line
115+
body = IO.read EMAIL_FIXTURE_PATH.join("email_2_2.txt").to_s
116+
assert_equal "Outlook with a reply directly above line", EmailReplyParser.parse_reply(body)
117+
end
118+
114119
def test_parse_out_sent_from_iPhone
115120
body = IO.read EMAIL_FIXTURE_PATH.join("email_iPhone.txt").to_s
116121
assert_equal "Here is another email", EmailReplyParser.parse_reply(body)

test/emails/email_2_2.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Outlook with a reply directly above line
2+
________________________________________
3+
From: CRM Comments [crm-comment@example.com]
4+
Sent: Friday, 23 March 2012 5:08 p.m.
5+
To: John S. Greene
6+
Subject: [contact:106] John Greene
7+
8+
A new comment has been added to the Contact named 'John Greene':
9+
10+
I am replying to a comment.

0 commit comments

Comments
 (0)