From 0395eb99decaac54dc8acf6162b3129893341be0 Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Tue, 2 Nov 2010 19:00:31 +0000 Subject: [PATCH] Remove email quotes (>) when searching for incoming email delimiters. #2852 #6628 Changes the email truncation so a delimiter can be prefixed by email quotes or spaces ("> Eric said..."). This will let it be combined with a "--- Reply above ---" delimiter to match "> --- Reply above ---" git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4361 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/mail_handler.rb | 2 +- ...pdate_with_multiple_quoted_reply_above.eml | 48 +++++++++++++++++++ .../issue_update_with_quoted_reply_above.eml | 48 +++++++++++++++++++ test/unit/mail_handler_test.rb | 32 +++++++++++++ 4 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/mail_handler/issue_update_with_multiple_quoted_reply_above.eml create mode 100644 test/fixtures/mail_handler/issue_update_with_quoted_reply_above.eml diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb index 518f0433f1..35e3396879 100644 --- a/app/models/mail_handler.rb +++ b/app/models/mail_handler.rb @@ -318,7 +318,7 @@ class MailHandler < ActionMailer::Base def cleanup_body(body) delimiters = Setting.mail_handler_body_delimiters.to_s.split(/[\r\n]+/).reject(&:blank?).map {|s| Regexp.escape(s)} unless delimiters.empty? - regex = Regexp.new("^(#{ delimiters.join('|') })\s*[\r\n].*", Regexp::MULTILINE) + regex = Regexp.new("^[> ]*(#{ delimiters.join('|') })\s*[\r\n].*", Regexp::MULTILINE) body = body.gsub(regex, '') end body.strip diff --git a/test/fixtures/mail_handler/issue_update_with_multiple_quoted_reply_above.eml b/test/fixtures/mail_handler/issue_update_with_multiple_quoted_reply_above.eml new file mode 100644 index 0000000000..ff8f63fda3 --- /dev/null +++ b/test/fixtures/mail_handler/issue_update_with_multiple_quoted_reply_above.eml @@ -0,0 +1,48 @@ +Return-Path: +Received: from osiris ([127.0.0.1]) + by OSIRIS + with hMailServer ; Sun, 22 Jun 2008 12:28:07 +0200 +Message-ID: <000501c8d452$a95cd7e0$0a00a8c0@osiris> +In-Reply-To: +From: "John Smith" +To: +Subject: Re: update to issue 2 +Date: Sun, 22 Jun 2008 12:28:07 +0200 +MIME-Version: 1.0 +Content-Type: text/plain; + format=flowed; + charset="iso-8859-1"; + reply-type=original +Content-Transfer-Encoding: 7bit +X-Priority: 3 +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook Express 6.00.2900.2869 +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869 + +An update to the issue by the sender. + +Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas imperdiet +turpis et odio. Integer eget pede vel dolor euismod varius. Phasellus +blandit eleifend augue. Nulla facilisi. Duis id diam. Class aptent taciti +sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. In +in urna sed tellus aliquet lobortis. Morbi scelerisque tortor in dolor. Cras +sagittis odio eu lacus. Aliquam sem tortor, consequat sit amet, vestibulum +id, iaculis at, lectus. Fusce tortor libero, congue ut, euismod nec, luctus +eget, eros. Pellentesque tortor enim, feugiat in, dignissim eget, tristique +sed, mauris --- Pellentesque habitant morbi tristique senectus et netus et +malesuada fames ac turpis egestas. Quisque sit amet libero. In hac habitasse +platea dictumst. + +>> > --- Reply above. Do not remove this line. --- +>> > +>> > Issue #6779 has been updated by Eric Davis. +>> > +>> > Subject changed from Projects with JSON to Project JSON API +>> > Status changed from New to Assigned +>> > Assignee set to Eric Davis +>> > Priority changed from Low to Normal +>> > Estimated time deleted (1.00) +>> > +>> > Looks like the JSON api for projects was missed. I'm going to be +>> > reviewing the existing APIs and trying to clean them up over the next +>> > few weeks. diff --git a/test/fixtures/mail_handler/issue_update_with_quoted_reply_above.eml b/test/fixtures/mail_handler/issue_update_with_quoted_reply_above.eml new file mode 100644 index 0000000000..848382ca44 --- /dev/null +++ b/test/fixtures/mail_handler/issue_update_with_quoted_reply_above.eml @@ -0,0 +1,48 @@ +Return-Path: +Received: from osiris ([127.0.0.1]) + by OSIRIS + with hMailServer ; Sun, 22 Jun 2008 12:28:07 +0200 +Message-ID: <000501c8d452$a95cd7e0$0a00a8c0@osiris> +In-Reply-To: +From: "John Smith" +To: +Subject: Re: update to issue 2 +Date: Sun, 22 Jun 2008 12:28:07 +0200 +MIME-Version: 1.0 +Content-Type: text/plain; + format=flowed; + charset="iso-8859-1"; + reply-type=original +Content-Transfer-Encoding: 7bit +X-Priority: 3 +X-MSMail-Priority: Normal +X-Mailer: Microsoft Outlook Express 6.00.2900.2869 +X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869 + +An update to the issue by the sender. + +Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas imperdiet +turpis et odio. Integer eget pede vel dolor euismod varius. Phasellus +blandit eleifend augue. Nulla facilisi. Duis id diam. Class aptent taciti +sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. In +in urna sed tellus aliquet lobortis. Morbi scelerisque tortor in dolor. Cras +sagittis odio eu lacus. Aliquam sem tortor, consequat sit amet, vestibulum +id, iaculis at, lectus. Fusce tortor libero, congue ut, euismod nec, luctus +eget, eros. Pellentesque tortor enim, feugiat in, dignissim eget, tristique +sed, mauris --- Pellentesque habitant morbi tristique senectus et netus et +malesuada fames ac turpis egestas. Quisque sit amet libero. In hac habitasse +platea dictumst. + +> --- Reply above. Do not remove this line. --- +> +> Issue #6779 has been updated by Eric Davis. +> +> Subject changed from Projects with JSON to Project JSON API +> Status changed from New to Assigned +> Assignee set to Eric Davis +> Priority changed from Low to Normal +> Estimated time deleted (1.00) +> +> Looks like the JSON api for projects was missed. I'm going to be +> reviewing the existing APIs and trying to clean them up over the next +> few weeks. diff --git a/test/unit/mail_handler_test.rb b/test/unit/mail_handler_test.rb index 947845a585..e59d78be96 100644 --- a/test/unit/mail_handler_test.rb +++ b/test/unit/mail_handler_test.rb @@ -335,6 +335,38 @@ class MailHandlerTest < ActiveSupport::TestCase end end + context "with a single quoted reply (e.g. reply to a Redmine email notification)" do + setup do + Setting.mail_handler_body_delimiters = '--- Reply above. Do not remove this line. ---' + end + + should "truncate the email at the delimiter with the quoted reply symbols (>)" do + journal = submit_email('issue_update_with_quoted_reply_above.eml') + assert journal.is_a?(Journal) + assert journal.notes.include?('An update to the issue by the sender.') + assert !journal.notes.match(Regexp.escape("--- Reply above. Do not remove this line. ---")) + assert !journal.notes.include?('Looks like the JSON api for projects was missed.') + + end + + end + + context "with multiple quoted replies (e.g. reply to a reply of a Redmine email notification)" do + setup do + Setting.mail_handler_body_delimiters = '--- Reply above. Do not remove this line. ---' + end + + should "truncate the email at the delimiter with the quoted reply symbols (>)" do + journal = submit_email('issue_update_with_multiple_quoted_reply_above.eml') + assert journal.is_a?(Journal) + assert journal.notes.include?('An update to the issue by the sender.') + assert !journal.notes.match(Regexp.escape("--- Reply above. Do not remove this line. ---")) + assert !journal.notes.include?('Looks like the JSON api for projects was missed.') + + end + + end + context "with multiple strings" do setup do Setting.mail_handler_body_delimiters = "---\nBREAK"