From 72069e45ef97a399638989f0870df34c1d153136 Mon Sep 17 00:00:00 2001 From: Pranav Raj S Date: Thu, 15 Jul 2021 20:06:43 +0530 Subject: [PATCH] fix: Use mail.decoded as fallback for text content to fix char-rendering --- app/presenters/mail_presenter.rb | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/app/presenters/mail_presenter.rb b/app/presenters/mail_presenter.rb index cd17eb76f..4b26e86a3 100644 --- a/app/presenters/mail_presenter.rb +++ b/app/presenters/mail_presenter.rb @@ -12,7 +12,10 @@ class MailPresenter < SimpleDelegator end def text_content - @decoded_text_content ||= encode_to_unicode(text_part&.decoded || fallback_content) + @decoded_text_content ||= encode_to_unicode(text_part&.decoded || mail.decoded || '') + + return {} if @decoded_text_content.blank? + @text_content ||= { full: @decoded_text_content, reply: extract_reply(@decoded_text_content)[:reply], @@ -21,7 +24,10 @@ class MailPresenter < SimpleDelegator end def html_content - @decoded_html_content ||= encode_to_unicode(html_part&.decoded || fallback_content) + @decoded_html_content ||= encode_to_unicode(html_part&.decoded) + + return {} if @decoded_html_content.blank? + @html_content ||= { full: @decoded_html_content, reply: extract_reply(@decoded_html_content)[:reply], @@ -29,10 +35,6 @@ class MailPresenter < SimpleDelegator } end - def fallback_content - body&.decoded || '' - end - def attachments # ref : https://github.com/gorails-screencasts/action-mailbox-action-text/blob/master/app/mailboxes/posts_mailbox.rb mail.attachments.map do |attachment| @@ -69,6 +71,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) + return '' if str.blank? + current_encoding = str.encoding.name return str if current_encoding == 'UTF-8'