Browse Source

Allow newlines and quote characters within mail body delimiters (#34794).

Patch by Holger Just.


git-svn-id: http://svn.redmine.org/redmine/trunk@20767 e93f8b46-1217-0410-a6f0-8f06a7374b81
tags/4.2.0
Go MAEDA 3 years ago
parent
commit
2cbf5bb29e

+ 12
- 1
app/models/mail_handler.rb View File

@@ -622,10 +622,21 @@ class MailHandler < ActionMailer::Base
rescue RegexpError => e
logger&.error "MailHandler: invalid regexp delimiter found in mail_handler_body_delimiters setting (#{e.message})"
end
else
# In a "normal" delimiter, allow a single space from the originally
# defined delimiter to match:
# * any space-like character, or
# * line-breaks and optional quoting with arbitrary spacing around it
# in the mail in order to allow line breaks of delimiters.
delimiters = delimiters.map do |delimiter|
delimiter = Regexp.escape(delimiter).encode!(Encoding::UTF_8)
delimiter = delimiter.gsub(/(\\ )+/, '\p{Space}*(\p{Space}|[\r\n](\p{Space}|>)*)')
Regexp.new(delimiter)
end
end

unless delimiters.empty?
regex = Regexp.new("^[> ]*(#{ Regexp.union(delimiters) })[[:blank:]]*[\r\n].*", Regexp::MULTILINE)
regex = Regexp.new("^(\\p{Space}|>)*(#{ Regexp.union(delimiters) })\\p{Space}*[\\r\\n].*", Regexp::MULTILINE)
body = body.gsub(regex, '')
end
body.strip

+ 2
- 1
test/fixtures/mail_handler/issue_update_with_quoted_reply_above.eml View File

@@ -33,7 +33,8 @@ 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. ---
> --- Reply above. Do not
> remove this line. ---
>
> Issue #6779 has been updated by Eric Davis.
>

Loading…
Cancel
Save