diff options
author | Go MAEDA <maeda@farend.jp> | 2021-03-09 08:28:01 +0000 |
---|---|---|
committer | Go MAEDA <maeda@farend.jp> | 2021-03-09 08:28:01 +0000 |
commit | 2cbf5bb29e2bd459f7971ab84c30033c8b5e9b9f (patch) | |
tree | f65e39b1c464e5627905ad0b2f919d7fc8dd4a3f /app | |
parent | 4031ac31393a4421f1058d76bae45ff95bdbcf19 (diff) | |
download | redmine-2cbf5bb29e2bd459f7971ab84c30033c8b5e9b9f.tar.gz redmine-2cbf5bb29e2bd459f7971ab84c30033c8b5e9b9f.zip |
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
Diffstat (limited to 'app')
-rw-r--r-- | app/models/mail_handler.rb | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb index db9358eef..5c1653709 100644 --- a/app/models/mail_handler.rb +++ b/app/models/mail_handler.rb @@ -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 |