Sha256: 2c94e91d72d9d42391bcacb79acfba1993c256b879d9d5bf8130a249a4665cef

Contents?: true

Size: 1.15 KB

Versions: 48

Compression:

Stored size: 1.15 KB

Contents

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['content-disposition'] && part['content-disposition'].disposition == "attachment") ||
      part.header['content-type'].main_type != "text"
    end

    def attachments
      if multipart?
        parts.collect { |part| 
          if 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
        }.compact
      end      
    end
  end
end

Version data entries

48 entries across 48 versions & 5 rubygems

Version Path
jstorimer-deep-test-2.0.0 sample_rails_project/vendor/rails/actionmailer/lib/action_mailer/vendor/tmail/attachments.rb
jstorimer-deep-test-1.4.0 sample_rails_project/vendor/rails/actionmailer/lib/action_mailer/vendor/tmail/attachments.rb
jstorimer-deep-test-1.3.0 sample_rails_project/vendor/rails/actionmailer/lib/action_mailer/vendor/tmail/attachments.rb
jstorimer-deep-test-1.2.0 sample_rails_project/vendor/rails/actionmailer/lib/action_mailer/vendor/tmail/attachments.rb
jstorimer-deep-test-1.1.0 sample_rails_project/vendor/rails/actionmailer/lib/action_mailer/vendor/tmail/attachments.rb
jstorimer-deep-test-1.0.0 sample_rails_project/vendor/rails/actionmailer/lib/action_mailer/vendor/tmail/attachments.rb
jstorimer-deep-test-0.2.0 sample_rails_project/vendor/rails/actionmailer/lib/action_mailer/vendor/tmail/attachments.rb
jstorimer-deep-test-0.1.0 sample_rails_project/vendor/rails/actionmailer/lib/action_mailer/vendor/tmail/attachments.rb
actionmailer-1.2.1 lib/action_mailer/vendor/tmail/attachments.rb
actionmailer-1.2.0 lib/action_mailer/vendor/tmail/attachments.rb
actionmailer-1.2.2 lib/action_mailer/vendor/tmail/attachments.rb
actionmailer-1.2.3 lib/action_mailer/vendor/tmail/attachments.rb
actionmailer-1.2.4 lib/action_mailer/vendor/tmail/attachments.rb
actionmailer-1.3.1 lib/action_mailer/vendor/tmail/attachments.rb
actionmailer-1.3.6 lib/action_mailer/vendor/tmail/attachments.rb
actionmailer-1.3.3 lib/action_mailer/vendor/tmail/attachments.rb
actionmailer-1.3.5 lib/action_mailer/vendor/tmail/attachments.rb
actionmailer-1.3.4 lib/action_mailer/vendor/tmail/attachments.rb
actionmailer-1.2.5 lib/action_mailer/vendor/tmail/attachments.rb
actionmailer-1.3.2 lib/action_mailer/vendor/tmail/attachments.rb