From 505c93c46748ca014adae079431f3a7617864322 Mon Sep 17 00:00:00 2001 From: Pranav Raj S Date: Tue, 15 Feb 2022 17:19:28 +0530 Subject: [PATCH] revert: "fix: html content is available and mail_part empty" (#3986) Reverts de4e4c6 --- app/presenters/mail_presenter.rb | 25 ++--- spec/fixtures/files/support_1.eml | 144 ------------------------- spec/mailboxes/support_mailbox_spec.rb | 23 ---- 3 files changed, 9 insertions(+), 183 deletions(-) delete mode 100644 spec/fixtures/files/support_1.eml 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 - - - - - - - - - - - - - -
-Hi,

We are providing you platform from here you can sell= -paid posts on your website. - -

Chatwoot | CS team | C

-

Skype: live:.cid.something

- -
-3D"" - - diff --git a/spec/mailboxes/support_mailbox_spec.rb b/spec/mailboxes/support_mailbox_spec.rb index da2e1df9f..c0cb4a5b9 100644 --- a/spec/mailboxes/support_mailbox_spec.rb +++ b/spec/mailboxes/support_mailbox_spec.rb @@ -157,29 +157,6 @@ RSpec.describe SupportMailbox, type: :mailbox do end end - describe 'when mail part is not present' do - let(:support_mail) { create_inbound_email_from_fixture('support_1.eml') } - let(:described_subject) { described_class.receive support_mail } - - it 'Considers raw html mail body' do - described_subject - expect(conversation.inbox.id).to eq(channel_email.inbox.id) - expect(conversation.messages.last.content).to include( - <<-BODY.strip_heredoc.chomp - Hi, - We are providing you platform from here you can sellpaid posts on your website. - - Chatwoot | CS team | [C](https://d33wubrfki0l68.cloudfront.net/973467c532160fd8b940300a43fa85fa2d060307/dc9a0/static/brand-73f58cdefae282ae74cebfa74c1d7003.svg) - - Skype: live:.cid.something - - [] - BODY - ) - expect(conversation.messages.last.content_attributes['email']['subject']).to eq('Get Paid to post an article') - end - end - describe 'Sender with reply_to email address' do let(:reply_to_mail) { create_inbound_email_from_fixture('reply_to.eml') } let(:email_channel) { create(:channel_email, email: 'test@example.com', account: account) }