diff --git a/app/presenters/mail_presenter.rb b/app/presenters/mail_presenter.rb index bea652eb7..9ab3a5d38 100644 --- a/app/presenters/mail_presenter.rb +++ b/app/presenters/mail_presenter.rb @@ -27,21 +27,17 @@ class MailPresenter < SimpleDelegator end # returns encoded mail body text_part if available. - # returns encoded raw mail body as it is if mail_part not available. + # returns encoded mail body as it is if mail_part not available. # else returns parsed the html body if contains text/html content. def select_body(mail_part) - decoded = if mail_part - mail_part.decoded - else - raw_mail_body - end + return encoded_mail_body unless mail_part - encoded = encode_to_unicode(decoded) + decoded = encode_to_unicode(mail_part.decoded) if mail.text_part - encoded + decoded elsif html_mail_body? - ::HtmlParser.parse_reply(encoded) + ::HtmlParser.parse_reply(decoded) end end @@ -135,15 +131,12 @@ class MailPresenter < SimpleDelegator end def html_mail_body? - ((mail.content_type || '').include? 'text/html') || @mail.html_part&.content_type&.include?('text/html') + ((mail.content_type || '').include? 'text/html') || @mail.html_part || @mail.html_part.content_type.include?('text/html') end - def text_mail_body? - ((mail.content_type || '').include? 'text') || @mail.text_part&.content_type&.include?('text') - end - - def raw_mail_body - return @mail.body.decoded if html_mail_body? || text_mail_body? + # returns mail body if mail content_type is text/plain + def encoded_mail_body + return encode_to_unicode(@mail.body.decoded) if (@mail.content_type || '').include? 'text/plain' '' end diff --git a/spec/fixtures/files/support_1.eml b/spec/fixtures/files/support_1.eml deleted file mode 100644 index c16f461cf..000000000 --- a/spec/fixtures/files/support_1.eml +++ /dev/null @@ -1,144 +0,0 @@ -Date: Fri, 11 Feb 2022 05:15:51 +0000 -Mime-Version: 1.0 -Subject: Get Paid to post an article -From: sony@chatwoot.com -To: care@example.com -X-Mailgun-Tag: test1 -X-Mailgun-Track-Clicks: true -X-Mailgun-Track: true -X-Mailgun-Track-Opens: true -Message-Id: <20220211051551.0ac6490aa10da09b@chatwoot.com> -Content-Type: text/html; charset="ascii" -Content-Transfer-Encoding: quoted-printable - - - - -
-Chatwoot | CS team | C
-Skype: live:.cid.something
- -