diff --git a/app/presenters/mail_presenter.rb b/app/presenters/mail_presenter.rb index 4ad650db8..e42bbbf7b 100644 --- a/app/presenters/mail_presenter.rb +++ b/app/presenters/mail_presenter.rb @@ -27,17 +27,21 @@ class MailPresenter < SimpleDelegator end # returns encoded mail body text_part if available. - # returns encoded mail body as it is if mail_part not available. + # returns encoded raw 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) - return encoded_mail_body unless mail_part + decoded = if mail_part + mail_part.decoded + else + raw_mail_body + end - decoded = encode_to_unicode(mail_part.decoded) + encoded = encode_to_unicode(decoded) if mail.text_part - decoded + encoded elsif html_mail_body? - ::HtmlParser.parse_reply(decoded) + ::HtmlParser.parse_reply(encoded) end end @@ -131,12 +135,15 @@ class MailPresenter < SimpleDelegator end def html_mail_body? - ((mail.content_type || '').include? 'text/html') || @mail.html_part || @mail.html_part.content_type.include?('text/html') + ((mail.content_type || '').include? 'text/html') || @mail.html_part&.content_type&.include?('text/html') end - # 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' + 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? '' end diff --git a/spec/fixtures/files/support_1.eml b/spec/fixtures/files/support_1.eml new file mode 100644 index 000000000..c16f461cf --- /dev/null +++ b/spec/fixtures/files/support_1.eml @@ -0,0 +1,144 @@ +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
+ +