Class: Mail::UnstructuredField

Inherits:
Object
  • Object
show all
Includes:
CommonField, Utilities
Defined in:
lib/mail/fields/unstructured_field.rb

Overview

Provides access to an unstructured header field

Per RFC 2822:

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).

Constant Summary

Constant Summary

Constants included from Constants

Constants::ASTERISK, Constants::ATOM_UNSAFE, Constants::B_VALUES, Constants::CAPITAL_M, Constants::COLON, Constants::CONTROL_CHAR, Constants::CR, Constants::CRLF, Constants::CR_ENCODED, Constants::EMPTY, Constants::ENCODED_VALUE, Constants::EQUAL_LF, Constants::FIELD_BODY, Constants::FIELD_LINE, Constants::FIELD_NAME, Constants::FIELD_PREFIX, Constants::FIELD_SPLIT, Constants::FWS, Constants::HEADER_LINE, Constants::HEADER_SPLIT, Constants::HYPHEN, Constants::LF, Constants::LF_ENCODED, Constants::NULL_SENDER, Constants::PHRASE_UNSAFE, Constants::QP_SAFE, Constants::QP_UNSAFE, Constants::Q_VALUES, Constants::SPACE, Constants::TEXT, Constants::TOKEN_UNSAFE, Constants::UNDERSCORE, Constants::WSP

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utilities

#atom_safe?, #bracket, #capitalize_field, #constantize, #dasherize, #dquote, #escape_paren, #map_lines, #map_with_index, #match_to_s, #paren, #quote_atom, #quote_phrase, #quote_token, #token_safe?, #unbracket, #underscoreize, #unparen, #unquote, #uri_escape, #uri_parser, #uri_unescape

Methods included from CommonField

#field_length, #name, #name=, #responsible_for?, #to_s, #value, #value=

Constructor Details

#initialize(name, value, charset = nil) ⇒ UnstructuredField

Returns a new instance of UnstructuredField



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/mail/fields/unstructured_field.rb', line 25

def initialize(name, value, charset = nil)
  @errors = []

  if value.is_a?(Array)
    # Probably has arrived here from a failed parse of an AddressList Field
    value = value.join(', ')
  else
    # Ensure we are dealing with a string
    value = value.to_s
  end

  if charset
    self.charset = charset
  else
    if value.respond_to?(:encoding)
      self.charset = value.encoding
    else
      self.charset = $KCODE
    end
  end
  self.name = name
  self.value = value
  self
end

Instance Attribute Details

#charsetObject

Returns the value of attribute charset



22
23
24
# File 'lib/mail/fields/unstructured_field.rb', line 22

def charset
  @charset
end

#errorsObject (readonly)

Returns the value of attribute errors



23
24
25
# File 'lib/mail/fields/unstructured_field.rb', line 23

def errors
  @errors
end

Instance Method Details

#decodedObject



54
55
56
# File 'lib/mail/fields/unstructured_field.rb', line 54

def decoded
  do_decode
end

#defaultObject



58
59
60
# File 'lib/mail/fields/unstructured_field.rb', line 58

def default
  decoded
end

#encodedObject



50
51
52
# File 'lib/mail/fields/unstructured_field.rb', line 50

def encoded
  do_encode
end

#parseObject

An unstructured field does not parse



62
63
64
# File 'lib/mail/fields/unstructured_field.rb', line 62

def parse # An unstructured field does not parse
  self
end