Skip to content

Commit f960af1

Browse files
committed
check for correct signatures
1 parent 5c869db commit f960af1

3 files changed

Lines changed: 17 additions & 2 deletions

File tree

lib/email_reply_parser.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ def read(text)
9898

9999
private
100100
EMPTY = "".freeze
101+
SIG_REGEX = /(\s--|__|\w-)$/
101102

102103
### Line-by-Line Parsing
103104

@@ -109,7 +110,7 @@ def read(text)
109110
# Returns nothing.
110111
def scan_line(line)
111112
line.chomp!("\n")
112-
line.lstrip!
113+
line.lstrip! unless line =~ SIG_REGEX
113114

114115
# We're looking for leading `>`'s to see if this line is part of a
115116
# quoted Fragment.
@@ -118,7 +119,7 @@ def scan_line(line)
118119
# Mark the current Fragment as a signature if the current line is empty
119120
# and the Fragment starts with a common signature indicator.
120121
if @fragment && line == EMPTY
121-
if @fragment.lines.last =~ /(--|__|\w-)$/
122+
if @fragment.lines.last =~ SIG_REGEX
122123
@fragment.signature = true
123124
finish_fragment
124125
end

test/email_reply_parser_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,16 @@ def test_a_complex_body_with_only_one_fragment
7777
assert_equal 1, reply.fragments.size
7878
end
7979

80+
def test_reads_email_with_correct_signature
81+
reply = email :correct_sig
82+
83+
assert_equal 2, reply.fragments.size
84+
assert_equal [false, false], reply.fragments.map { |f| f.quoted? }
85+
assert_equal [false, true], reply.fragments.map { |f| f.signature? }
86+
assert_equal [false, true], reply.fragments.map { |f| f.hidden? }
87+
assert_match /^-- \nrick/, reply.fragments[1].to_s
88+
end
89+
8090
def email(name)
8191
body = IO.read EMAIL_FIXTURE_PATH.join("#{name}.txt").to_s
8292
EmailReplyParser.read body

test/emails/correct_sig.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
this is an email with a correct -- signature.
2+
3+
--
4+
rick

0 commit comments

Comments
 (0)