Froze rails gems
[depot.git] / vendor / rails / actionmailer / lib / action_mailer / vendor / tmail-1.2.3 / tmail / attachments.rb
1 =begin rdoc
2
3 = Attachment handling file
4
5 =end
6
7 require 'stringio'
8
9 module TMail
10 class Attachment < StringIO
11 attr_accessor :original_filename, :content_type
12 end
13
14 class Mail
15 def has_attachments?
16 multipart? && parts.any? { |part| attachment?(part) }
17 end
18
19 def attachment?(part)
20 part.disposition_is_attachment? || part.content_type_is_text?
21 end
22
23 def attachments
24 if multipart?
25 parts.collect { |part|
26 if part.multipart?
27 part.attachments
28 elsif attachment?(part)
29 content = part.body # unquoted automatically by TMail#body
30 file_name = (part['content-location'] &&
31 part['content-location'].body) ||
32 part.sub_header("content-type", "name") ||
33 part.sub_header("content-disposition", "filename")
34
35 next if file_name.blank? || content.blank?
36
37 attachment = Attachment.new(content)
38 attachment.original_filename = file_name.strip
39 attachment.content_type = part.content_type
40 attachment
41 end
42 }.flatten.compact
43 end
44 end
45 end
46 end