Open
Description
I came across to this issue in Ruby On Rails (rails/rails#14158), and have traced it, and it seems that it might be actually a bug in mail
-gem.
I have tried to fix it, but my dirty fix makes one other test to fail:
1) Mail::UnstructuredField displaying encoded field and decoded value should encode additional special characters inside encoded-word-encoded strings
Failure/Error: @field.encoded.should eq result
expected: "Subject: =?UTF-8?Q?Her_er_=C3=A6=28=29<>@,;:\\=22/[]=3F.=3D?=\r\n"
got: "Subject: =?UTF-8?Q?Her_er_=C3=A6=28=29<>@,;:=22/[]=3F.=3D?=\r\n"
(compared using ==)
Diff:
@@ -1,2 +1,2 @@
-Subject: =?UTF-8?Q?Her_er_=C3=A6=28=29<>@,;:\=22/[]=3F.=3D?=
+Subject: =?UTF-8?Q?Her_er_=C3=A6=28=29<>@,;:=22/[]=3F.=3D?=
My "fix": https://github.com/jamox/mail/blob/fixing_fail_when_name_has_quotes/lib/mail/encodings.rb#L98-L110
Error occurs when in: https://github.com/mikel/mail/blob/master/lib/mail/attachments_list.rb#L40
def []=(name, value)
encoded_name = Mail::Encodings.decode_encode name, :encode
default_values = { :content_type => "#{set_mime_type(name)}; filename=\"#{encoded_name}\"",
:content_transfer_encoding => "#{guess_encoding}",
:content_disposition => "#{@content_disposition_type}; filename=\"#{encoded_name}\"" }
we have name = 'invoice "for you".pdf'
and then we insert it into
default_values = { :content_type => "#{set_mime_type(name)}; filename=\"#{encoded_name}\"",
Thus getting
default_values = { :content_type => "#{set_mime_type(name)}; filename=\"invoice \"for you\".pdf\"",
And later we get the filename \"invoice \"for you\".pdf\"
=> "invoice "for you".pdf"
...
Id be happy to fix this (in case this ain't due to misuse of this library) :)