From 327a0bd50a36e820c122135c73f62f8572484751 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Tue, 17 May 2016 11:55:12 +0200 Subject: [PATCH] Add filename to attachment parts. --- app/models/channel/email_build.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/models/channel/email_build.rb b/app/models/channel/email_build.rb index a7a0fb42b..4871cee7b 100644 --- a/app/models/channel/email_build.rb +++ b/app/models/channel/email_build.rb @@ -90,7 +90,7 @@ module Channel::EmailBuild next if attachment.preferences['Content-ID'].empty? attachment = Mail::Part.new do content_type attachment.preferences['Content-Type'] - content_id attachment.preferences['Content-ID'] + content_id "<#{attachment.preferences['Content-ID']}>" content_disposition attachment.preferences['Content-Disposition'] || 'inline' content_transfer_encoding 'binary' body attachment.content.force_encoding('BINARY') @@ -111,10 +111,13 @@ module Channel::EmailBuild mail.attachments[ attachment[:filename] ] = attachment else next if !attachment.preferences['Content-ID'].empty? + 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' mail.attachments[attachment.filename] = { - content_disposition: attachment.preferences['Content-Disposition'] || 'attachment', - content_type: attachment.preferences['Content-Type'], - mime_type: attachment.preferences['Mime-Type'], + content_disposition: "#{disposition}; filename=\"#{encoded_filename}\"", + content_type: "#{content_type}; filename=\"#{encoded_filename}\"", content: attachment.content } end