Class: SPF::Record::V2

Inherits:
SPF::Record show all
Defined in:
lib/spf/model.rb

Constant Summary collapse

MECH_CLASSES =
{
  :all      => SPF::Mech::All,
  :ip4      => SPF::Mech::IP4,
  :ip6      => SPF::Mech::IP6,
  :a        => SPF::Mech::A,
  :mx       => SPF::Mech::MX,
  :ptr      => SPF::Mech::PTR,
  :exists   => SPF::Mech::Exists,
  :include  => SPF::Mech::Include
}
MOD_CLASSES =
{
  :redirect => SPF::Mod::Redirect,
  :exp      => SPF::Mod::Exp
}
VALID_SCOPE =
/^(?: mfrom | pra )$/x

Constants inherited from SPF::Record

DEFAULT_QUALIFIER, RESULTS_BY_QUALIFIER

Instance Attribute Summary

Attributes inherited from SPF::Record

#errors, #terms, #text

Instance Method Summary collapse

Methods inherited from SPF::Record

#eval, #global_mod, #global_mods, #ip_netblocks, new_from_string, #parse, #parse_term, #to_s

Constructor Details

#initialize(options = {}) ⇒ V2

Returns a new instance of V2.



1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
# File 'lib/spf/model.rb', line 1020

def initialize(options = {})
  super(options)
  unless @parse_text
    scopes = @scopes || {}
    raise SPF::InvalidScopeError.new('No scopes for spf2.0 record') if scopes.empty?
    scopes.each do |scope|
      if scope !~ VALID_SCOPE
        raise SPF::InvalidScopeError.new("Invalid scope '#{scope}' for spf2.0 record")
      end
    end
  end
end

Instance Method Details

#mech_classesObject



1016
1017
1018
# File 'lib/spf/model.rb', line 1016

def mech_classes
  MECH_CLASSES
end

#parse_version_tagObject



1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
# File 'lib/spf/model.rb', line 1038

def parse_version_tag

  @parse_text.sub!(/#{version_tag_pattern}(?:\x20+|$)/ix, '')
  if $1
    scopes = @scopes = "#{$2}".split(/,/)
    if scopes.empty?
      raise SPF::InvalidScopeError.new('No scopes for spf2.0 record')
    end
    scopes.each do |scope|
      if scope !~ VALID_SCOPE
        raise SPF::InvalidScopeError.new("Invalid scope '#{scope}' for spf2.0 record")
      end
    end
  else
    raise SPF::InvalidRecordVersionError.new(
      "Not a 'spf2.0' record: '#{@text}'")
  end
end

#version_tagObject



1003
1004
1005
# File 'lib/spf/model.rb', line 1003

def version_tag
  'v=spf2.0'
end

#version_tag_patternObject



1007
1008
1009
1010
1011
1012
1013
1014
# File 'lib/spf/model.rb', line 1007

def version_tag_pattern
"
  spf(2\.0)
  \/
  ( (?: mfrom | pra ) (?: , (?: mfrom | pra ) )* )
  (?= \\x20 | $ )
"
end