diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb old mode 100644 new mode 100755 index 2884131..25b0b57 --- a/app/models/mail_handler.rb +++ b/app/models/mail_handler.rb @@ -561,7 +561,7 @@ class MailHandler < ActionMailer::Base # Removes the email body of text after the truncation configurations. def cleanup_body(body) - delimiters = Setting.mail_handler_body_delimiters.to_s.split(/[\r\n]+/).reject(&:blank?).map {|s| Regexp.escape(s)} + delimiters = Setting.mail_handler_body_delimiters.to_s.split(/[\r\n]+/).reject(&:blank?) unless delimiters.empty? regex = Regexp.new("^[> ]*(#{ delimiters.join('|') })\s*[\r\n].*", Regexp::MULTILINE) body = body.gsub(regex, '') diff --git a/test/fixtures/mail_handler/ticket_reply_from_mail.eml b/test/fixtures/mail_handler/ticket_reply_from_mail.eml new file mode 100644 index 0000000..016b189 --- /dev/null +++ b/test/fixtures/mail_handler/ticket_reply_from_mail.eml @@ -0,0 +1,35 @@ +Return-Path: +Received: from osiris ([127.0.0.1]) + by OSIRIS + with hMailServer; Wed, 12 Oct 2016 03:05:50 -0700 +Message-ID: <000501c8d452$a95cd7e0$0a00a8c0@osiris> +From: "John Smith" +To: +Subject: New ticket on a given project +Date: Wed, 12 Oct 2016 13:05:38 +0300 +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 + +Project: onlinestore +Status: Resolved +due date: 2010-12-31 +Start Date:2010-01-01 +Assigned to: John Smith +fixed version: alpha +estimated hours: 2.5 +remaining hours: 1 +done ratio: 30 + +This paragraph is before delimiter + +On Wed, 11 Oct at 1:05 PM, Jon Smith > wrote: + +This paragraph is after the delimiter diff --git a/test/unit/mail_handler_test.rb b/test/unit/mail_handler_test.rb old mode 100644 new mode 100755 index c1afdae..24b86bd --- a/test/unit/mail_handler_test.rb +++ b/test/unit/mail_handler_test.rb @@ -977,6 +977,16 @@ class MailHandlerTest < ActiveSupport::TestCase end end + test "truncate emails using a regex delimiter" do + with_settings :mail_handler_body_delimiters => "On .*, .* at .*, .* <.*> wrote:" do + issue = submit_email('ticket_reply_from_mail.eml') + assert_issue_created(issue) + assert issue.description.include?('This paragraph is before delimiter') + assert !issue.description.include?('On Wed, 11 Oct at 1:05 PM, Jon Smith > wrote:') + assert !issue.description.include?('This paragraph is after the delimiter') + end + end + def test_attachments_that_match_mail_handler_excluded_filenames_should_be_ignored with_settings :mail_handler_excluded_filenames => '*.vcf, *.jpg' do issue = submit_email('ticket_with_attachment.eml', :issue => {:project => 'onlinestore'})