mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Make sure TMail#attachments includes anything with content-disposition of "attachment", regardless of content-type
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3474 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
7d0d0f0edd
commit
acfb8b6191
4 changed files with 44 additions and 1 deletions
|
@ -1,5 +1,7 @@
|
||||||
*SVN*
|
*SVN*
|
||||||
|
|
||||||
|
* Make sure TMail#attachments includes anything with content-disposition of "attachment", regardless of content-type [Jamis Buck]
|
||||||
|
|
||||||
* Rename Version constant to VERSION. #2802 [Marcel Molina Jr.]
|
* Rename Version constant to VERSION. #2802 [Marcel Molina Jr.]
|
||||||
|
|
||||||
* Stricter matching for implicitly multipart filenames excludes files ending in unsupported extensions (such as foo.rhtml.bak) and without a two-part content type (such as foo.text.rhtml or foo.text.really.plain.rhtml). #2398 [Dave Burt <dave@burt.id.au>, Jeremy Kemper]
|
* Stricter matching for implicitly multipart filenames excludes files ending in unsupported extensions (such as foo.rhtml.bak) and without a two-part content type (such as foo.text.rhtml or foo.text.really.plain.rhtml). #2398 [Dave Burt <dave@burt.id.au>, Jeremy Kemper]
|
||||||
|
|
|
@ -10,10 +10,15 @@ module TMail
|
||||||
multipart? && parts.any? { |part| part.header["content-type"].main_type != "text" }
|
multipart? && parts.any? { |part| part.header["content-type"].main_type != "text" }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def attachment?(part)
|
||||||
|
(part['content-disposition'] && part['content-disposition'].disposition == "attachment") ||
|
||||||
|
part.header['content-type'].main_type != "text"
|
||||||
|
end
|
||||||
|
|
||||||
def attachments
|
def attachments
|
||||||
if multipart?
|
if multipart?
|
||||||
parts.collect { |part|
|
parts.collect { |part|
|
||||||
if part.header["content-type"].main_type != "text"
|
if attachment?(part)
|
||||||
content = part.body # unquoted automatically by TMail#body
|
content = part.body # unquoted automatically by TMail#body
|
||||||
file_name = (part['content-location'] &&
|
file_name = (part['content-location'] &&
|
||||||
part['content-location'].body) ||
|
part['content-location'].body) ||
|
||||||
|
|
29
actionmailer/test/fixtures/raw_email13
vendored
Normal file
29
actionmailer/test/fixtures/raw_email13
vendored
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
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/x-ruby-script; name="hello.rb"
|
||||||
|
Content-Transfer-Encoding: 7bit
|
||||||
|
Content-Disposition: attachment;
|
||||||
|
filename="api.rb"
|
||||||
|
|
||||||
|
puts "Hello, world!"
|
||||||
|
gets
|
||||||
|
|
||||||
|
--Apple-Mail-13-196941151--
|
||||||
|
|
|
@ -573,6 +573,13 @@ EOF
|
||||||
assert_equal "Photo25.jpg", mail.attachments.first.original_filename
|
assert_equal "Photo25.jpg", mail.attachments.first.original_filename
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_attachment_with_text_type
|
||||||
|
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email13")
|
||||||
|
mail = TMail::Mail.parse(fixture)
|
||||||
|
assert_equal 1, mail.attachments.length
|
||||||
|
assert_equal "hello.rb", mail.attachments.first.original_filename
|
||||||
|
end
|
||||||
|
|
||||||
def test_decode_part_without_content_type
|
def test_decode_part_without_content_type
|
||||||
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email4")
|
fixture = File.read(File.dirname(__FILE__) + "/fixtures/raw_email4")
|
||||||
mail = TMail::Mail.parse(fixture)
|
mail = TMail::Mail.parse(fixture)
|
||||||
|
|
Loading…
Reference in a new issue