iachat/app
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: downcase email before finding (#8921) 2024-02-21 18:51:00 +05:30
assets feat: Vite + vue 3 💚 (#10047) 2024-10-02 00:36:30 -07:00
builders fix: default return in blocked domains (#10046) 2024-08-29 15:36:57 +05:30
channels chore: Sentry issues (#4623) 2022-05-06 14:50:55 +05:30
controllers feat(v4): Update the help center portal design (#10296) 2024-10-23 22:09:36 -07:00
dashboards feat: Super admin design improvements (#8517) 2023-12-08 19:40:35 -08:00
dispatchers fix: assignee_changed callback not getting triggered during conversation creation (#9334) 2024-05-06 11:48:17 -07:00
drops feat: Add the support for custom attributes in message variables (#8511) 2023-12-08 14:13:35 -08:00
fields feat: Supports masking tokens in super admin (#6491) 2023-02-21 17:50:55 +05:30
finders feat: Conversation API to return applied_sla and sla_events (#9174) 2024-04-01 23:30:07 +05:30
helpers feat: Improve Report API performance (#9476) 2024-05-22 17:34:24 -07:00
javascript feat(v4): Update the campaigns page design (#10371) 2024-10-31 11:57:13 +05:30
jobs feat: Integration with Captain (alpha) (#9834) 2024-07-25 14:24:04 -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 chore: Custom Roles to manage permissions [ UI ] (#9865) 2024-09-17 11:40:11 -07:00
presenters fix: last_activity_at is nil when conv is created (#9934) 2024-08-12 15:15:49 +05:30
services fix: ip-lookup database lazy loading for all environments (#8052) 2024-10-22 23:18:30 -07:00
views feat(v4): Update the help center portal design (#10296) 2024-10-23 22:09:36 -07:00
workers fix: Capture delivery errors to avoid false positives (#8790) 2024-01-26 14:22:18 +04:00