Add support to elide content from ProtonMail emails

This commit is contained in:
Régis Hanol 2018-03-30 10:41:32 +02:00
parent 67efdaea40
commit a0386655a6

View File

@ -301,6 +301,7 @@ module Email
[:exchange, /name="message(Body|Reply)Section"/], [:exchange, /name="message(Body|Reply)Section"/],
[:apple_mail, /id="AppleMailSignature"/], [:apple_mail, /id="AppleMailSignature"/],
[:mozilla, /class="moz-/], [:mozilla, /class="moz-/],
[:protonmail, /class="protonmail_/],
] ]
def extract_from_gmail(html) def extract_from_gmail(html)
@ -351,6 +352,13 @@ module Email
to_markdown(doc.to_html, elided.to_html) to_markdown(doc.to_html, elided.to_html)
end end
def extract_from_protonmail(html)
doc = Nokogiri::HTML.fragment(html)
# Removes anything that has a class starting with "protonmail_" and everything after that
elided = doc.css("*[class^='protonmail_'], *[class^='protonmail_'] ~ *").remove
to_markdown(doc.to_html, elided.to_html)
end
def trim_reply_and_extract_elided(text) def trim_reply_and_extract_elided(text)
return [text, ""] if @opts[:skip_trimming] return [text, ""] if @opts[:skip_trimming]
EmailReplyTrimmer.trim(text, true) EmailReplyTrimmer.trim(text, true)