Skip to content

Commit

Permalink
Handle yahoo style reply quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
felixge committed Nov 5, 2013
1 parent 17719ff commit e844df5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
6 changes: 6 additions & 0 deletions fixtures/yahoo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
who is using yahoo?


On Monday, November 4, 2013 4:29 PM, John Smith <john.smith@example.org> wrote:

hello from my yahoo account
10 changes: 9 additions & 1 deletion mailstrip.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,20 @@ func (p *parser) scanLine(line string) {
}
}

isQuoteHeader := p.quoteHeader(line)
// Yahoo! does not use '>' quote indicator in replies, so if a quote header
// suddenly appears in an otherwise unquoted fragment, consider it quoted
// now.
if p.fragment != nil && isQuoteHeader {
p.fragment.quoted = true
}

// If the line matches the current fragment, add it. Note that a common
// reply header also counts as part of the quoted Fragment, even though
// it doesn't start with `>`.
if p.fragment != nil &&
((p.fragment.quoted == isQuoted) ||
(p.fragment.quoted && (p.quoteHeader(line) || line == ""))) {
(p.fragment.quoted && (isQuoteHeader || line == ""))) {
p.fragment.lines = append(p.fragment.lines, line)

// Otherwise, finish the fragment and start a new one.
Expand Down
12 changes: 12 additions & 0 deletions mailstrip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,18 @@ I am currently using the Java HTTP API.
&attributeChecker{"Forwarded", []bool{false, true}},
},
},

{
"yahoo reply quotes should be handled",
"yahoo",
[]checker{
&emailStringChecker{equalsString("who is using yahoo?")},
&attributeChecker{"Quoted", []bool{false, true}},
&attributeChecker{"Hidden", []bool{false, true}},
&attributeChecker{"Signature", []bool{false, false}},
&attributeChecker{"Forwarded", []bool{false, false}},
},
},
}

func TestParse(t *testing.T) {
Expand Down

0 comments on commit e844df5

Please sign in to comment.