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

Constants included from Utilities

Mail::Utilities::CRLF, Mail::Utilities::LF, Mail::Utilities::TO_CRLF_REGEX

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::FULL_ENCODED_VALUE, 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?, binary_unsafe_to_crlf, binary_unsafe_to_lf, blank?, #bracket, #capitalize_field, #constantize, #dasherize, #dquote, #escape_paren, #map_lines, #map_with_index, #match_to_s, #paren, #quote_atom, #quote_phrase, #quote_token, safe_for_line_ending_conversion?, to_crlf, to_lf, #token_safe?, #unbracket, #underscoreize, unescape, #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.


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

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

    # Mark UTF-8 strings parsed from ASCII-8BIT
    if value.respond_to?(:force_encoding) && value.encoding == Encoding::ASCII_8BIT
      utf8 = value.dup.force_encoding(Encoding::UTF_8)
      value = utf8 if utf8.valid_encoding?
    end
  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


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

def charset
  @charset
end

#errorsObject (readonly)

Returns the value of attribute errors


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

def errors
  @errors
end

Instance Method Details

#decodedObject


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

def decoded
  do_decode
end

#defaultObject


65
66
67
# File 'lib/mail/fields/unstructured_field.rb', line 65

def default
  decoded
end

#encodedObject


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

def encoded
  do_encode
end

#parseObject

An unstructured field does not parse


69
70
71
# File 'lib/mail/fields/unstructured_field.rb', line 69

def parse # An unstructured field does not parse
  self
end