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 25 25: def initialize(name, value, charset = nil) 26: @errors = [] 27: if charset 28: self.charset = charset 29: else 30: if value.to_s.respond_to?(:encoding) 31: self.charset = value.to_s.encoding 32: else 33: self.charset = $KCODE 34: end 35: end 36: self.name = name 37: self.value = value 38: self 39: end
# File lib/mail/fields/unstructured_field.rb, line 45 45: def decoded 46: do_decode 47: end
# File lib/mail/fields/unstructured_field.rb, line 49 49: def default 50: decoded 51: end
# File lib/mail/fields/unstructured_field.rb, line 63 63: def do_decode 64: result = value.blank? ? nil : Encodings.decode_encode(value, :decode) 65: result.encode!(value.encoding || "UTF-8") if RUBY_VERSION >= '1.9' && !result.blank? 66: result 67: end
# File lib/mail/fields/unstructured_field.rb, line 59 59: def do_encode 60: value.nil? ? '' : "#{wrapped_value}\r\n" 61: end
# File lib/mail/fields/unstructured_field.rb, line 167 167: def encode(value) 168: value = [value].pack("M").gsub("=\n", '') 169: value.gsub!(/"/, '=22') 170: value.gsub!(/\(/, '=28') 171: value.gsub!(/\)/, '=29') 172: value.gsub!(/\?/, '=3F') 173: value.gsub!(/_/, '=5F') 174: value.gsub!(/ /, '_') 175: value 176: end
# File lib/mail/fields/unstructured_field.rb, line 178 178: def encode_crlf(value) 179: value.gsub!("\r", '=0D') 180: value.gsub!("\n", '=0A') 181: value 182: end
# File lib/mail/fields/unstructured_field.rb, line 184 184: def normalized_encoding 185: encoding = charset.to_s.upcase.gsub('_', '-') 186: encoding = 'UTF-8' if encoding == 'UTF8' # Ruby 1.8.x and $KCODE == 'u' 187: encoding 188: 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 107 107: def wrap_lines(name, folded_lines) 108: result = ["#{name}: #{folded_lines.shift}"] 109: result.concat(folded_lines) 110: result.join("\r\n\s") 111: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.