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

Direct Known Subclasses

CommentsField, ContentDescriptionField, OptionalField, SubjectField

Constant Summary

Constant Summary

Constants included from Patterns

Patterns::ATOM_UNSAFE, Patterns::CONTROL_CHAR, Patterns::CRLF, Patterns::FIELD_BODY, Patterns::FIELD_LINE, Patterns::FIELD_NAME, Patterns::FIELD_PREFIX, Patterns::FIELD_SPLIT, Patterns::FWS, Patterns::HEADER_LINE, Patterns::HEADER_SPLIT, Patterns::PHRASE_UNSAFE, Patterns::QP_SAFE, Patterns::QP_UNSAFE, Patterns::TEXT, Patterns::TOKEN_UNSAFE, Patterns::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

- (UnstructuredField) initialize(name, value, charset = nil)

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

- (Object) charset

Returns the value of attribute charset



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

def charset
  @charset
end

- (Object) errors (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

- (Object) decoded



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

def decoded
  do_decode
end

- (Object) default



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

def default
  decoded
end

- (Object) encoded



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

def encoded
  do_encode
end

- (Object) parse

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