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
622 622
      rescue RegexpError => e
623 623
        logger&.error "MailHandler: invalid regexp delimiter found in mail_handler_body_delimiters setting (#{e.message})"
624 624
      end
625
    else
626
      # In a "normal" delimiter, allow a single space from the originally
627
      # defined delimiter to match:
628
      #   * any space-like character, or
629
      #   * line-breaks and optional quoting with arbitrary spacing around it
630
      # in the mail in order to allow line breaks of delimiters.
631
      delimiters = delimiters.map do |delimiter|
632
        delimiter = Regexp.escape(delimiter).encode!(Encoding::UTF_8)
633
        delimiter = delimiter.gsub(/(\\ )+/, '\p{Space}*(\p{Space}|[\r\n](\p{Space}|>)*)')
634
        Regexp.new(delimiter)
635
      end
625 636
    end
626 637

  
627 638
    unless delimiters.empty?
628
      regex = Regexp.new("^[> ]*(#{ Regexp.union(delimiters) })[[:blank:]]*[\r\n].*", Regexp::MULTILINE)
639
      regex = Regexp.new("^(\\p{Space}|>)*(#{ Regexp.union(delimiters) })\\p{Space}*[\\r\\n].*", Regexp::MULTILINE)
629 640
      body = body.gsub(regex, '')
630 641
    end
631 642
    body.strip
test/fixtures/mail_handler/issue_update_with_quoted_reply_above.eml
33 33
malesuada fames ac turpis egestas. Quisque sit amet libero. In hac habitasse 
34 34
platea dictumst.
35 35

  
36
> --- Reply above. Do not remove this line. ---
36
> --- Reply above. Do not
37
> remove this line. ---
37 38
> 
38 39
> Issue #6779 has been updated by Eric Davis.
39 40
> 
    (1-1/1)