Feature #5864 » allow_regex_delimiters.patch
| app/models/mail_handler.rb | ||
|---|---|---|
| 561 | 561 | |
| 562 | 562 |
# Removes the email body of text after the truncation configurations. |
| 563 | 563 |
def cleanup_body(body) |
| 564 |
delimiters = Setting.mail_handler_body_delimiters.to_s.split(/[\r\n]+/).reject(&:blank?).map {|s| Regexp.escape(s)}
|
|
| 564 |
delimiters = Setting.mail_handler_body_delimiters.to_s.split(/[\r\n]+/).reject(&:blank?) |
|
| 565 | 565 |
unless delimiters.empty? |
| 566 | 566 |
regex = Regexp.new("^[> ]*(#{ delimiters.join('|') })\s*[\r\n].*", Regexp::MULTILINE)
|
| 567 | 567 |
body = body.gsub(regex, '') |
| test/fixtures/mail_handler/ticket_reply_from_mail.eml | ||
|---|---|---|
| 1 |
Return-Path: <jsmith@somenet.foo> |
|
| 2 |
Received: from osiris ([127.0.0.1]) |
|
| 3 |
by OSIRIS |
|
| 4 |
with hMailServer; Wed, 12 Oct 2016 03:05:50 -0700 |
|
| 5 |
Message-ID: <000501c8d452$a95cd7e0$0a00a8c0@osiris> |
|
| 6 |
From: "John Smith" <JSmith@somenet.foo> |
|
| 7 |
To: <redmine@somenet.foo> |
|
| 8 |
Subject: New ticket on a given project |
|
| 9 |
Date: Wed, 12 Oct 2016 13:05:38 +0300 |
|
| 10 |
MIME-Version: 1.0 |
|
| 11 |
Content-Type: text/plain; |
|
| 12 |
format=flowed; |
|
| 13 |
charset="iso-8859-1"; |
|
| 14 |
reply-type=original |
|
| 15 |
Content-Transfer-Encoding: 7bit |
|
| 16 |
X-Priority: 3 |
|
| 17 |
X-MSMail-Priority: Normal |
|
| 18 |
X-Mailer: Microsoft Outlook Express 6.00.2900.2869 |
|
| 19 |
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869 |
|
| 20 | ||
| 21 |
Project: onlinestore |
|
| 22 |
Status: Resolved |
|
| 23 |
due date: 2010-12-31 |
|
| 24 |
Start Date:2010-01-01 |
|
| 25 |
Assigned to: John Smith |
|
| 26 |
fixed version: alpha |
|
| 27 |
estimated hours: 2.5 |
|
| 28 |
remaining hours: 1 |
|
| 29 |
done ratio: 30 |
|
| 30 | ||
| 31 |
This paragraph is before delimiter |
|
| 32 | ||
| 33 |
On Wed, 11 Oct at 1:05 PM, Jon Smith <jsmith@somenet.foo<mailto:jsmith@somenet.foo>> wrote: |
|
| 34 | ||
| 35 |
This paragraph is after the delimiter |
|
| test/unit/mail_handler_test.rb | ||
|---|---|---|
| 977 | 977 |
end |
| 978 | 978 |
end |
| 979 | 979 | |
| 980 |
test "truncate emails using a regex delimiter" do |
|
| 981 |
with_settings :mail_handler_body_delimiters => "On .*, .* at .*, .* <.*<mailto:.*>> wrote:" do |
|
| 982 |
issue = submit_email('ticket_reply_from_mail.eml')
|
|
| 983 |
assert_issue_created(issue) |
|
| 984 |
assert issue.description.include?('This paragraph is before delimiter')
|
|
| 985 |
assert !issue.description.include?('On Wed, 11 Oct at 1:05 PM, Jon Smith <jsmith@somenet.foo<mailto:jsmith@somenet.foo>> wrote:')
|
|
| 986 |
assert !issue.description.include?('This paragraph is after the delimiter')
|
|
| 987 |
end |
|
| 988 |
end |
|
| 989 | ||
| 980 | 990 |
def test_attachments_that_match_mail_handler_excluded_filenames_should_be_ignored |
| 981 | 991 |
with_settings :mail_handler_excluded_filenames => '*.vcf, *.jpg' do |
| 982 | 992 |
issue = submit_email('ticket_with_attachment.eml', :issue => {:project => 'onlinestore'})
|