Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with handling quotation marks in attachment names #680

Open
jamo opened this issue Feb 25, 2014 · 2 comments
Open

Issues with handling quotation marks in attachment names #680

jamo opened this issue Feb 25, 2014 · 2 comments

Comments

@jamo
Copy link

jamo commented Feb 25, 2014

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) :)

@joeyAghion
Copy link

I ran into this recently. The cleanest thing appeared to be manually removing/replacing quotation marks in the names before attaching files, but it would be nice to have a proper fix. I'm happy to PR if someone can provide guidance about the correct encoding.

@j15e
Copy link

j15e commented Nov 22, 2015

I got into this issue too. It would be nice to raise if the quotes isn't supported in attachment filename rather than silently creating an invalid email.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants