aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/attachments.rb
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2007-11-07 19:29:21 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2007-11-07 19:29:21 +0000
commit709dc33c927652cc5ffb5758811e036336c95038 (patch)
treecc34c22e3ac0373a9c98c1c1414b14283ccfbb96 /actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/attachments.rb
parent57cde631383a8a0fa8d231ac1ae85ea725e12cd5 (diff)
downloadrails-709dc33c927652cc5ffb5758811e036336c95038.tar.gz
rails-709dc33c927652cc5ffb5758811e036336c95038.tar.bz2
rails-709dc33c927652cc5ffb5758811e036336c95038.zip
Rearrange vendor bundles so gem overrides work correctly.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8112 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/attachments.rb')
-rw-r--r--actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/attachments.rb47
1 files changed, 47 insertions, 0 deletions
diff --git a/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/attachments.rb b/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/attachments.rb
new file mode 100644
index 0000000000..a8b8017cf9
--- /dev/null
+++ b/actionmailer/lib/action_mailer/vendor/tmail-1.1.0/tmail/attachments.rb
@@ -0,0 +1,47 @@
+=begin rdoc
+
+= Attachment handling class
+
+=end
+
+require 'stringio'
+
+module TMail
+ class Attachment < StringIO
+ attr_accessor :original_filename, :content_type
+ end
+
+ class Mail
+ def has_attachments?
+ multipart? && parts.any? { |part| attachment?(part) }
+ end
+
+ def attachment?(part)
+ (part['content-disposition'] && part['content-disposition'].disposition == "attachment") ||
+ part.header['content-type'].main_type != "text"
+ end
+
+ def attachments
+ if multipart?
+ parts.collect { |part|
+ if part.multipart?
+ part.attachments
+ elsif attachment?(part)
+ content = part.body # unquoted automatically by TMail#body
+ file_name = (part['content-location'] &&
+ part['content-location'].body) ||
+ part.sub_header("content-type", "name") ||
+ part.sub_header("content-disposition", "filename")
+
+ next if file_name.blank? || content.blank?
+
+ attachment = Attachment.new(content)
+ attachment.original_filename = file_name.strip
+ attachment.content_type = part.content_type
+ attachment
+ end
+ }.flatten.compact
+ end
+ end
+ end
+end