Sha256: 66dda873321cc6bdca1c42a2af43fa6b41d6791cfc4a4bb1dc0016e4aa8745b3

Contents?: true

Size: 1.2 KB

Versions: 4

Compression:

Stored size: 1.2 KB

Contents

require 'dkim/canonicalizable'

module Dkim
  class Header < Struct.new(:key, :value)
    include Canonicalizable

    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
    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
    def canonical_relaxed
      "#{relaxed_key}:#{relaxed_value}"
    end
    def canonical_simple
      "#{key}:#{value}"
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dkim-0.2.0 lib/dkim/header.rb
dkim-0.1.0 lib/dkim/header.rb
dkim-0.0.3 lib/dkim/header.rb
dkim-0.0.2 lib/dkim/header.rb