Skip to content

Commit

Permalink
Fix DABBLE-ME-6G
Browse files Browse the repository at this point in the history
  • Loading branch information
parterburn committed Sep 2, 2024
1 parent e51095e commit b344eae
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions app/lib/email_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,6 @@ def clean_message(body)
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!("p.MsoNormal,p.MsoNoSpacing{margin:0}", "") # remove outlook styles
body&.gsub!("\0", '') # remove null characters
body = body&.strip

return unless body.present?
Expand All @@ -325,17 +324,17 @@ def clean_message(body)

def to_utf8(content)
return unless content.present?
content = content&.gsub!("\0", '') # remove null characters

begin
detection = CharlockHolmes::EncodingDetector.detect(content)
if detection[:confidence] > 95
CharlockHolmes::Converter.convert content, detection[:encoding].gsub("IBM424_ltr", "UTF-8"), "UTF-8"
else
content
content = CharlockHolmes::Converter.convert content, detection[:encoding].gsub("IBM424_ltr", "UTF-8"), "UTF-8"
end
rescue
content
end

content
end

def clean_html_version(html)
Expand Down Expand Up @@ -363,7 +362,6 @@ def clean_html_version(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
html&.gsub!("p.MsoNormal,p.MsoNoSpacing{margin:0}", "") # remove outlook styles
html&.gsub!("\0", '') # remove null characters

empty_line_regex = /(<div>\n<div>\z)|(<br\s*\/?>\z)|(\n\z)/
while html&.match?(empty_line_regex)
Expand Down

0 comments on commit b344eae

Please sign in to comment.