iachat/spec
Pranav 8cdbdaaa07
fix: Process attachments as regular attachments if the text/plain or text/html part is empty (#10379)
Some email clients automatically set Content-Disposition to inline for
specific content types, such as images. In cases where the email body is
empty, inline attachments may not display correctly due to our previous
implementation. Our assumption was that these attachments are referenced
within text/plain or text/html parts.

Customer-reported issues, especially with Apple Mail, show emails with
attachments marked as inline but without any corresponding text parts.
This leads to missing attachments even though would have processed the
attachment.

This update introduces a check for the presence of a text part. If none
exists, inline attachments are treated as regular attachments and added
to the external attachments array, ensuring that all attachments display
properly.

<details>
<summary><b>Script to update the existing emails that are already
available in the system</b></summary>

```rb
def update_content id
  message = Message.find id
  conversation = message.conversation
  message_id = message.source_id

  channel = message.inbox.channel

  authentication_type = 'XOAUTH2'
  imap_password = Google::RefreshOauthTokenService.new(channel: channel).access_token
  imap = Net::IMAP.new(channel.imap_address, port: channel.imap_port, ssl: true)
  imap.authenticate(authentication_type, channel.imap_login, imap_password)
  imap.select('INBOX')

  results = imap.search(['HEADER', 'MESSAGE-ID', message_id])
  message_content = imap.fetch(results.first, 'RFC822').first.attr['RFC822']
  mail = MailPresenter.new(Mail.read_from_string(message_content))

  mail_content = if mail.text_content.present?
                   mail.text_content[:reply]
                 elsif mail.html_content.present?
                   mail.html_content[:reply]
                 end

  attachments = mail.attachments.last(Message::NUMBER_OF_PERMITTED_ATTACHMENTS)
  inline_attachments = attachments.select { |attachment| attachment[:original].inline? && mail_content.present? }
  regular_attachments = attachments - inline_attachments

  regular_attachments.each do |mail_attachment|
    attachment = message.attachments.new(
      account_id: conversation.account_id,
      file_type: 'file'
    )
    attachment.file.attach(mail_attachment[:blob])
  end

  message.save!
end
```
</details>
2024-11-04 10:25:01 +01:00
..
actions fix: Migrate notes when merging the contacts (#8749) 2024-01-20 10:32:18 +04:00
assets chore: Contact import improvements (#7787) 2023-08-23 23:24:47 -07:00
builders feat: Render instagram reels in Chatwoot (#9829) 2024-07-24 12:58:12 -07:00
channels chore: Enable the new Rubocop rules (#7122) 2023-05-19 14:37:10 +05:30
configs chore: Enable the new Rubocop rules (#7122) 2023-05-19 14:37:10 +05:30
controllers feat(v4): Update the help center portal design (#10296) 2024-10-23 22:09:36 -07:00
dispatchers Non blocking event dispatch (#652) 2020-03-29 19:18:30 +05:30
drops feat: Add the support for custom attributes in message variables (#8511) 2023-12-08 14:13:35 -08:00
enterprise chore: Custom Roles to manage permissions [ UI ] (#9865) 2024-09-17 11:40:11 -07:00
factories fix: Include uncategorized articles in the all article section to allow edit/delete (#10153) 2024-09-23 23:39:03 -07:00
finders fix: Inbox view Read/Snoozed display filters (#8907) 2024-02-17 13:59:25 +05:30
fixtures fix: Process attachments as regular attachments if the text/plain or text/html part is empty (#10379) 2024-11-04 10:25:01 +01:00
helpers feat: Add contact helper (#8989) 2024-03-06 17:39:39 +05:30
integration Fix url in emails, add frontendURL helper (#19) 2019-08-25 19:59:28 +05:30
jobs chore: [Snyk] Security upgrade rspec-rails from 6.1.4 to 6.1.5 (#10066) 2024-09-16 09:44:07 +05:30
lib feat: Provision captain accounts automatically (#10168) 2024-09-26 19:21:29 -07:00
listeners fix: Use message sender ID in the analytics for first response time (#9605) 2024-06-06 20:20:35 -07:00
mailboxes fix: Process attachments as regular attachments if the text/plain or text/html part is empty (#10379) 2024-11-04 10:25:01 +01:00
mailers feat: add Google Email fetch and OAuth token refresh service (#9603) 2024-06-11 14:22:03 +05:30
models feat(v4): Update the help center portal design (#10296) 2024-10-23 22:09:36 -07:00
policies Feature: Ability to switch between multiple accounts (#881) 2020-05-26 22:38:48 +05:30
presenters chore: Stop processing auto-response emails (#9606) 2024-06-13 14:19:11 -07:00
requests/api/v1 feat: Update the slack integration-flow to allow users to select the channel (#7637) 2023-07-28 14:50:30 -07:00
services feat: Add the ability to un-assign teams using automation (#9668) 2024-06-26 12:40:36 -07:00
support feat: Slack link unfurling (#7940) 2023-09-29 19:35:56 +05:30
workers fix: Capture delivery errors to avoid false positives (#8790) 2024-01-26 14:22:18 +04:00
rails_helper.rb feat: locking and retry in FB message parsing (#7701) 2023-08-23 09:48:17 +07:00
spec_helper.rb feat(ee): Add reporting events for bots (#9027) 2024-02-27 14:53:28 -08:00
test_helper.rb Chore: Setup test coverage in codeclimate [#332] (#333) 2019-12-02 08:57:11 +05:30