diff --git a/app/models/channel/email_build.rb b/app/models/channel/email_build.rb index b01182cbf..67e6eae51 100644 --- a/app/models/channel/email_build.rb +++ b/app/models/channel/email_build.rb @@ -105,13 +105,13 @@ module Channel::EmailBuild attr[:attachments]&.each do |attachment| if attachment.class == Hash attachment['content-id'] = nil - mail.attachments[ attachment[:filename] ] = attachment + mail.attachments[attachment[:filename]] = attachment else next if attachment.preferences['Content-ID'].present? filename = attachment.filename encoded_filename = Mail::Encodings.decode_encode filename, :encode disposition = attachment.preferences['Content-Disposition'] || 'attachment' - content_type = attachment.preferences['Content-Type'] || 'application/octet-stream' + content_type = attachment.preferences['Content-Type'] || attachment.preferences['Mime-Type'] || 'application/octet-stream' mail.attachments[attachment.filename] = { content_disposition: "#{disposition}; filename=\"#{encoded_filename}\"", content_type: "#{content_type}; filename=\"#{encoded_filename}\"", diff --git a/test/unit/email_build_test.rb b/test/unit/email_build_test.rb index cf6585e4d..71d850ab4 100644 --- a/test/unit/email_build_test.rb +++ b/test/unit/email_build_test.rb @@ -49,8 +49,8 @@ class EmailBuildTest < ActiveSupport::TestCase { 'Mime-Type' => 'image/png', :content => 'xxx', - :filename => 'somename.png', - }, + :filename => 'somename.png' + } ], ) @@ -103,8 +103,8 @@ class EmailBuildTest < ActiveSupport::TestCase { 'Mime-Type' => 'image/png', :content => 'xxx', - :filename => 'somename.png', - }, + :filename => 'somename.png' + } ], ) @@ -114,6 +114,7 @@ class EmailBuildTest < ActiveSupport::TestCase >' assert_equal(should, mail.text_part.body.to_s) assert_nil(mail.html_part) + assert_equal('image/png; filename=somename.png', mail.attachments[0].content_type) parser = Channel::EmailParser.new data = parser.parse(mail.to_s) @@ -137,6 +138,88 @@ class EmailBuildTest < ActiveSupport::TestCase end end + test 'plain email + attachment check 2' do + ticket1 = Ticket.create!( + title: 'some article helper test1', + group: Group.lookup(name: 'Users'), + customer_id: 2, + state: Ticket::State.lookup(name: 'new'), + priority: Ticket::Priority.lookup(name: '2 normal'), + updated_by_id: 1, + created_by_id: 1, + ) + assert(ticket1, 'ticket created') + + # create inbound article #1 + article1 = Ticket::Article.create!( + ticket_id: ticket1.id, + from: 'some_sender@example.com', + to: 'some_recipient@example.com', + subject: 'some subject', + message_id: 'some@id', + content_type: 'text/html', + body: 'some message article helper test1