Class: Mail::UnstructuredField

Inherits:
CommonField show all
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

NamedUnstructuredField, OptionalField

Instance Attribute Summary

Attributes inherited from CommonField

#charset, #errors, #name, #value

Instance Method Summary collapse

Methods inherited from CommonField

#decoded, #default, #element, #encoded, parse, #responsible_for?, singular?, #singular?, #to_s

Constructor Details

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

:nodoc:



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/mail/fields/unstructured_field.rb', line 20

def initialize(name, value, charset = nil)
  if value.is_a?(Array)
    # Probably has arrived here from a failed parse of an AddressList Field
    value = value.join(', ')

  # Mark UTF-8 strings parsed from ASCII-8BIT
  elsif 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

  charset ||=
    if value.respond_to?(:encoding)
      value.encoding
    end

  super name, value.to_s, charset
end

Instance Method Details

#parseObject

An unstructured field does not parse



40
41
42
# File 'lib/mail/fields/unstructured_field.rb', line 40

def parse
  self
end