diff --git a/Gemfile b/Gemfile index 10f209d3d68..595932d342c 100644 --- a/Gemfile +++ b/Gemfile @@ -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 diff --git a/Gemfile.lock b/Gemfile.lock index 4b249ed1079..a1ffac6d8cf 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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 diff --git a/lib/email/receiver.rb b/lib/email/receiver.rb index 674ac9be443..7ad4e0049e3 100644 --- a/lib/email/receiver.rb +++ b/lib/email/receiver.rb @@ -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") diff --git a/spec/components/email/receiver_spec.rb b/spec/components/email/receiver_spec.rb index 3b9364fd897..35a94c14c5e 100644 --- a/spec/components/email/receiver_spec.rb +++ b/spec/components/email/receiver_spec.rb @@ -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( diff --git a/spec/fixtures/emails/original_message_context.eml b/spec/fixtures/emails/original_message_context.eml new file mode 100644 index 00000000000..31088c16e6f --- /dev/null +++ b/spec/fixtures/emails/original_message_context.eml @@ -0,0 +1,30 @@ +Delivered-To: test@mail.com +Return-Path: +From: Walter White +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 +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 wrote: +> +> Signature in email replies! + +--Apple-Mail-8E182EEF-9DBC-41DE-A593-DF2E5EBD3975 diff --git a/spec/fixtures/emails/signature.eml b/spec/fixtures/emails/signature.eml new file mode 100644 index 00000000000..01a0dd78748 --- /dev/null +++ b/spec/fixtures/emails/signature.eml @@ -0,0 +1,29 @@ +Delivered-To: test@mail.com +Return-Path: +From: Walter White +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 +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 wrote: +> +> Signature in email replies! + +--Apple-Mail-8E182EEF-9DBC-41DE-A593-DF2E5EBD3975