FEATURE: new 'trim_incoming_emails' site setting (#12874)

This setting allows admin to de/activate automatic trimming of incoming email.
There are instances where it does wonders in trimming all the garbage content and other
instances where it's so bad that it trims the most important part of the email.

FIX: don't remove hidden content using the style attribute when converting HTML to Markdown.
The regexp used was doing more harm than good. It was way too broad.

FIX: properly elide signatures from emails sent with Front App.
This is fairly safe as Front App nicely identifies signatures in the HTML part.
This commit is contained in:
Régis Hanol
2021-04-28 17:08:48 +02:00
committed by GitHub
parent 548c044809
commit cd93d1b5f7
6 changed files with 32 additions and 23 deletions

View File

@ -37,11 +37,8 @@ class HtmlToMarkdown
@doc.traverse { |node| node.remove if !allowed.include?(node.name) }
end
HIDDEN_STYLES ||= /(display\s*:\s*none)|(visibility\s*:\s*hidden)|(opacity\s*:\s*0)|(transform\s*:\s*scale\(0\))|((width|height)\s*:\s*0)/i
def remove_hidden!(doc)
@doc.css("[hidden]").remove
@doc.css("[style]").each { |n| n.remove if n["style"][HIDDEN_STYLES] }
@doc.css("img[width]").each { |n| n.remove if n["width"].to_i <= 0 }
@doc.css("img[height]").each { |n| n.remove if n["height"].to_i <= 0 }
end