Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/email_reply_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ def read(text)
text.gsub! $1, $1.gsub("\n", " ")
end

# Some users may reply directly above a line of underscores.
# In order to ensure that these fragments are split correctly,
# make sure that all lines of underscores are preceded by
# at least two newline characters.
text.gsub!(/([^\n])(?=\n_{7}_+)$/m, "\\1\n")

# The text is reversed initially due to the way we check for hidden
# fragments.
text = text.reverse
Expand Down
5 changes: 5 additions & 0 deletions test/email_reply_parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ def test_parse_out_just_top_for_outlook_reply
assert_equal "Outlook with a reply", EmailReplyParser.parse_reply(body)
end

def test_parse_out_just_top_for_outlook_with_reply_directly_above_line
body = IO.read EMAIL_FIXTURE_PATH.join("email_2_2.txt").to_s
assert_equal "Outlook with a reply directly above line", EmailReplyParser.parse_reply(body)
end

def test_parse_out_sent_from_iPhone
body = IO.read EMAIL_FIXTURE_PATH.join("email_iPhone.txt").to_s
assert_equal "Here is another email", EmailReplyParser.parse_reply(body)
Expand Down
10 changes: 10 additions & 0 deletions test/emails/email_2_2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Outlook with a reply directly above line
________________________________________
From: CRM Comments [crm-comment@example.com]
Sent: Friday, 23 March 2012 5:08 p.m.
To: John S. Greene
Subject: [contact:106] John Greene

A new comment has been added to the Contact named 'John Greene':

I am replying to a comment.