Skip to content

Commit b91a00f

Browse files
author
Drew Batshaw
committed
make visible_text strip extra new lines
allow header line to have spaces before the dashes
1 parent 8eda177 commit b91a00f

3 files changed

Lines changed: 34 additions & 4 deletions

File tree

lib/email_reply_parser.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def initialize
5858

5959

6060
def visible_text
61-
fragments.select{|f| !f.hidden?}.map{|f| f.to_s}.join("\n")
61+
fragments.select{|f| !f.hidden?}.map{|f| f.to_s}.join("\n").rstrip
6262
end
6363

6464
# Splits the given text into a list of Fragments. This is roughly done by
@@ -127,7 +127,7 @@ def scan_line(line)
127127
# Mark the current Fragment as a signature if the current line is empty
128128
# and the Fragment starts with a common signature indicator.
129129
if @fragment && line == EMPTY
130-
if @fragment.lines.last =~ /[\-\_]$/
130+
if @fragment.lines.last =~ /[\-\_]\s*$/
131131
@fragment.signature = true
132132
finish_fragment
133133
end

test/email_reply_parser_test.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,13 @@ def test_does_not_modify_input_string
7878
end
7979

8080
def test_returns_only_the_visible_fragments_as_a_string
81-
reply = email(:email_1_2)
82-
assert_equal reply.fragments.select{|r| !r.hidden?}.map{|r| r.to_s}.join("\n"), reply.visible_text
81+
reply = email(:email_2_1)
82+
assert_equal reply.fragments.select{|r| !r.hidden?}.map{|r| r.to_s}.join("\n").rstrip, reply.visible_text
83+
end
84+
85+
def test_parse_out_just_top_for_outlook_reply
86+
body = IO.read EMAIL_FIXTURE_PATH.join("email_2_1.txt").to_s
87+
assert_equal "Outlook with a reply", EmailReplyParser.parse_reply(body)
8388
end
8489

8590
def test_parse_reply

test/emails/email_2_1.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Outlook with a reply
2+
3+
4+
------------------------------
5+
6+
*From:* Google Apps Sync Team [mailto:mail-noreply@google.com]
7+
*Sent:* Thursday, February 09, 2012 1:36 PM
8+
*To:* jow@xxxx.com
9+
*Subject:* Google Apps Sync was updated!
10+
11+
12+
13+
Dear Google Apps Sync user,
14+
15+
Google Apps Sync for Microsoft Outlook® was recently updated. Your computer
16+
now has the latest version (version 2.5). This release includes bug fixes
17+
to improve product reliability. For more information about these and other
18+
changes, please see the help article here:
19+
20+
http://www.google.com/support/a/bin/answer.py?answer=153463
21+
22+
Sincerely,
23+
24+
The Google Apps Sync Team.
25+

0 commit comments

Comments
 (0)