Skip to content

Commit 3cfc798

Browse files
committed
Fixed failing encoding / decoding test - reverted commit f721e24
1 parent a457606 commit 3cfc798

File tree

5 files changed

+30
-4
lines changed

5 files changed

+30
-4
lines changed

lib/tmail/attachments.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def attachments
4141
end
4242

4343
private
44-
44+
require 'ruby-debug'
4545
def attachment(part)
4646
if part.multipart?
4747
part.attachments

lib/tmail/quoting.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,17 @@ class Attachment
6060

6161
include TextUtils
6262

63+
def quoted?(string)
64+
!!((string =~ /.+'\w\w'.+/) || (string =~ /=\?.+\?.\?.+\?=/))
65+
end
66+
67+
# Only unquote if quoted
6368
def original_filename(to_charset = 'utf-8')
64-
Unquoter.unquote_and_convert_to(quoted_filename, to_charset).chomp
69+
if quoted?(quoted_filename)
70+
Unquoter.unquote_and_convert_to(quoted_filename, to_charset).chomp
71+
else
72+
quoted_filename
73+
end
6574
end
6675
end
6776

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Return-path: <[email protected]>
2+
Envelope-to: [email protected]
3+
Delivery-date: Mon, 09 Mar 2009 13:18:38 +0100
4+
Message-Id: <[email protected]>
5+
From: Stefan Haubold <[email protected]>
6+
To: Stefan Haubold <[email protected]>
7+
Content-Type: text/plain; charset=US-ASCII; format=flowed
8+
Content-Transfer-Encoding: 7bit
9+
Mime-Version: 1.0 (Apple Message framework v930.3)
10+
Subject: =?UTF-8?Q?Stefan_Haubold_hat_dich_als_FreundIn_auf_Facebook_hinzugef=C3?=
11+
=?UTF-8?Q?=BCgt_...?=
12+
Date: Mon, 9 Mar 2009 13:18:26 +0100
13+
X-Mailer: Apple Mail (2.930.3)
14+
15+
test

test/test_attachments.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ def test_decode_encoded_attachment_filename
4444
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email8")
4545
mail = TMail::Mail.parse(fixture)
4646
attachment = mail.attachments.last
47-
assert_equal "01 Quien Te Dij\302\212at. Pitbull.mp3", attachment.original_filename unless RUBY_VERSION.match(/1.9/)
47+
expected = "01 Quien Te Dij\212at. Pitbull.mp3"
48+
expected.force_encoding(Encoding::ASCII_8BIT) if expected.respond_to?(:force_encoding)
49+
assert_equal expected, attachment.original_filename
4850
end
4951

5052
def test_attachment_with_quoted_filename

tmail.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
66

77
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
88
s.authors = ["Mikel Lindsaar <raasdnil AT gmail.com>"]
9-
s.date = %q{2009-05-17}
9+
s.date = %q{2010-01-06}
1010
s.description = %q{TMail is a Ruby-based mail handler. It allows you to compose stadards compliant emails in a very Ruby-way.}
1111
s.email = %q{raasdnil AT gmail.com}
1212
s.extensions = ["ext/tmailscanner/tmail/extconf.rb"]

0 commit comments

Comments
 (0)