Class: RMail::Header::Field

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

Overview

:nodoc:

Constant Summary collapse

EXTRACT_FIELD_NAME_RE =

accoring to RFC2822 the header field name can consist of any ASCII char between and including 33 and 126.

/\A(^\w[-\w]+):\s*/o

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.


92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/rmail/header.rb', line 92

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.


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

def name
  @name
end

#rawObject (readonly)

Returns the value of attribute raw.


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

def raw
  @raw
end

#valueObject (readonly)

Returns the value of attribute value.


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

def value
  @value
end

Class Method Details

.name_canonicalize(name) ⇒ Object


113
114
115
# File 'lib/rmail/header.rb', line 113

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

.parse(field) ⇒ Object


82
83
84
85
86
87
88
89
# File 'lib/rmail/header.rb', line 82

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


107
108
109
110
111
# File 'lib/rmail/header.rb', line 107

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