Skip to content

Commit 436cab0

Browse files
author
Drew Batshaw
committed
catch mobile signatures like "Sent from my Verizon Wireless BlackBerry"
1 parent bdb99f8 commit 436cab0

4 files changed

Lines changed: 17 additions & 1 deletion

File tree

lib/email_reply_parser.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def scan_line(line)
126126
# Mark the current Fragment as a signature if the current line is empty
127127
# and the Fragment starts with a common signature indicator.
128128
if @fragment && line == EMPTY
129-
if @fragment.lines.last =~ /([\-\_]\s*$)|(^\w+ #{"Sent from my".reverse}$)/
129+
if @fragment.lines.last =~ /([\-\_]\s*$)|(^(\w+\s*){1,3} #{"Sent from my".reverse}$)/ #will catch up to 3 words after "sent from my "
130130
@fragment.signature = true
131131
finish_fragment
132132
end

test/email_reply_parser_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,16 @@ def test_parse_out_sent_from_BlackBerry
9797
assert_equal "Here is another email", EmailReplyParser.parse_reply(body)
9898
end
9999

100+
def test_parse_out_send_from_multiword_mobile_device
101+
body = IO.read EMAIL_FIXTURE_PATH.join("email_multi_word_sent_from_my_mobile_device.txt").to_s
102+
assert_equal "Here is another email", EmailReplyParser.parse_reply(body)
103+
end
104+
105+
def test_do_not_parse_out_send_from_in_regular_sentence
106+
body = IO.read EMAIL_FIXTURE_PATH.join("email_sent_from_my_not_signature.txt").to_s
107+
assert_equal "Here is another email\n\nSent from my desk, is much easier then my mobile phone.", EmailReplyParser.parse_reply(body)
108+
end
109+
100110

101111
def test_parse_reply
102112
body = IO.read EMAIL_FIXTURE_PATH.join("email_1_2.txt").to_s
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Here is another email
2+
3+
Sent from my Verizon Wireless BlackBerry
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Here is another email
2+
3+
Sent from my desk, is much easier then my mobile phone.

0 commit comments

Comments
 (0)