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.
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/mail/fields/content_type_field.rb', line 22
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
106
107
108
109
110
111
112
113
|
# File 'lib/mail/fields/content_type_field.rb', line 106
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
17
18
19
|
# File 'lib/mail/fields/content_type_field.rb', line 17
def generate_boundary
"--==_mimepart_#{Mail.random_tag}"
end
|
.singular? ⇒ Boolean
9
10
11
|
# File 'lib/mail/fields/content_type_field.rb', line 9
def singular?
true
end
|
.with_boundary(type) ⇒ Object
13
14
15
|
# File 'lib/mail/fields/content_type_field.rb', line 13
def with_boundary(type)
new "#{type}; boundary=#{generate_boundary}"
end
|
Instance Method Details
#attempt_to_clean ⇒ Object
#decoded ⇒ Object
99
100
101
102
|
# File 'lib/mail/fields/content_type_field.rb', line 99
def decoded
p = "; #{parameters.decoded}" if parameters && parameters.length > 0
"#{content_type}#{p}"
end
|
#default ⇒ Object
66
67
68
|
# File 'lib/mail/fields/content_type_field.rb', line 66
def default
decoded
end
|
#encoded ⇒ Object
94
95
96
97
|
# File 'lib/mail/fields/content_type_field.rb', line 94
def encoded
p = ";\r\n\s#{parameters.encoded}" if parameters && parameters.length > 0
"#{name}: #{content_type}#{p}\r\n"
end
|
#filename ⇒ Object
90
91
92
|
# File 'lib/mail/fields/content_type_field.rb', line 90
def filename
@filename ||= parameters['filename'] || parameters['name']
end
|
#main_type ⇒ Object
53
54
55
|
# File 'lib/mail/fields/content_type_field.rb', line 53
def main_type
@main_type ||= element.main_type
end
|
#parameters ⇒ Object
70
71
72
73
74
75
76
|
# File 'lib/mail/fields/content_type_field.rb', line 70
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
61
62
63
|
# File 'lib/mail/fields/content_type_field.rb', line 61
def string
"#{main_type}/#{sub_type}"
end
|
#stringify(params) ⇒ Object
86
87
88
|
# File 'lib/mail/fields/content_type_field.rb', line 86
def stringify(params)
params.map { |k,v| "#{k}=#{Encodings.param_encode(v)}" }.join("; ")
end
|
#sub_type ⇒ Object
57
58
59
|
# File 'lib/mail/fields/content_type_field.rb', line 57
def sub_type
@sub_type ||= element.sub_type
end
|
#value ⇒ Object
78
79
80
81
82
83
84
|
# File 'lib/mail/fields/content_type_field.rb', line 78
def value
if @value.is_a? Array
"#{@main_type}/#{@sub_type}; #{stringify(parameters)}"
else
@value
end
end
|