mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05:00
Merge pull request #3918 from techAPJ/better-email-parsing
FEATURE: better email reply parsing
This commit is contained in:
commit
02279c41cb
6 changed files with 71 additions and 4 deletions
2
Gemfile
2
Gemfile
|
@ -47,7 +47,7 @@ gem 'aws-sdk', require: false
|
||||||
gem 'excon', require: false
|
gem 'excon', require: false
|
||||||
gem 'unf', 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
|
# note: for image_optim to correctly work you need to follow
|
||||||
# https://github.com/toy/image_optim
|
# https://github.com/toy/image_optim
|
||||||
|
|
|
@ -113,9 +113,9 @@ GEM
|
||||||
diff-lcs (1.2.5)
|
diff-lcs (1.2.5)
|
||||||
discourse-qunit-rails (0.0.8)
|
discourse-qunit-rails (0.0.8)
|
||||||
railties
|
railties
|
||||||
|
discourse_email_parser (0.6.1)
|
||||||
docile (1.1.5)
|
docile (1.1.5)
|
||||||
dotenv (2.0.2)
|
dotenv (2.0.2)
|
||||||
email_reply_parser (0.5.8)
|
|
||||||
ember-data-source (1.0.0.beta.16.1)
|
ember-data-source (1.0.0.beta.16.1)
|
||||||
ember-source (~> 1.8)
|
ember-source (~> 1.8)
|
||||||
ember-handlebars-template (0.1.5)
|
ember-handlebars-template (0.1.5)
|
||||||
|
@ -451,7 +451,7 @@ DEPENDENCIES
|
||||||
byebug
|
byebug
|
||||||
certified
|
certified
|
||||||
discourse-qunit-rails
|
discourse-qunit-rails
|
||||||
email_reply_parser
|
discourse_email_parser
|
||||||
ember-rails
|
ember-rails
|
||||||
ember-source (= 1.12.1)
|
ember-source (= 1.12.1)
|
||||||
excon
|
excon
|
||||||
|
|
|
@ -140,7 +140,7 @@ module Email
|
||||||
body = discourse_email_trimmer body
|
body = discourse_email_trimmer body
|
||||||
raise EmptyEmailError if body.strip.blank?
|
raise EmptyEmailError if body.strip.blank?
|
||||||
|
|
||||||
body = EmailReplyParser.parse_reply body
|
body = DiscourseEmailParser.parse_reply body
|
||||||
raise EmptyEmailError if body.strip.blank?
|
raise EmptyEmailError if body.strip.blank?
|
||||||
|
|
||||||
body.force_encoding(encoding).encode("UTF-8")
|
body.force_encoding(encoding).encode("UTF-8")
|
||||||
|
|
|
@ -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/)
|
expect(test_parse_body(fixture_file("emails/iphone_signature.eml"))).not_to match(/Sent from my iPhone/)
|
||||||
end
|
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
|
it "properly renders email reply from gmail web client" do
|
||||||
expect(test_parse_body(fixture_file("emails/gmail_web.eml"))).
|
expect(test_parse_body(fixture_file("emails/gmail_web.eml"))).
|
||||||
to eq(
|
to eq(
|
||||||
|
|
30
spec/fixtures/emails/original_message_context.eml
vendored
Normal file
30
spec/fixtures/emails/original_message_context.eml
vendored
Normal 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
29
spec/fixtures/emails/signature.eml
vendored
Normal 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
|
Loading…
Reference in a new issue