aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer/lib/action_mailer/vendor/tmail/attachments.rb
blob: fb6629d67ea1ecfa7a63c6efa9f2d87fb1aa7037 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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