This is an HTML message with an inline image.
+
+
+
+
+------=_NextPart_001_0002--
+
+------=_NextPart_000_0001
+Content-Type: image/jpeg;
+ filename="image001.jpg"
+Content-Transfer-Encoding: base64
+Content-ID:
')
+
+ expect(helper_instance.send(:body_references_cid?, 'image001.jpg@test')).to be true
+ end
+ end
+
+ describe '#upload_inline_image' do
+ let(:mail_attachment) do
+ {
+ original: OpenStruct.new(cid: 'image001.jpg@test'),
+ blob: get_blob_for('spec/assets/avatar.png', 'image/png')
+ }
+ end
+ let(:helper_instance) { mailbox_helper_obj.new(conversation, processed_mail) }
+
+ it 'replaces percent-encoded CID references in HTML content' do
+ allow(Rails.application.routes.url_helpers).to receive(:url_for).and_return('/fake-image-url')
+ helper_instance.instance_variable_set(:@html_content, '
')
+
+ helper_instance.send(:upload_inline_image, mail_attachment)
+
+ html_content = helper_instance.instance_variable_get(:@html_content)
+ expect(html_content).to include('/fake-image-url"')
+ expect(html_content).not_to include('cid:')
+ end
+ end
+
+ describe '#add_attachments_to_message' do
+ let(:mail) { create_inbound_email_from_fixture('cid_inline_images_without_disposition.eml').mail }
+ let(:processed_mail) { MailPresenter.new(mail) }
+ let(:conversation) { create(:conversation) }
+ let(:helper_instance) { mailbox_helper_obj.new(conversation, processed_mail) }
+
+ before do
+ helper_instance.send(:create_message)
+ end
+
+ it 'detects inline image attachment by cid reference when Content-Disposition is missing' do
+ allow(Rails.application.routes.url_helpers).to receive(:url_for).and_return('/fake-image-url')
+ helper_instance.send(:add_attachments_to_message)
+
+ message = conversation.messages[0]
+
+ expect(message.attachments.count).to eq(0)
+
+ html_content = message.content_attributes[:email][:html_content][:full]
+
+ expect(html_content).to include('/fake-image-url"')
+ expect(html_content).not_to include('cid:')
+ end
+ end
end