lib/mournmail/message_rendering.rb in mournmail-1.0.4 vs lib/mournmail/message_rendering.rb in mournmail-1.0.5

- old
+ new

@@ -1,7 +1,7 @@ require "mail" -require "html2text" +require "nokogiri" module Mournmail module MessageRendering refine ::Mail::Message do def render(indices = []) @@ -32,11 +32,13 @@ part.render([*indices, i], no_content) }.join elsif main_type.nil? || main_type == "text" s = Mournmail.to_utf8(body.decoded, charset) if sub_type == "html" - "[0 text/html]\n" + Html2Text.convert(s) + doc = Nokogiri::HTML(s) + doc.css("script, style, link").each { |node| node.remove } + "[0 text/html]\n" + doc.css("body").text.squeeze(" \n") else s end else type = Mail::Encodings.decode_encode(self["content-type"].to_s, @@ -113,9 +115,13 @@ def render(indices, no_content = false) index = indices.map { |i| i + 1 }.join(".") type = Mail::Encodings.decode_encode(self["content-type"].to_s, :decode) rescue "broken/type; error=\"#{$!} (#{$!.class})\"" + filename = self["content-disposition"]&.filename + if filename && !self["content-type"]&.filename + type += "; filename=#{filename}" + end "[#{index} #{type}]\n" + render_content(indices, no_content) end def render_text(indices)