Skip to content

Update body preprocessing #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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: 3 additions & 3 deletions lib/email_reply_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ def read(text)
text.gsub! $1, $1.gsub("\n", " ")
end

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

# The text is reversed initially due to the way we check for hidden
# fragments.
Expand Down
9 changes: 7 additions & 2 deletions test/email_reply_parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ def test_deals_with_windows_line_endings
assert_match /Steps 0-2/, reply.fragments[1].to_s
end

def test_parse_out_just_top_for_reply_directly_above_hyphen_line
body = IO.read EMAIL_FIXTURE_PATH.join("email_1_9.txt").to_s
assert_equal "Reply directly above hyphen line", EmailReplyParser.parse_reply(body)
end

def test_does_not_modify_input_string
original = "The Quick Brown Fox Jumps Over The Lazy Dog"
EmailReplyParser.read original
Expand All @@ -139,9 +144,9 @@ 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
def test_parse_out_just_top_for_outlook_with_reply_directly_above_underscore_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)
assert_equal "Outlook with a reply directly above underscore line", EmailReplyParser.parse_reply(body)
end

def test_parse_out_sent_from_iPhone
Expand Down
3 changes: 3 additions & 0 deletions test/emails/email_1_9.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Reply directly above hyphen line
----------------------------------------------
A bunch of stuff below hyphen.
2 changes: 1 addition & 1 deletion test/emails/email_2_2.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Outlook with a reply directly above line
Outlook with a reply directly above underscore line
________________________________________
From: CRM Comments [[email protected]]
Sent: Friday, 23 March 2012 5:08 p.m.
Expand Down