Feature #5864 » allow_regex_delimiters.patch
| app/models/mail_handler.rb | ||
|---|---|---|
|
# 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, '')
|
||
| test/fixtures/mail_handler/ticket_reply_from_mail.eml | ||
|---|---|---|
|
Return-Path: <jsmith@somenet.foo>
|
||
|
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" <JSmith@somenet.foo>
|
||
|
To: <redmine@somenet.foo>
|
||
|
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 <jsmith@somenet.foo<mailto:jsmith@somenet.foo>> wrote:
|
||
|
This paragraph is after the delimiter
|
||
| test/unit/mail_handler_test.rb | ||
|---|---|---|
|
end
|
||
|
end
|
||
|
test "truncate emails using a regex delimiter" do
|
||
|
with_settings :mail_handler_body_delimiters => "On .*, .* at .*, .* <.*<mailto:.*>> 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 <jsmith@somenet.foo<mailto:jsmith@somenet.foo>> 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'})
|
||