From f64f2138dbbdf0a1cebd1f22bcce115ce5741212 Mon Sep 17 00:00:00 2001 From: Tejaswini Chile Date: Fri, 9 Jun 2023 16:08:40 +0530 Subject: [PATCH] fix: Update mail check for html_part (#7273) --- app/jobs/inboxes/fetch_imap_emails_job.rb | 2 +- app/mailboxes/mailbox_helper.rb | 6 +- .../mail_with_html_part_no_html_content.eml | 5985 +++++++++++++++++ spec/mailboxes/reply_mailbox_spec.rb | 23 + 4 files changed, 6011 insertions(+), 5 deletions(-) create mode 100644 spec/fixtures/files/mail_with_html_part_no_html_content.eml diff --git a/app/jobs/inboxes/fetch_imap_emails_job.rb b/app/jobs/inboxes/fetch_imap_emails_job.rb index 5173e478b..f2f1bd2e9 100644 --- a/app/jobs/inboxes/fetch_imap_emails_job.rb +++ b/app/jobs/inboxes/fetch_imap_emails_job.rb @@ -125,7 +125,7 @@ class Inboxes::FetchImapEmailsJob < ApplicationJob rescue StandardError => e ChatwootExceptionTracker.new(e, account: channel.account).capture_exception Rails.logger.error(" - #{channel.provider} Email dropped: #{inbound_mail.from} and message_source_id: #{inbound_mail.message_id}, message_id: #{message_id}") + #{channel.provider} Email dropped: #{inbound_mail.from} and message_source_id: #{inbound_mail.message_id}") end # Making sure the access token is valid for microsoft provider diff --git a/app/mailboxes/mailbox_helper.rb b/app/mailboxes/mailbox_helper.rb index f96266713..ec3685cc3 100644 --- a/app/mailboxes/mailbox_helper.rb +++ b/app/mailboxes/mailbox_helper.rb @@ -38,11 +38,9 @@ module MailboxHelper end def embed_inline_image_source(mail_attachment) - current_mail = processed_mail.mail - - if current_mail.html_part.present? + if processed_mail.serialized_data[:html_content].present? upload_inline_image(mail_attachment) - elsif current_mail.text_part.present? + elsif processed_mail.serialized_data[:text_content].present? embed_plain_text_email_with_inline_image(mail_attachment) end end diff --git a/spec/fixtures/files/mail_with_html_part_no_html_content.eml b/spec/fixtures/files/mail_with_html_part_no_html_content.eml new file mode 100644 index 000000000..1f64b7388 --- /dev/null +++ b/spec/fixtures/files/mail_with_html_part_no_html_content.eml @@ -0,0 +1,5985 @@ +Delivered-To: hello@chatwoot.com +Received: by 2002:a05:7010:e38c:b0:354:f2b8:cc31 with SMTP id ma12csp1010920mdb; + Wed, 7 Jun 2023 19:48:08 -0700 (PDT) +X-Google-Smtp-Source: ACHHUZ57LBzK2OVBP6udVBC9CbSsPHwJYC8okfkQWT8Q0m28WoFGG1VLohBJoHwQR2a6eqG7mvqi +X-Received: by 2002:a05:6a21:32a2:b0:100:eb1e:3939 with SMTP id yt34-20020a056a2132a200b00100eb1e3939mr4073677pzb.1.1686192487801; + Wed, 07 Jun 2023 19:48:07 -0700 (PDT) +ARC-Seal: i=2; a=rsa-sha256; t=1686192487; cv=pass; + d=google.com; s=arc-20160816; + b=gNCX3HZKz0nD1+rhJSWiDBq/1U7Ng8+1NHiTODRU0Qi2P+5MYwitJBckofu9T224wQ + WvuPgCnyOOYeVvROyFvy7r/aewAb8tiDUbpWUP5TC8zHeylH3rHiNICXYax7A4ZsOYM2 + WlHBruR/2PH8pa7ukmPs8r3uJr7LrPRcDcPI/SzvtvtD5B9BWWlg+thvDrV1IKAA1S9E + guQ8oTEdL5+aMylzldb/Wp+WEPsq5eDHiLIngq00MKOtbOkx/oSDwOR5a4ex0fpeLf5f + 2omGJiUV71El0U+x/uqZTwc2bMhw0ZKXD6p4hPAEdRAWWxvLtodXbGP18h8EEJBUleke + LvYQ== +ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; + h=user-agent:importance:mime-version:subject:message-id:to:from:date + :dkim-signature; + bh=c7IZAVOxMAePAqqcN/hReTJniMV6fL4PHunQIM8V12k=; + b=xjTumctRuw91odBSSUScU8fDrysl3EWdguMqnSFVVY4UDlVeRE4h/3eqnM0+1jYNOb + d+qQq4KMF2Q1KA4OZ2/Xz8qakc7ASZ503WYQ61Cd+qZJnyOXkdgyUwtPUteaoBHO792t + QTk0JGYIQ43CoQ+17veukiivv3MiDmnKzhIxkBbznQ51ahPfzUXLHpN4T1+fseATXuiU + 3WOdnJbUwfRbAWy9+AciWIqZGTsHAmjt/WW/h/jOtpWu1rhyD4sdmjbskyJizqqS3Aqo + l4Zp/Sf8P8yK/4wPPKQF9qQ9W9iu2oZBPC8aAxWJuTOemKl3KzrOymdddb0SUYPBKAXs + X5pg== +ARC-Authentication-Results: i=2; mx.google.com; + dkim=pass header.i=@example.com header.s=pl header.b=VKZIicfZ; + arc=pass (i=1 spf=pass spfdomain=example.com dkim=pass dkdomain=example.com dmarc=pass fromdomain=example.com>); + spf=pass (google.com: domain of test.w@example.com designates 136.143.188.115 as permitted sender) smtp.mailfrom=test.w@example.com +Return-Path: +Received: from sender4-pp-f115.zoho.com (sender4-pp-f115.zoho.com. [136.143.188.115]) + by mx.google.com with ESMTPS id q22-20020aa79836000000b006634c05d13csi86057pfl.172.2023.06.07.19.48.07 + for + (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); + Wed, 07 Jun 2023 19:48:07 -0700 (PDT) +Received-SPF: pass (google.com: domain of test.w@example.com designates 136.143.188.115 as permitted sender) client-ip=136.143.188.115; +Authentication-Results: mx.google.com; + dkim=pass header.i=@example.com header.s=pl header.b=VKZIicfZ; + arc=pass (i=1 spf=pass spfdomain=example.com dkim=pass dkdomain=example.com dmarc=pass fromdomain=example.com>); + spf=pass (google.com: domain of test.w@example.com designates 136.143.188.115 as permitted sender) smtp.mailfrom=test.w@example.com +ARC-Seal: i=1; a=rsa-sha256; t=1686192485; cv=none; d=zohomail.com; s=zohoarc; b=QSgE7NI4tC9p/bfQw2/H0PgkCg+Fw7e22W6kpNTczkT4sQxX1+ju1CFF+/sN0K31/JuBKAfclr46/UxmjkXdRS2w4K+dlDSGCMpMdccjmnwwg4eGczfutcyhgL1o6vpUPH+NW7VrwjLNk95zD1l+TAVwgRaxt68Y9U04so25oTs= +ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1686192485; h=Content-Type:Date:From:MIME-Version:Message-ID:Subject:To; bh=c7IZAVOxMAePAqqcN/hReTJniMV6fL4PHunQIM8V12k=; b=lV34BJ1BkmRjvh7t5ZlOg5KsrEMoCZBHuyLv1tBzO1hqt1OTwT6vnVf8TUXVVqU5yI5qB+focsVqA+kFea/PttC5BRuAsww0iDm0XyfYCyY8QMyQ+RA51FvB6hYDnFyoC1D8ZliSHdcNsAEumuYmGyrbZBGxQH0vCMhs2+lnVXE= +ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass + header.i=example.com; spf=pass + smtp.mailfrom=test.w@example.com; dmarc=pass header.from= +DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1686192485; s=pl; d=example.com; i=test.w@example.com; h=Date:Date:From:From:To:To:Message-Id:Message-Id:Subject:Subject:MIME-Version:Content-Type:Reply-To:Cc; bh=c7IZAVOxMAePAqqcN/hReTJniMV6fL4PHunQIM8V12k=; b=VKZIicfZCxaYdi5lACEiz8f0IJFFNn67BD5cfhMDaYaYHJigtN+14SjFWptKGcSx ho94gttv/VzPJzcwi+Py2vf1bVWE8jBXLf3rmEdfSMUP9Tp7XtxOK5PB9XDLpR+5K+G pGndsa3D7i/uVH1pZ7DmKQf3cx8NFogBDIUY66Ec= +Received: from mail.zoho.com by mx.zohomail.com with SMTP id 1686192484329887.4815133280084; Wed, 7 Jun 2023 19:48:04 -0700 (PDT) +Date: Wed, 07 Jun 2023 21:48:04 -0500 +Message-ID: +Subject: New inline image test email conversation +From: Sony Mathew +To: "Replies" +MIME-Version: 1.0 +Content-Type: multipart/alternative; boundary="----=_Part_737886_53803080.1686187550614" +Importance: Medium +User-Agent: Zoho Mail +X-Mailer: Zoho Mail +X-Zoho-Virus-Status: 1 + +------=_Part_737886_53803080.1686187550614 +Content-Type: text/plain; charset="UTF-8" +Content-Transfer-Encoding: quoted-printable + +Greetings! + + + +This is test message. + + +=E2=80=8B + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +This is test message. =C2=A0 Thank you. + + + +Sincerely, + + +Sales Associate + +example.com +------=_Part_737886_53803080.1686187550614 +Content-Type: multipart/related; boundary="----=_Part_737887_1998664302.1686187550644" + +------=_Part_737887_1998664302.1686187550644 +Content-Type: text/html; charset="UTF-8" +Content-Transfer-Encoding: quoted-printable + += +
= +
<= +div style=3D"font-family : Verdana, = + Arial, Helvetica, sans-serif; font= +-size : 10pt;">
<= +div>
<= +div style=3D"font-family = + : Verdana, = + Arial, = + = + Helvetica, = + sans-serif; font-size = + : 10pt;">
= +
= +
= +
= +
= +
= +
<= +div style=3D"font-family = + = + = + : Verdana, = + = + = + Arial, = + = + = + Helvetica, = + = + = + sans-serif; font-size = + = + = + : 10pt;">
= +
Greetings!
= +

This is test, a Me= +dia Associate of example.com, example.com with 5 mi= +llion visitors monthly, Based on our marketing research, your services are = +among the best in the market. We believe that our readers will be the right= + target for you to promote your product and build up your branding.<= +/span>

= +Here are the 2 articles that we offer:

1. Ranki= +ng Article
2. Software/Product Review
= +
Meanwhile, example is well known for Ranking Articles. For exampl= +e, If you Google "Best Technology test Firms in India" or "Top 5 NFT, you = +can play, " you will see that our posts are on the 1st page of Google. (Thi= +s is an example we did for our client)

Currently, we are= + focusing on the "Top 5 Be= +st Shared Inbox Software in 2023<= +span>". Please let me know if you are interested in being featured as= + No.1. You can also sugges= +t the best keyword for your business.
=E2=80=8B
Please let me know if you are= + interested.  Thank you.
<= +div>
= +
= +
<= +div style=3D"font-family = + : Verdana= +, = + Arial, = + = + Helvetica, = + sans-se= +rif; font-size = + : 10pt;">
= +
= +
= +
= +
<= +div>

= +Sincerely,= +
test W= +right= +
Sales Associate
example.com

<= +div>


<= +/div>
<= +/div>
<= +/div>
<= +/div>
<= +/div>
<= +/div>
<= +/div>
<= +/div>
<= +/div>
<= +/div>
<= +/div>
<= +/div>
<= +/div>
<= +/div>
<= +div>
<= +div style=3D"font-family = + : Verdana, = + Arial, = + = + Helvetica, = + sans-serif; font-size = + : 10pt;">
= +
= +
= +
= +
= +

= +
= +







<= +br>


= +



= +



= +



= +













<= +br>


= +



= +



= +



= +













<= +br>


= +



= +



= +










<= +br>


= +



= +



= +



= +













<= +br>


= +



= +



= +



= +













<= +br>


= +



= +



+------=_Part_737887_1998664302.1686187550644 +Content-Type: image/png; name=1.png +Content-Transfer-Encoding: base64 +Content-Disposition: inline; filename=1.png +Content-ID: <0.28869202910.6138388557080725296.1839baef51b__inline__img__src> + + +------=_Part_737887_1998664302.1686187550644-- +------=_Part_737886_53803080.1686187550614-- diff --git a/spec/mailboxes/reply_mailbox_spec.rb b/spec/mailboxes/reply_mailbox_spec.rb index d8d0991a8..0bee15fa9 100644 --- a/spec/mailboxes/reply_mailbox_spec.rb +++ b/spec/mailboxes/reply_mailbox_spec.rb @@ -110,6 +110,29 @@ RSpec.describe ReplyMailbox do end end + context 'with inline attachments and html_part' do + let(:mail_with_html_part_no_html_content) { create_inbound_email_from_fixture('mail_with_html_part_no_html_content.eml') } + let(:described_subject) { described_class.receive mail_with_html_part_no_html_content } + + before do + conversation.uuid = '6bdc3f4d-0bed-4515-a284-5d916fdde489' + conversation.save! + + described_subject + end + + it 'mail content will create message' do + expect(conversation.messages.last.content).to include('This is test message.') + end + + it 'html_content is empty' do + expect(conversation.messages.last.attachments.count).to eq(0) + + html_full_content = conversation.messages.last.content_attributes[:email][:html_content][:full] + expect(html_full_content).to be_nil + end + end + context 'with reply_to email address present' do let(:email_channel) { create(:channel_email, email: 'test@example.com', account: account) } let(:conversation_1) do