Parent

Namespace

Included Modules

Class/Module Index [+]

Quicksearch

Mail::Field

Provides a single class to call to create a new structured or unstructured field. Works out per RFC what field of field it is being given and returns the correct field of class back on new.

Per RFC 2822

2.2. Header Fields

   Header fields are lines composed of a field name, followed by a colon
   (":"), followed by a field body, and terminated by CRLF.  A field
   name MUST be composed of printable US-ASCII characters (i.e.,
   characters that have values between 33 and 126, inclusive), except
   colon.  A field body may be composed of any US-ASCII characters,
   except for CR and LF.  However, a field body may contain CRLF when
   used in header "folding" and  "unfolding" as described in section
   2.2.3.  All field bodies MUST conform to the syntax described in
   sections 3 and 4 of this standard.

Public Instance Methods

<=>( other ) click to toggle source
# File lib/mail/field.rb, line 116
def <=>( other )
  self_order = FIELD_ORDER.rindex(self.name.to_s.downcase) || 100
  other_order = FIELD_ORDER.rindex(other.name.to_s.downcase) || 100
  self_order <=> other_order
end
field() click to toggle source
# File lib/mail/field.rb, line 88
def field
  @field
end
field=(value) click to toggle source
# File lib/mail/field.rb, line 84
def field=(value)
  @field = value
end
method_missing(name, *args, &block) click to toggle source
# File lib/mail/field.rb, line 122
def method_missing(name, *args, &block)
  field.send(name, *args, &block)
end
name() click to toggle source
# File lib/mail/field.rb, line 92
def name
  field.name
end
same( other ) click to toggle source
# File lib/mail/field.rb, line 112
def same( other )
  match_to_s(other.name, field.name)
end
to_s() click to toggle source
# File lib/mail/field.rb, line 104
def to_s
  field.to_s
end
update(name, value) click to toggle source
# File lib/mail/field.rb, line 108
def update(name, value)
  create_field(name, value, charset)
end
value() click to toggle source
# File lib/mail/field.rb, line 96
def value
  field.value
end
value=(val) click to toggle source
# File lib/mail/field.rb, line 100
def value=(val)
  create_field(name, val, charset)
end

Public Class Methods

new(name, value = nil, charset = 'utf-8') click to toggle source

Accepts a string:

Field.new("field-name: field data")

Or name, value pair:

Field.new("field-name", "value")

Or a name by itself:

Field.new("field-name")

Note, does not want a terminating carriage return. Returns self appropriately parsed. If value is not a string, then it will be passed through as is, for example, content-type field can accept an array with the type and a hash of parameters:

Field.new('content-type', ['text', 'plain', {:charset => 'UTF-8'}])
# File lib/mail/field.rb, line 70
def initialize(name, value = nil, charset = 'utf-8')
  case
  when name =~ /:/                  # Field.new("field-name: field data")
    charset = value unless value.blank?
    name, value = split(name)
    create_field(name, value, charset)
  when name !~ /:/ && value.blank?  # Field.new("field-name")
    create_field(name, nil, charset)
  else                              # Field.new("field-name", "value")
    create_field(name, value, charset)
  end
  return self
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.