Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle mulitline reply headers in Gmail #77

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
pkg
.ruby-version
.ruby-version
.byebug_history
.idea
2 changes: 1 addition & 1 deletion lib/email_reply_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def read(text)

# Check for multi-line reply headers. Some clients break up
# the "On DATE, NAME <EMAIL> wrote:" line into multiple lines.
if text =~ /^(?!On.*On\s.+?wrote:)(On\s(.+?)wrote:)$/m
if text =~ /(^On\s((?!On).)*wrote:$)/m
# Remove all new lines from the reply header.
text.gsub! $1, $1.gsub("\n", " ")
end
Expand Down
7 changes: 6 additions & 1 deletion test/email_reply_parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def test_one_is_not_on
assert_match(/^On Oct 1, 2012/, reply.fragments[1].to_s)
end

def test_mulitple_on
def test_multiple_on
reply = email("greedy_on")
assert_match(/^On your remote host/, reply.fragments[0].to_s)
assert_match(/^On 9 Jan 2014/, reply.fragments[1].to_s)
Expand All @@ -211,6 +211,11 @@ def test_mulitple_on
assert_equal [false, true, true], reply.fragments.map { |f| f.hidden? }
end

def test_multiple_replies
reply = email("email_multiple_replies")
assert_equal("TAKE 3 - testing once again", reply.fragments[0].to_s)
end

def test_pathological_emails
t0 = Time.now
email("pathological")
Expand Down
19 changes: 19 additions & 0 deletions test/emails/email_multiple_replies.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
TAKE 3 - testing once again

On Fri, Apr 3, 2020 at 12:32 PM Someone <
[email protected]> wrote:

> TAKE 2 - Lets see what is posted now to the portal
>
> On Fri, Apr 3, 2020 at 12:31 PM Someone <
> [email protected]> wrote:
>
>> Lets see what is posted now to the portal
>>
>> On Fri, Apr 3, 2020 at 11:58 AM <[email protected]> wrote:
>>
>>> Project~Stream - Comment Posted
>>>
>>> Someone1 added a comment on 04/03/2020 at 11:58 AM
>>>
>>> Full email test... Hopefully you don't see this in the reply