According to RFC2183 any Content-Disposition: header may contain the filename parameter: for attachments as well as inline disposition types:
disposition := "Content-Disposition" ":"
disposition-type
*(";" disposition-parm)
disposition-type := "inline"
/ "attachment"
/ extension-token
; values are not case-sensitive
disposition-parm := filename-parm
/ creation-date-parm
/ modification-date-parm
/ read-date-parm
/ size-parm
/ parameter
filename-parm := "filename" "=" value
Setting the filename on an inline MIME part is useful in situations when it's desirable to include some files as inline parts (e.g. inline image, pdf etc): client MUA or webmail then presents the correct filename when the user wants to download the file. Currently, ActionMailer adds the filename parameter for attachments only (part.rb):
if content_disposition == "attachment"
ctype_attrs.delete "charset"
part.set_content_type(real_content_type, nil,
squish("name" => filename).merge(ctype_attrs))
part.set_content_disposition(content_disposition,
squish("filename" => filename).merge(ctype_attrs))
else
part.set_content_type(real_content_type, nil, ctype_attrs)
part.set_content_disposition(content_disposition)
end
I suggest to replace the above code with the following:
if content_disposition == "attachment"
ctype_attrs.delete "charset"
else
part.set_content_type(real_content_type, nil, ctype_attrs)
end
part.set_content_type(real_content_type, nil,
squish("name" => filename).merge(ctype_attrs))
part.set_content_disposition(content_disposition,
squish("filename" => filename).merge(ctype_attrs))
When the name or filename parameters are not used by the caller, the Content-Type: and Content-Disposition: headers will not be affected. For consistency, the name parameter is also added to the Content-Type: header when filename is provided ( see RFC2045 for discussion about media types and parameters).
Code patch to the edge rails and units are attached. With the patch applied, it's easy to include inline images with correct filenames, e.g.:
part :content_type => 'text/plain',
:body => 'Hello text!'
part 'multipart/mixed' do |p|
p.content_type = 'text/html'
p.part :content_type => 'image/png',
:content_disposition => 'inline',
:filename => 'rails-logo.png',
:transfer_encoding => 'base64',
:body => File.read('/tmp/rails.png')
p.part :content_type => 'text/html',
:body => '<html><body>inline image with filename provided</body></html>'
end