fix: Email attachments created with empty filename (#10420)

- We observed in prod for certain emails active storage blob objects
were getting created with empty file name. The conversations further
causes conversation and filter pages to break. This change will fix the
mentioned issue.

fixes:
https://linear.app/chatwoot/issue/CW-3331/missing-file-name-for-some-of-the-uploads-for-emails

---------

Co-authored-by: Pranav <pranavrajs@gmail.com>
This commit is contained in:
Sojan Jose
2024-11-15 09:07:24 +04:00
committed by GitHub
parent 4cfa7e4c97
commit 933ae8aa49
3 changed files with 60 additions and 1 deletions

View File

@@ -43,6 +43,22 @@ RSpec.describe Imap::ImapMailbox do
end
end
context 'when the email has attachments with no filename' do
let(:inbound_mail) { create_inbound_email_from_fixture('attachments_without_filename.eml') }
it 'creates a conversation and a message with properly named attachments' do
expect do
class_instance.process(inbound_mail.mail, channel)
end.to change(Conversation, :count).by(1)
last_message = conversation.messages.last
expect(last_message.attachments.count).to be 2
filenames = last_message.attachments.map(&:file).map { |file| file.blob.filename.to_s }
expect(filenames.all? { |filename| filename.present? && filename.start_with?('attachment_') }).to be true
end
end
context 'when the email has 15 or more attachments' do
let(:inbound_mail) { create_inbound_email_from_fixture('multiple_attachments.eml') }