Skip to content

Commit 5c869db

Browse files
committed
Tightens up regular expression for catching signatures
There were cases where bulleted lists that were prefixed by dashes were considered signatures.
1 parent 94d27e1 commit 5c869db

3 files changed

Lines changed: 26 additions & 5 deletions

File tree

lib/email_reply_parser.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#
2020
# this is some text
2121
#
22-
# --
22+
# --
2323
# Bob
2424
# http://homepage.com/~bob
2525
#
@@ -85,7 +85,7 @@ def read(text)
8585
end
8686

8787
# Finish up the final fragment. Finishing a fragment will detect any
88-
# attributes (hidden, signature, reply), and join each line into a
88+
# attributes (hidden, signature, reply), and join each line into a
8989
# string.
9090
finish_fragment
9191

@@ -118,7 +118,7 @@ def scan_line(line)
118118
# Mark the current Fragment as a signature if the current line is empty
119119
# and the Fragment starts with a common signature indicator.
120120
if @fragment && line == EMPTY
121-
if @fragment.lines.last =~ /[\-\_]$/
121+
if @fragment.lines.last =~ /(--|__|\w-)$/
122122
@fragment.signature = true
123123
finish_fragment
124124
end
@@ -165,10 +165,10 @@ def quote_header?(line)
165165
#
166166
# Go fish! (visible)
167167
#
168-
# > --
168+
# > --
169169
# > Player 1 (quoted, hidden)
170170
#
171-
# --
171+
# --
172172
# Player 2 (signature, hidden)
173173
#
174174
def finish_fragment

test/email_reply_parser_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ def test_recognizes_date_string_above_quote
7171
assert_match /Loader/, reply.fragments[1].to_s
7272
end
7373

74+
def test_a_complex_body_with_only_one_fragment
75+
reply = email :email_1_5
76+
77+
assert_equal 1, reply.fragments.size
78+
end
79+
7480
def email(name)
7581
body = IO.read EMAIL_FIXTURE_PATH.join("#{name}.txt").to_s
7682
EmailReplyParser.read body

test/emails/email_1_5.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
One: Here's what I've got.
2+
3+
- This would be the first bullet point that wraps to the second line
4+
to the next
5+
- This is the second bullet point and it doesn't wrap
6+
- This is the third bullet point and I'm having trouble coming up with enough
7+
to say
8+
- This is the fourth bullet point
9+
10+
Two:
11+
- Here is another bullet point
12+
- And another one
13+
14+
This is a paragraph that talks about a bunch of stuff. It goes on and on
15+
for a while.

0 commit comments

Comments
 (0)