Sha256: c68e1a7b15328e84ecdfbd3a4d97535eb3dc0a4e403419e0f94e888d4995c550

Contents?: true

Size: 1.13 KB

Versions: 10

Compression:

Stored size: 1.13 KB

Contents

# encoding: utf-8
# 
# 
# 
module Mail
  class ContentDispositionField < StructuredField
    
    FIELD_NAME = 'content-disposition'
    CAPITALIZED_FIELD = 'Content-Disposition'
    
    def initialize(*args)
      super(CAPITALIZED_FIELD, strip_field(FIELD_NAME, args.last))
      self.parse
      self

    end
    
    def parse(val = value)
      unless val.blank?
        @element = Mail::ContentDispositionElement.new(val)
      end
    end
    
    def element
      @element ||= Mail::ContentDispositionElement.new(value)
    end

    def disposition_type
      element.disposition_type
    end
    
    def parameters
      @parameters = ParameterHash.new
      element.parameters.each { |p| @parameters.merge!(p) }
      @parameters
    end

    def filename
      case
      when !parameters['filename'].blank?
        @filename = parameters['filename']
      when !parameters['name'].blank?
        @filename = parameters['name']
      else 
        @filename = nil
      end
      @filename
    end

    # TODO: Fix this up
    def encoded
      "#{CAPITALIZED_FIELD}: #{value}\r\n"
    end
    
    def decoded
      value
    end

  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
mail-2.1.3 lib/mail/fields/content_disposition_field.rb
kbaum-mail-2.1.2.1 lib/mail/fields/content_disposition_field.rb
mail-2.1.2 lib/mail/fields/content_disposition_field.rb
mail-2.1.1 lib/mail/fields/content_disposition_field.rb
mail-2.1.0 lib/mail/fields/content_disposition_field.rb
mail-2.0.5 lib/mail/fields/content_disposition_field.rb
mail-2.0.3 lib/mail/fields/content_disposition_field.rb
mail-1.6.0 lib/mail/fields/content_disposition_field.rb
mail-1.5.4 lib/mail/fields/content_disposition_field.rb
mail-1.5.3 lib/mail/fields/content_disposition_field.rb