Skip to content

Commit

Permalink
Remove HTML showing in entries
Browse files Browse the repository at this point in the history
  • Loading branch information
parterburn committed Oct 6, 2024
1 parent 63fb607 commit 0ff179b
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions app/lib/email_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,9 @@ def clean_message(body)
body&.gsub!(/<(http[s]?:\/\/\S*?)>/, "(\\1)") # convert links to show up
body&.gsub!(/<br\s*\/?>$/, "")&.gsub!(/<br\s*\/?>$/, "")&.gsub!(/^$\n/, "") # remove last unnecessary line break
body&.gsub!(/--( \*)?$\z/, "") # remove gmail signature break
body&.gsub!(/<style[^>]*>.*?<\/style>/mi, '') # remove styles
body&.gsub!(/<xml[^>]*>.*?<\/xml>/mi, '') # remove xml
body&.gsub!(/<style(?:\s+[^>]*)?>.*?<\/style>/mi, '') # remove styles
body&.gsub!(/<xml(?:\s+[^>]*)?>.*?<\/xml>/mi, '') # remove xml

body&.gsub!(/<!--.*?-->/m, '') # remove comments
body&.gsub!('<![endif]-->', '') # remove comments
body&.gsub!(/<br\s*\/?>\z/, "")&.gsub!(/<br\s*\/?>\z/, "")&.gsub!(/^$\n\z/, "") # remove last unnecessary line break
Expand Down Expand Up @@ -363,10 +364,15 @@ def clean_html_version(html)
html = html.split("<br>--").first # strip out gmail signature
html = html.presence || ""
html = html.split("<br>\n--").first # strip out gmail signature
html&.gsub!(/<style[^>]*>.*?<\/style>/mi, '') # remove styles
html&.gsub!(/<xml[^>]*>.*?<\/xml>/mi, '') # remove xml
html&.gsub!(/<style(?:\s+[^>]*)?>.*?<\/style>/mi, '') # remove styles
html&.gsub!(/<xml(?:\s+[^>]*)?>.*?<\/xml>/mi, '') # remove xml
html&.gsub!(/<!--.*?-->/m, '') # remove comments
html&.gsub!('<![endif]-->', '') # remove comments
html&.gsub!(/<(?:\/)?html(?:\s+[^>]*)?>/i, '') # remove html tags
html&.gsub!(/<(?:\/)?head(?:\s+[^>]*)?>/i, '') # remove head tags
html&.gsub!(/<(?:\/)?body(?:\s+[^>]*)?>/i, '') # remove body tags



html&.gsub!(/\A<br\s*\/?>/, "") # remove <br> from very beginning of html
html&.gsub!(/<div style="display:none;border:0px;width:0px;height:0px;overflow:hidden;">.+<\/div>/, "") # remove hidden divs / tracking pixels
Expand Down Expand Up @@ -424,4 +430,3 @@ def collage_from_urls(urls)
# rubocop:enable Metrics/ClassLength
# rubocop:enable Metrics/PerceivedComplexity
# rubocop:enable Metrics/CyclomaticComplexity

0 comments on commit 0ff179b

Please sign in to comment.