aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer/lib/action_mailer/vendor/tmail/attachments.rb
diff options
context:
space:
mode:
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