Class: RMail::Header::Field

Inherits:
Object
  • Object
show all
Defined in:
lib/rmail/header.rb

Overview

:nodoc:

Constant Summary collapse

EXTRACT_FIELD_NAME_RE =

fixme, document methadology for this (RFC2822)

/\A([^\x00-\x1f\x7f-\xff :]+):\s*/no

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, value = nil) ⇒ Field

Returns a new instance of Field.



89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/rmail/header.rb', line 89

def initialize(name, value = nil)
  if value
    @name = Field.name_strip(name.to_str).freeze
    @value = Field.value_strip(value.to_str).freeze
    @raw = nil
  else
    @raw = name.to_str.freeze
    @name, @value = Field.parse(@raw)
    @name.freeze
    @value.freeze
  end
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



102
103
104
# File 'lib/rmail/header.rb', line 102

def name
  @name
end

#rawObject (readonly)

Returns the value of attribute raw.



102
103
104
# File 'lib/rmail/header.rb', line 102

def raw
  @raw
end

#valueObject (readonly)

Returns the value of attribute value.



102
103
104
# File 'lib/rmail/header.rb', line 102

def value
  @value
end

Class Method Details

.name_canonicalize(name) ⇒ Object



110
111
112
# File 'lib/rmail/header.rb', line 110

def Field.name_canonicalize(name)
  name_strip(name.to_str).downcase
end

.parse(field) ⇒ Object



79
80
81
82
83
84
85
86
# File 'lib/rmail/header.rb', line 79

def parse(field)
  field = field.to_str
  if field =~ EXTRACT_FIELD_NAME_RE
    [ $1, $'.chomp ]
  else
    [ "", Field.value_strip(field) ]
  end
end

Instance Method Details

#==(other) ⇒ Object



104
105
106
107
108
# File 'lib/rmail/header.rb', line 104

def ==(other)
  other.kind_of?(self.class) &&
    @name.downcase == other.name.downcase &&
    @value == other.value
end