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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
# encoding: utf-8
# frozen_string_literal: true
require 'mail/fields/named_structured_field'
require 'mail/fields/parameter_hash'
module Mail
class ContentDispositionField < NamedStructuredField #:nodoc:
NAME = 'Content-Disposition'
def self.singular?
true
end
def initialize(value = nil, charset = nil)
super ensure_filename_quoted(value), charset
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) } unless element.parameters.nil?
@parameters
end
def filename
@filename ||= parameters['filename'] || parameters['name']
end
def encoded
p = ";\r\n\s#{parameters.encoded}" if parameters.length > 0
"#{name}: #{disposition_type}#{p}\r\n"
end
def decoded
p = "; #{parameters.decoded}" if parameters.length > 0
"#{disposition_type}#{p}"
end
end
end
|