Object
Provides access to an unstructured header field
2.2.1. Unstructured Header Field Bodies
Some field bodies in this standard are defined simply as
"unstructured" (which is specified below as any US-ASCII characters,
except for CR and LF) with no further restrictions. These are
referred to as unstructured field bodies. Semantically, unstructured
field bodies are simply to be treated as a single line of characters
with no further processing (except for header "folding" and
"unfolding" as described in section 2.2.3).
# File lib/mail/fields/unstructured_field.rb, line 22
22: def initialize(name, value, charset = nil)
23: self.charset = charset
24: @errors = []
25: if charset
26: self.charset = charset
27: else
28: if value.to_s.respond_to?(:encoding)
29: self.charset = value.to_s.encoding
30: else
31: self.charset = $KCODE
32: end
33: end
34: self.name = name
35: self.value = value
36: self
37: end
# File lib/mail/fields/unstructured_field.rb, line 39
39: def charset
40: @charset
41: end
# File lib/mail/fields/unstructured_field.rb, line 43
43: def charset=(val)
44: @charset = val
45: end
# File lib/mail/fields/unstructured_field.rb, line 55
55: def decoded
56: do_decode
57: end
# File lib/mail/fields/unstructured_field.rb, line 59
59: def default
60: decoded
61: end
# File lib/mail/fields/unstructured_field.rb, line 51
51: def encoded
52: do_encode(self.name)
53: end
# File lib/mail/fields/unstructured_field.rb, line 73
73: def do_decode
74: value.blank? ? nil : Encodings.decode_encode(value, :decode)
75: end
# File lib/mail/fields/unstructured_field.rb, line 69
69: def do_encode(name)
70: value.nil? ? '' : "#{wrapped_value}\r\n"
71: end
# File lib/mail/fields/unstructured_field.rb, line 166
166: def encode(value)
167: (value.not_ascii_only? ? [value].pack("M").gsub("=\n", '') : value).gsub("\r", "=0D").gsub("\n", "=0A")
168: end
# File lib/mail/fields/unstructured_field.rb, line 170
170: def encoded_word_safify!(value)
171: value.gsub!(/"/, '=22')
172: value.gsub!(/\(/, '=28')
173: value.gsub!(/\)/, '=29')
174: value.gsub!(/\?/, '=3F')
175: value.gsub!(/_/, '=5F')
176: end
6.2. Display of ‘encoded-word’s
When displaying a particular header field that contains multiple 'encoded-word's, any 'linear-white-space' that separates a pair of adjacent 'encoded-word's is ignored. (This is to allow the use of multiple 'encoded-word's to represent long strings of unencoded text, without having to separate 'encoded-word's where spaces occur in the unencoded text.)
# File lib/mail/fields/unstructured_field.rb, line 118
118: def wrap_lines(name, folded_lines)
119: result = []
120: index = 0
121: result[index] = "#{name}: #{folded_lines.shift}"
122: result.concat(folded_lines)
123: result.join("\r\n\s")
124: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.