Skip to content

Commit

Permalink
Fix token quoting with UTF-8 attributes
Browse files Browse the repository at this point in the history
References #1191
  • Loading branch information
ahorek authored and jeremy committed Feb 28, 2018
1 parent 061d092 commit e304218
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Performance:

Bugs:
* Fix transfer encoding when message encoding is blank. (jakubonty, saks)
* Fix UTF-8 attachment filename quoting. (ahorek)


== Version 2.7.0 (2017-10-31)
Expand Down
12 changes: 11 additions & 1 deletion lib/mail/utilities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,17 @@ def token_safe?( str )
# If the string supplied has TOKEN unsafe characters in it, will return the string quoted
# in double quotes, otherwise returns the string unmodified
def quote_token( str )
token_safe?( str ) ? str : dquote(str)
if str.respond_to?(:force_encoding)
original_encoding = str.encoding
ascii_str = str.dup.force_encoding('ASCII-8BIT')
if token_safe?( ascii_str )
str
else
dquote(ascii_str).force_encoding(original_encoding)
end
else
token_safe?( str ) ? str : dquote(str)
end
end

# Wraps supplied string in double quotes and applies \-escaping as necessary,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Mime-Version: 1.0 (Apple Message framework v730)
Content-Type: multipart/mixed; boundary=Apple-Mail-13-196941151
Message-Id: <9169D984-4E0B-45EF-82D4-8F5E53AD7012@example.com>
From: foo@example.com
Subject: testing
Date: Mon, 6 Jun 2005 22:21:22 +0200
To: blah@example.com


--Apple-Mail-13-196941151
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
charset=ISO-8859-1;
delsp=yes;
format=flowed
This is the first part.
--Apple-Mail-13-196941151
Content-Type: text/plain; name=ciële.txt
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename=ciële.txt
Hi there.
--Apple-Mail-13-196941151--

6 changes: 6 additions & 0 deletions spec/mail/attachments_list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,12 @@ def check_decoded(actual, expected)
expect(mail.attachments.first.filename).to eq "This is a test.txt"
end

it "should decode an attachment without ascii compatible filename" do
mail = read_fixture('emails/attachment_emails/attachment_nonascii_filename.eml')
expect(mail.attachments.length).to eq 1
expect(mail.attachments.first.filename).to eq "ciële.txt"
end

it "should find attachments inside parts with content-type message/rfc822" do
mail = read_fixture('emails/attachment_emails/attachment_message_rfc822.eml')
expect(mail.attachments.length).to eq 1
Expand Down

0 comments on commit e304218

Please sign in to comment.