Skip to content

Commit

Permalink
Cleaner posts
Browse files Browse the repository at this point in the history
  • Loading branch information
parterburn committed Oct 5, 2024
1 parent b61312d commit 03286d1
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions app/lib/email_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,14 @@ def clean_message(body)
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!(/<!--.*?-->/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
body&.gsub!(/<br\s*\/?>\z/, "")&.gsub!(/<br\s*\/?>\z/, "")&.gsub!(/^$\n\z/, "") # remove last unnecessary line break
body&.gsub!(/<br\s*\/?>\z/, "")&.gsub!(/<br\s*\/?>\z/, "")&.gsub!(/^$\n\z/, "") # remove last unnecessary line break
body&.gsub!(/<br\s*\/?>\z/, "")&.gsub!(/<br\s*\/?>\z/, "")&.gsub!(/^$\n\z/, "") # remove last unnecessary line break
body&.gsub!(/\A(\s*<br\s*\/?>|\s*<p>\s*<\/p>|\s*<div>\s*<\/div>|\s*\n|\s*\r\n)*/, '') # remove beginning line breaks

body&.gsub!("p.MsoNormal,p.MsoNoSpacing{margin:0}", "") # remove outlook styles
body = body&.strip
Expand Down Expand Up @@ -360,6 +364,10 @@ def clean_html_version(html)
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!(/<!--.*?-->/m, '') # remove comments
html.gsub!('<![endif]-->', '') # remove comments

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
html&.gsub!(/src=\"cid\:\S+\"/, "src=\"\" style=\"display: none;\"") # remove attached images showing as broken inline images
Expand All @@ -371,6 +379,7 @@ def clean_html_version(html)
end

html&.gsub!(/<br\s*\/?>$/, "")&.gsub!(/<br\s*\/?>$/, "")&.gsub!(/^$\n/, "") # remove last unnecessary line break
html&.gsub!(/\A(\s*<br\s*\/?>|\s*<p>\s*<\/p>|\s*<div>\s*<\/div>|\s*\n|\s*\r\n)*/, '')

to_utf8(html)
end
Expand Down

0 comments on commit 03286d1

Please sign in to comment.