Project

General

Profile

Feature #34794 ยป 0001-Allow-newlines-and-quote-characters-within-mail-body.patch

Holger Just, 2021-02-23 11:47

View differences:

app/models/mail_handler.rb
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
test/fixtures/mail_handler/issue_update_with_quoted_reply_above.eml
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.
>
    (1-1/1)