]> source.dussan.org Git - redmine.git/commitdiff
Remove email quotes (>) when searching for incoming email delimiters. #2852 #6628
authorEric Davis <edavis@littlestreamsoftware.com>
Tue, 2 Nov 2010 19:00:31 +0000 (19:00 +0000)
committerEric Davis <edavis@littlestreamsoftware.com>
Tue, 2 Nov 2010 19:00:31 +0000 (19:00 +0000)
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
test/fixtures/mail_handler/issue_update_with_multiple_quoted_reply_above.eml [new file with mode: 0644]
test/fixtures/mail_handler/issue_update_with_quoted_reply_above.eml [new file with mode: 0644]
test/unit/mail_handler_test.rb

index 518f0433f19ddcee43f05f35ff13af0459c88b3e..35e33968796fbf1f629105a41e8137f5b84964ae 100644 (file)
@@ -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 (file)
index 0000000..ff8f63f
--- /dev/null
@@ -0,0 +1,48 @@
+Return-Path: <JSmith@somenet.foo>\r
+Received: from osiris ([127.0.0.1])\r
+       by OSIRIS\r
+       with hMailServer ; Sun, 22 Jun 2008 12:28:07 +0200\r
+Message-ID: <000501c8d452$a95cd7e0$0a00a8c0@osiris>\r
+In-Reply-To: <redmine.issue-2.20060719210421@osiris>\r
+From: "John Smith" <JSmith@somenet.foo>\r
+To: <redmine@somenet.foo>\r
+Subject: Re: update to issue 2\r
+Date: Sun, 22 Jun 2008 12:28:07 +0200\r
+MIME-Version: 1.0\r
+Content-Type: text/plain;\r
+       format=flowed;\r
+       charset="iso-8859-1";\r
+       reply-type=original\r
+Content-Transfer-Encoding: 7bit\r
+X-Priority: 3\r
+X-MSMail-Priority: Normal\r
+X-Mailer: Microsoft Outlook Express 6.00.2900.2869\r
+X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869\r
+\r
+An update to the issue by the sender.\r
+\r
+Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas imperdiet \r
+turpis et odio. Integer eget pede vel dolor euismod varius. Phasellus \r
+blandit eleifend augue. Nulla facilisi. Duis id diam. Class aptent taciti \r
+sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. In \r
+in urna sed tellus aliquet lobortis. Morbi scelerisque tortor in dolor. Cras \r
+sagittis odio eu lacus. Aliquam sem tortor, consequat sit amet, vestibulum \r
+id, iaculis at, lectus. Fusce tortor libero, congue ut, euismod nec, luctus \r
+eget, eros. Pellentesque tortor enim, feugiat in, dignissim eget, tristique \r
+sed, mauris --- Pellentesque habitant morbi tristique senectus et netus et \r
+malesuada fames ac turpis egestas. Quisque sit amet libero. In hac habitasse \r
+platea dictumst.\r
+\r
+>> > --- Reply above. Do not remove this line. ---\r
+>> > \r
+>> > Issue #6779 has been updated by Eric Davis.\r
+>> > \r
+>> > Subject changed from Projects with JSON to Project JSON API\r
+>> > Status changed from New to Assigned\r
+>> > Assignee set to Eric Davis\r
+>> > Priority changed from Low to Normal\r
+>> > Estimated time deleted (1.00)\r
+>> > \r
+>> > Looks like the JSON api for projects was missed. I'm going to be\r
+>> > reviewing the existing APIs and trying to clean them up over the next\r
+>> > few weeks.\r
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 (file)
index 0000000..848382c
--- /dev/null
@@ -0,0 +1,48 @@
+Return-Path: <JSmith@somenet.foo>\r
+Received: from osiris ([127.0.0.1])\r
+       by OSIRIS\r
+       with hMailServer ; Sun, 22 Jun 2008 12:28:07 +0200\r
+Message-ID: <000501c8d452$a95cd7e0$0a00a8c0@osiris>\r
+In-Reply-To: <redmine.issue-2.20060719210421@osiris>\r
+From: "John Smith" <JSmith@somenet.foo>\r
+To: <redmine@somenet.foo>\r
+Subject: Re: update to issue 2\r
+Date: Sun, 22 Jun 2008 12:28:07 +0200\r
+MIME-Version: 1.0\r
+Content-Type: text/plain;\r
+       format=flowed;\r
+       charset="iso-8859-1";\r
+       reply-type=original\r
+Content-Transfer-Encoding: 7bit\r
+X-Priority: 3\r
+X-MSMail-Priority: Normal\r
+X-Mailer: Microsoft Outlook Express 6.00.2900.2869\r
+X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869\r
+\r
+An update to the issue by the sender.\r
+\r
+Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas imperdiet \r
+turpis et odio. Integer eget pede vel dolor euismod varius. Phasellus \r
+blandit eleifend augue. Nulla facilisi. Duis id diam. Class aptent taciti \r
+sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. In \r
+in urna sed tellus aliquet lobortis. Morbi scelerisque tortor in dolor. Cras \r
+sagittis odio eu lacus. Aliquam sem tortor, consequat sit amet, vestibulum \r
+id, iaculis at, lectus. Fusce tortor libero, congue ut, euismod nec, luctus \r
+eget, eros. Pellentesque tortor enim, feugiat in, dignissim eget, tristique \r
+sed, mauris --- Pellentesque habitant morbi tristique senectus et netus et \r
+malesuada fames ac turpis egestas. Quisque sit amet libero. In hac habitasse \r
+platea dictumst.\r
+\r
+> --- Reply above. Do not remove this line. ---\r
+> \r
+> Issue #6779 has been updated by Eric Davis.\r
+> \r
+> Subject changed from Projects with JSON to Project JSON API\r
+> Status changed from New to Assigned\r
+> Assignee set to Eric Davis\r
+> Priority changed from Low to Normal\r
+> Estimated time deleted (1.00)\r
+> \r
+> Looks like the JSON api for projects was missed. I'm going to be\r
+> reviewing the existing APIs and trying to clean them up over the next\r
+> few weeks.\r
index 947845a58523e7602940befbcc4dc79226b86271..e59d78be967082a4fb529d0641c89e5acac4cbd6 100644 (file)
@@ -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"