diff --git a/app/presenters/mail_presenter.rb b/app/presenters/mail_presenter.rb index a320c1ce0..40070fd04 100644 --- a/app/presenters/mail_presenter.rb +++ b/app/presenters/mail_presenter.rb @@ -12,7 +12,7 @@ class MailPresenter < SimpleDelegator end def text_content - @decoded_text_content ||= encode_to_unicode(text_part&.body&.decoded || fallback_content) + @decoded_text_content ||= encode_to_unicode(text_part&.decoded || fallback_content) @text_content ||= { full: @decoded_text_content, reply: extract_reply(@decoded_text_content)[:reply], @@ -21,7 +21,7 @@ class MailPresenter < SimpleDelegator end def html_content - @decoded_html_content ||= encode_to_unicode(html_part&.body&.decoded || fallback_content) + @decoded_html_content ||= encode_to_unicode(html_part&.decoded || fallback_content) @html_content ||= { full: @decoded_html_content, reply: extract_reply(@decoded_html_content)[:reply], @@ -70,6 +70,8 @@ class MailPresenter < SimpleDelegator # forcing the encoding of the content to UTF-8 so as to be compatible with database and serializers def encode_to_unicode(str) current_encoding = str.encoding.name + return str if current_encoding == 'UTF-8' + str.encode(current_encoding, 'UTF-8', invalid: :replace, undef: :replace, replace: '?') end