Sha256: 9ffc2d59d3c0ae9eabce1ac2961889dda179379391b20480011cb8bcaab79664

Contents?: true

Size: 1.18 KB

Versions: 89

Compression:

Stored size: 1.18 KB

Contents

=begin rdoc

= Attachment handling file

=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.disposition_is_attachment? || part.content_type_is_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

Version data entries

89 entries across 86 versions & 19 rubygems

Version Path
bjornblomqvist-tmail-0.0.1 lib/tmail/attachments.rb
bjornblomqvist-tmail-0.0.2 lib/tmail/attachments.rb
kennethkalmer-daemon-kit-0.1.7.10 vendor/tmail-1.2.3/tmail/attachments.rb
kennethkalmer-daemon-kit-0.1.7.4 vendor/tmail-1.2.3/tmail/attachments.rb
kennethkalmer-daemon-kit-0.1.7.5 vendor/tmail-1.2.3/tmail/attachments.rb
kennethkalmer-daemon-kit-0.1.7.7 vendor/tmail-1.2.3/tmail/attachments.rb
kennethkalmer-daemon-kit-0.1.7.8 vendor/tmail-1.2.3/tmail/attachments.rb
kennethkalmer-daemon-kit-0.1.7.9 vendor/tmail-1.2.3/tmail/attachments.rb
queso-daemon-kit-0.1.7.10 vendor/tmail-1.2.3/tmail/attachments.rb
skaar-daemon-kit-0.1.7.10 vendor/tmail-1.2.3/tmail/attachments.rb
actionmailer_csi-2.3.5.p8 lib/action_mailer/vendor/tmail-1.2.3/tmail/attachments.rb
actionmailer_csi-2.3.5.p7 lib/action_mailer/vendor/tmail-1.2.3/tmail/attachments.rb
actionmailer_csi-2.3.5.20130130071128 lib/action_mailer/vendor/tmail-1.2.3/tmail/attachments.rb
actionmailer_csi-2.3.5.p6 lib/action_mailer/vendor/tmail-1.2.3/tmail/attachments.rb
webroar-0.5.0 src/admin_panel/vendor/rails/actionmailer/lib/action_mailer/vendor/tmail-1.2.3/tmail/attachments.rb
radiantcms-couchrest_model-0.2.4 vendor/rails/actionmailer/lib/action_mailer/vendor/tmail-1.2.3/tmail/attachments.rb
radiantcms-couchrest_model-0.2.2 vendor/rails/actionmailer/lib/action_mailer/vendor/tmail-1.2.3/tmail/attachments.rb
radiantcms-couchrest_model-0.2.1 vendor/rails/actionmailer/lib/action_mailer/vendor/tmail-1.2.3/tmail/attachments.rb
radiantcms-couchrest_model-0.2 vendor/rails/actionmailer/lib/action_mailer/vendor/tmail-1.2.3/tmail/attachments.rb
radiantcms-couchrest_model-0.1.9 vendor/rails/actionmailer/lib/action_mailer/vendor/tmail-1.2.3/tmail/attachments.rb