Skip to content

Commit bdb99f8

Browse files
author
Drew Batshaw
committed
correctly detects signatures from mobile devices using "Sent from my
...."
1 parent b91a00f commit bdb99f8

4 files changed

Lines changed: 18 additions & 2 deletions

File tree

lib/email_reply_parser.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ def read(text)
107107

108108
private
109109
EMPTY = "".freeze
110-
111110
### Line-by-Line Parsing
112111

113112
# Scans the given line of text and figures out which fragment it belongs
@@ -127,7 +126,7 @@ def scan_line(line)
127126
# Mark the current Fragment as a signature if the current line is empty
128127
# and the Fragment starts with a common signature indicator.
129128
if @fragment && line == EMPTY
130-
if @fragment.lines.last =~ /[\-\_]\s*$/
129+
if @fragment.lines.last =~ /([\-\_]\s*$)|(^\w+ #{"Sent from my".reverse}$)/
131130
@fragment.signature = true
132131
finish_fragment
133132
end

test/email_reply_parser_test.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,17 @@ def test_parse_out_just_top_for_outlook_reply
8787
assert_equal "Outlook with a reply", EmailReplyParser.parse_reply(body)
8888
end
8989

90+
def test_parse_out_sent_from_iPhone
91+
body = IO.read EMAIL_FIXTURE_PATH.join("email_iPhone.txt").to_s
92+
assert_equal "Here is another email", EmailReplyParser.parse_reply(body)
93+
end
94+
95+
def test_parse_out_sent_from_BlackBerry
96+
body = IO.read EMAIL_FIXTURE_PATH.join("email_BlackBerry.txt").to_s
97+
assert_equal "Here is another email", EmailReplyParser.parse_reply(body)
98+
end
99+
100+
90101
def test_parse_reply
91102
body = IO.read EMAIL_FIXTURE_PATH.join("email_1_2.txt").to_s
92103
assert_equal EmailReplyParser.read(body).visible_text, EmailReplyParser.parse_reply(body)

test/emails/email_BlackBerry.txt

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 BlackBerry

test/emails/email_iPhone.txt

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 iPhone

0 commit comments

Comments
 (0)