Class: Mail::ContentTypeField
Overview
Constant Summary
collapse
- NAME =
'Content-Type'
Instance Attribute Summary
Attributes inherited from CommonField
#charset, #errors, #name
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from CommonField
parse, #parse, #responsible_for?, #singular?, #to_s
Constructor Details
#initialize(value = nil, charset = nil) ⇒ ContentTypeField
Returns a new instance of ContentTypeField.
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/mail/fields/content_type_field.rb', line 24
def initialize(value = nil, charset = nil)
if value.is_a? Array
@main_type = value[0]
@sub_type = value[1]
@parameters = ParameterHash.new.merge!(value.last)
else
@main_type = nil
@sub_type = nil
value = value.to_s
end
super ensure_filename_quoted(value), charset
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
108
109
110
111
112
113
114
115
|
# File 'lib/mail/fields/content_type_field.rb', line 108
def method_missing(name, *args, &block)
if name.to_s =~ /(\w+)=/
self.parameters[$1] = args.first
@value = "#{content_type}; #{stringify(parameters)}"
else
super
end
end
|
Class Method Details
.generate_boundary ⇒ Object
19
20
21
|
# File 'lib/mail/fields/content_type_field.rb', line 19
def generate_boundary
"--==_mimepart_#{Mail.random_tag}"
end
|
.singular? ⇒ Boolean
11
12
13
|
# File 'lib/mail/fields/content_type_field.rb', line 11
def singular?
true
end
|
.with_boundary(type) ⇒ Object
15
16
17
|
# File 'lib/mail/fields/content_type_field.rb', line 15
def with_boundary(type)
new "#{type}; boundary=#{generate_boundary}"
end
|
Instance Method Details
#attempt_to_clean ⇒ Object
#decoded ⇒ Object
101
102
103
104
|
# File 'lib/mail/fields/content_type_field.rb', line 101
def decoded
p = "; #{parameters.decoded}" if parameters && parameters.length > 0
"#{content_type}#{p}"
end
|
#default ⇒ Object
68
69
70
|
# File 'lib/mail/fields/content_type_field.rb', line 68
def default
decoded
end
|
#encoded ⇒ Object
96
97
98
99
|
# File 'lib/mail/fields/content_type_field.rb', line 96
def encoded
p = ";\r\n\s#{parameters.encoded}" if parameters && parameters.length > 0
"#{name}: #{content_type}#{p}\r\n"
end
|
#filename ⇒ Object
92
93
94
|
# File 'lib/mail/fields/content_type_field.rb', line 92
def filename
@filename ||= parameters['filename'] || parameters['name']
end
|
#main_type ⇒ Object
55
56
57
|
# File 'lib/mail/fields/content_type_field.rb', line 55
def main_type
@main_type ||= element.main_type
end
|
#parameters ⇒ Object
72
73
74
75
76
77
78
|
# File 'lib/mail/fields/content_type_field.rb', line 72
def parameters
unless defined? @parameters
@parameters = ParameterHash.new
element.parameters.each { |p| @parameters.merge!(p) }
end
@parameters
end
|
#string ⇒ Object
Also known as:
content_type
63
64
65
|
# File 'lib/mail/fields/content_type_field.rb', line 63
def string
"#{main_type}/#{sub_type}"
end
|
#stringify(params) ⇒ Object
88
89
90
|
# File 'lib/mail/fields/content_type_field.rb', line 88
def stringify(params)
params.map { |k,v| "#{k}=#{Encodings.param_encode(v)}" }.join("; ")
end
|
#sub_type ⇒ Object
59
60
61
|
# File 'lib/mail/fields/content_type_field.rb', line 59
def sub_type
@sub_type ||= element.sub_type
end
|
#value ⇒ Object
80
81
82
83
84
85
86
|
# File 'lib/mail/fields/content_type_field.rb', line 80
def value
if @value.is_a? Array
"#{@main_type}/#{@sub_type}; #{stringify(parameters)}"
else
@value
end
end
|