diff --git a/app/services/email_importer.rb b/app/services/email_importer.rb index 55f991c..b00e83b 100644 --- a/app/services/email_importer.rb +++ b/app/services/email_importer.rb @@ -42,9 +42,9 @@ class EmailImporter end elsif mail.content_type && mail.content_type.match?(/\btext\/html\b/) 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: '') + + if mail.content_type.match?(/\butf-8\b/i) and !plain_text.valid_encoding? + plain_text.encode('UTF-8', 'binary', invalid: :replace, undef: :replace) else plain_text end