aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer/lib/action_mailer/vendor/tmail/attachments.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-03-18 16:03:29 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-03-18 16:03:29 +0000
commit38591db14ff43540cfc039d8fa9aa0001a8de7b8 (patch)
treeb2d9620bd7841eae6ee56c58f61d835611ec3541 /actionmailer/lib/action_mailer/vendor/tmail/attachments.rb
parent060b9b16aa4104858c13e4fd467b05c8e4fda127 (diff)
downloadrails-38591db14ff43540cfc039d8fa9aa0001a8de7b8.tar.gz
rails-38591db14ff43540cfc039d8fa9aa0001a8de7b8.tar.bz2
rails-38591db14ff43540cfc039d8fa9aa0001a8de7b8.zip
Added better quoting and attachments handling in anticipation for ActionMailer::Receiver framework
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@916 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionmailer/lib/action_mailer/vendor/tmail/attachments.rb')
-rw-r--r--actionmailer/lib/action_mailer/vendor/tmail/attachments.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/actionmailer/lib/action_mailer/vendor/tmail/attachments.rb b/actionmailer/lib/action_mailer/vendor/tmail/attachments.rb
new file mode 100644
index 0000000000..fb6629d67e
--- /dev/null
+++ b/actionmailer/lib/action_mailer/vendor/tmail/attachments.rb
@@ -0,0 +1,25 @@
+require 'stringio'
+
+module TMail
+ class Attachment < StringIO
+ attr_accessor :original_filename, :content_type
+ end
+
+ class Mail
+ def has_attachments?
+ multipart? && parts.any? { |part| part.header["content-type"].main_type != "text" }
+ end
+
+ def attachments
+ if multipart?
+ parts.collect { |part|
+ if part.header["content-type"].main_type != "text"
+ attachment = Attachment.new(Base64.decode64(part.body))
+ attachment.original_filename = part.header["content-type"].params["name"].strip.dup
+ attachment
+ end
+ }.compact
+ end
+ end
+ end
+end \ No newline at end of file