Class: Dkim::Header

Inherits:
Struct
  • Object
show all
Includes:
Canonicalizable
Defined in:
lib/dkim/header.rb

Direct Known Subclasses

DkimHeader

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Canonicalizable

#to_s

Instance Attribute Details

#keyObject

Returns the value of attribute key

Returns:

  • (Object)

    the current value of key



4
5
6
# File 'lib/dkim/header.rb', line 4

def key
  @key
end

#valueObject

Returns the value of attribute value

Returns:

  • (Object)

    the current value of value



4
5
6
# File 'lib/dkim/header.rb', line 4

def value
  @value
end

Class Method Details

.parse(header_string) ⇒ Object



42
43
44
45
46
47
# File 'lib/dkim/header.rb', line 42

def self.parse header_string
  header_string.split(/\r?\n(?!([ \t]))/).map do |header|
    key, value = header.split(':', 2)
    new(key, value)
  end
end

Instance Method Details

#canonical_relaxedObject



35
36
37
# File 'lib/dkim/header.rb', line 35

def canonical_relaxed
  "#{relaxed_key}:#{relaxed_value}"
end

#canonical_simpleObject



38
39
40
# File 'lib/dkim/header.rb', line 38

def canonical_simple
  "#{key}:#{value}"
end

#relaxed_keyObject



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/dkim/header.rb', line 7

def relaxed_key
  key = self.key.dup

  #Convert all header field names (not the header field values) to lowercase.  For example, convert "SUBJect: AbC" to "subject: AbC".
  key.downcase!

  # Delete any WSP characters remaining before the colon separating the header field name from the header field value.
  key.gsub!(/[ \t]*\z/, '')

  key
end

#relaxed_valueObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/dkim/header.rb', line 18

def relaxed_value
  value  = self.value.dup

  # Unfold all header field continuation lines as described in [RFC2822]
  value.gsub!(/\r?\n[ \t]+/, ' ')

  # Convert all sequences of one or more WSP characters to a single SP character.
  value.gsub!(/[ \t]+/, ' ')

  # Delete all WSP characters at the end of each unfolded header field value.
  value.gsub!(/[ \t]*\z/, '')
  
  # Delete any WSP characters remaining after the colon separating the header field name from the header field value.
  value.gsub!(/\A[ \t]*/, '')

  value
end