1

perhaps somebody has a similar problem with Redmines contacts helpdesk plugin and HTML Mail parsing.

In my case after last update on Redmine 4.0.6.stable and contacts helpdesk plugin v4.1.7 HTML mails were rendered without line breaks which made the issues hard to read...
helpdesk plugin: https://www.redmine.org/plugins/redmine_contacts_helpdesk

After a while of investigation I found out, that the change from previous update on plugin was the main reason. Concrete the parsing of content has been changed from "doing it within the plugin" to "using redmine base functionality".

code reference function: helpdesk_mailer_support.rb line 293 (method plain_text_body)

Finally the problem was, that the basic redmine functionality to parse html uses Loofah.document(html) with method .text instead of using .to_text.
The difference is, that .text will produce lineAlineBlineC and .to_text will produce lineA\nlineB\nlineC which will display the line breakes in redmine issue.

Code change (helpdesk_mail_support.rb):

if Redmine::VERSION.to_s < '3.1'
      def html_body_to_text(html)

        # strip html tags and remove doctype directive
        html.gsub! %r{^[ ]+}, ''
        if RedmineHelpdesk.strip_tags?
          html.gsub! %r{<head>(?:.|\n|\r)+?<\/head>}, ''
          html.gsub! %r{<\/(li|ol|ul|h1|h2|h3|h4)>}, "\r\n"
          html.gsub! %r{<\/(p|div|pre)>}, "\r\n\r\n"
          html.gsub! %r{<li>}, '  - '
          html.gsub! %r{<br[^>]*>}, "\r\n"
          html.sub! %r{^<!DOCTYPE .*$}, ''
          html.strip
        end
      end

      def plain_text_body_to_text(text)
        text.gsub(/^ +(?![*#])/, '')
      end
    # change starts here
    else
      def html_body_to_text(html)
        doc = Loofah.document(html)
        Loofah.remove_extraneous_whitespace(doc.to_text(:encode_special_chars => false))
            .strip.squeeze(' ')
            .gsub(/^ +/, '')
      end
      # change ends here
    end
Sven
  • 11
  • 1

0 Answers0