diff --git a/lib/email_reply_parser.rb b/lib/email_reply_parser.rb index 982eaec..ebf2217 100644 --- a/lib/email_reply_parser.rb +++ b/lib/email_reply_parser.rb @@ -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. diff --git a/test/email_reply_parser_test.rb b/test/email_reply_parser_test.rb index 6710838..9a09dd5 100644 --- a/test/email_reply_parser_test.rb +++ b/test/email_reply_parser_test.rb @@ -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 @@ -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 diff --git a/test/emails/email_1_9.txt b/test/emails/email_1_9.txt new file mode 100644 index 0000000..269585e --- /dev/null +++ b/test/emails/email_1_9.txt @@ -0,0 +1,3 @@ +Reply directly above hyphen line +---------------------------------------------- +A bunch of stuff below hyphen. diff --git a/test/emails/email_2_2.txt b/test/emails/email_2_2.txt index cae8050..10f8902 100644 --- a/test/emails/email_2_2.txt +++ b/test/emails/email_2_2.txt @@ -1,4 +1,4 @@ -Outlook with a reply directly above line +Outlook with a reply directly above underscore line ________________________________________ From: CRM Comments [crm-comment@example.com] Sent: Friday, 23 March 2012 5:08 p.m.