EmailImporter: UTF-8 forcé pour nettoyage des caractères invalides

This commit is contained in:
Jérémy Lecour 2021-01-04 23:06:28 +01:00 committed by Jérémy Lecour
parent f7512345a8
commit 3dda716b68

View file

@ -47,7 +47,13 @@ class EmailImporter
mail.parts[0].decoded
end
elsif mail.content_type && mail.content_type.match?(/\btext\/html\b/)
html_to_text_class.new.convert(mail.decoded)
plain_text = html_to_text_class.new.convert(mail.decoded)
if mail.content_type.match?(/\butf-8\b/)
# force utf-8 charset, even if we have to remve invalid characters
plain_text.encode!('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '')
else
plain_text
end
else
mail.decoded
end