Merge pull request #3918 from techAPJ/better-email-parsing

FEATURE: better email reply parsing
This commit is contained in:
Régis Hanol 2015-12-11 14:51:24 +01:00
commit 02279c41cb
6 changed files with 71 additions and 4 deletions

View file

@ -47,7 +47,7 @@ gem 'aws-sdk', require: false
gem 'excon', require: false
gem 'unf', require: false
gem 'email_reply_parser'
gem 'discourse_email_parser'
# note: for image_optim to correctly work you need to follow
# https://github.com/toy/image_optim

View file

@ -113,9 +113,9 @@ GEM
diff-lcs (1.2.5)
discourse-qunit-rails (0.0.8)
railties
discourse_email_parser (0.6.1)
docile (1.1.5)
dotenv (2.0.2)
email_reply_parser (0.5.8)
ember-data-source (1.0.0.beta.16.1)
ember-source (~> 1.8)
ember-handlebars-template (0.1.5)
@ -451,7 +451,7 @@ DEPENDENCIES
byebug
certified
discourse-qunit-rails
email_reply_parser
discourse_email_parser
ember-rails
ember-source (= 1.12.1)
excon

View file

@ -140,7 +140,7 @@ module Email
body = discourse_email_trimmer body
raise EmptyEmailError if body.strip.blank?
body = EmailReplyParser.parse_reply body
body = DiscourseEmailParser.parse_reply body
raise EmptyEmailError if body.strip.blank?
body.force_encoding(encoding).encode("UTF-8")

View file

@ -173,6 +173,14 @@ the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown"
expect(test_parse_body(fixture_file("emails/iphone_signature.eml"))).not_to match(/Sent from my iPhone/)
end
it "strips regular signature" do
expect(test_parse_body(fixture_file("emails/signature.eml"))).not_to match(/Arpit/)
end
it "strips 'original message' context" do
expect(test_parse_body(fixture_file("emails/original_message_context.eml"))).not_to match(/Context/)
end
it "properly renders email reply from gmail web client" do
expect(test_parse_body(fixture_file("emails/gmail_web.eml"))).
to eq(

View file

@ -0,0 +1,30 @@
Delivered-To: test@mail.com
Return-Path: <walter.white@googlemail.com>
From: Walter White <walter.white@googlemail.com>
Content-Type: multipart/alternative;
boundary=Apple-Mail-8E182EEF-9DBC-41DE-A593-DF2E5EBD3975
Content-Transfer-Encoding: 7bit
Mime-Version: 1.0 (1.0)
Subject: Re: Signature in email replies!
Date: Thu, 23 Oct 2014 14:43:49 +0530
References: <1234@mail.gmail.com>
In-Reply-To: <1234@mail.gmail.com>
To: Arpit Jalan <test@mail.com>
X-Mailer: iPhone Mail (12A405)
--Apple-Mail-8E182EEF-9DBC-41DE-A593-DF2E5EBD3975
Content-Type: text/plain;
charset=us-ascii
Content-Transfer-Encoding: 7bit
This post should not include signature.
----Original Message----
Context here.
> On 23-Oct-2014, at 9:45 am, Arpit Jalan <test@mail.com> wrote:
>
> Signature in email replies!
--Apple-Mail-8E182EEF-9DBC-41DE-A593-DF2E5EBD3975

29
spec/fixtures/emails/signature.eml vendored Normal file
View file

@ -0,0 +1,29 @@
Delivered-To: test@mail.com
Return-Path: <walter.white@googlemail.com>
From: Walter White <walter.white@googlemail.com>
Content-Type: multipart/alternative;
boundary=Apple-Mail-8E182EEF-9DBC-41DE-A593-DF2E5EBD3975
Content-Transfer-Encoding: 7bit
Mime-Version: 1.0 (1.0)
Subject: Re: Signature in email replies!
Date: Thu, 23 Oct 2014 14:43:49 +0530
References: <1234@mail.gmail.com>
In-Reply-To: <1234@mail.gmail.com>
To: Arpit Jalan <test@mail.com>
X-Mailer: iPhone Mail (12A405)
--Apple-Mail-8E182EEF-9DBC-41DE-A593-DF2E5EBD3975
Content-Type: text/plain;
charset=us-ascii
Content-Transfer-Encoding: 7bit
This post should not include signature.
----Arpit
> On 23-Oct-2014, at 9:45 am, Arpit Jalan <test@mail.com> wrote:
>
> Signature in email replies!
--Apple-Mail-8E182EEF-9DBC-41DE-A593-DF2E5EBD3975