Navigation Menu

Skip to content

Commit

Permalink
Revert "Fixes #3529 - Attachments sent by Zammad not shown in Outlook."
Browse files Browse the repository at this point in the history
This reverts commit a862a44.
  • Loading branch information
rolfschmidt committed May 11, 2021
1 parent d5e1db2 commit be64e3f
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 989 deletions.
14 changes: 1 addition & 13 deletions app/models/channel/email_build.rb
Expand Up @@ -82,26 +82,14 @@ def self.build(attr, notification = false)
alternative_bodies = Mail::Part.new { content_type 'multipart/alternative' }
alternative_bodies.add_part text_alternative

found_content_ids = {}
if html_alternative

# check if content-ids are used in body
attr[:attachments]&.each do |attachment|
next if attachment.instance_of?(Hash)
next if attachment.preferences['Content-ID'].blank?
next if !/<img [^>]* src="cid:#{Regexp.quote(attachment.preferences['Content-ID'])}" [^>]*>/xmsi.match?(html_alternative.body.to_s)

found_content_ids[ attachment.preferences['Content-ID'] ] = true
end

html_container = Mail::Part.new { content_type 'multipart/related' }
html_container.add_part html_alternative

# place to add inline attachments related to html alternative
attr[:attachments]&.each do |attachment|
next if attachment.instance_of?(Hash)
next if attachment.preferences['Content-ID'].blank?
next if !found_content_ids[ attachment.preferences['Content-ID'] ]

attachment = Mail::Part.new do
content_type attachment.preferences['Content-Type']
Expand All @@ -123,7 +111,7 @@ def self.build(attr, notification = false)
attachment['content-id'] = nil
mail.attachments[attachment[:filename]] = attachment
else
next if attachment.preferences['Content-ID'].present? && found_content_ids[ attachment.preferences['Content-ID'] ]
next if attachment.preferences['Content-ID'].present?

filename = attachment.filename
encoded_filename = Mail::Encodings.decode_encode filename, :encode
Expand Down
33 changes: 0 additions & 33 deletions spec/models/channel/email_parser_spec.rb
Expand Up @@ -1064,39 +1064,6 @@
expect(article.attachments.first.content).to eq('Hello Zammad')
end
end

# https://github.com/zammad/zammad/issues/3529
context 'Attachments sent by Zammad not shown in Outlook' do
let(:mail_file) { Rails.root.join('test/data/mail/mail101.box') }

before do
described_class.new.process({}, raw_mail)
end

it 'does not have content disposition inline because the file is not referenced in body' do
mail = Channel::EmailBuild.build(
from: 'sender@example.com',
to: 'recipient@example.com',
body: 'somebody with some text',
content_type: 'text/html',
attachments: Store.where(filename: 'super-seven.jpg')
)
expect(mail.to_s).to include('Content-Disposition: attachment')
expect(mail.to_s).not_to include('Content-Disposition: inline')
end

it 'does have content disposition inline because the file is referenced in body' do
mail = Channel::EmailBuild.build(
from: 'sender@example.com',
to: 'recipient@example.com',
body: "somebody with some text <img src=\"cid:#{Store.find_by(filename: 'super-seven.jpg').preferences['Content-ID']}\">",
content_type: 'text/html',
attachments: Store.where(filename: 'super-seven.jpg')
)
expect(mail.to_s).to include('Content-Disposition: inline')
expect(mail.to_s).not_to include('Content-Disposition: attachment')
end
end
end

describe 'inline image handling' do
Expand Down

0 comments on commit be64e3f

Please sign in to comment.