Skip to content

Commit 32021fd

Browse files
committed
Merge pull request #8 from fatfreecrm/ensure_newline_above_underscores
Ensure that all lines of underscores have at least two preceding newlines
2 parents 8338124 + 49c62f9 commit 32021fd

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
@@ -89,6 +89,12 @@ def read(text)
8989
text.gsub! $1, $1.gsub("\n", " ")
9090
end
9191

92+
# Some users may reply directly above a line of underscores.
93+
# In order to ensure that these fragments are split correctly,
94+
# make sure that all lines of underscores are preceded by
95+
# at least two newline characters.
96+
text.gsub!(/([^\n])(?=\n_{7}_+)$/m, "\\1\n")
97+
9298
# The text is reversed initially due to the way we check for hidden
9399
# fragments.
94100
text = text.reverse

test/email_reply_parser_test.rb

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

122+
def test_parse_out_just_top_for_outlook_with_reply_directly_above_line
123+
body = IO.read EMAIL_FIXTURE_PATH.join("email_2_2.txt").to_s
124+
assert_equal "Outlook with a reply directly above line", EmailReplyParser.parse_reply(body)
125+
end
126+
122127
def test_parse_out_sent_from_iPhone
123128
body = IO.read EMAIL_FIXTURE_PATH.join("email_iPhone.txt").to_s
124129
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)