lib/spf/model.rb in spf-0.0.51 vs lib/spf/model.rb in spf-0.0.52
- old
+ new
@@ -84,21 +84,22 @@
:: (?: #{HEXWORD_PATTERN} : ){0,5} #{TWO_HEXWORDS_OR_IPV4_ADDRESS_PATTERN} |
# :: | -
::
"
- attr_reader :errors, :ip_netblocks, :ip_address, :ip_network, :ipv4_prefix_length, :ipv6_prefix_length, :domain_spec, :raw_params
+ attr_reader :errors, :ip_netblocks, :ip_address, :ip_network, :ipv4_prefix_length, :ipv6_prefix_length, :domain_spec, :raw_params, :record_domain
def initialize(options = {})
@ip_address = nil
@ip_network = nil
@ipv4_prefix_length = nil
@ipv6_prefix_length = nil
@raw_params = nil
@errors = []
@ip_netblocks = []
@text = options[:text]
+ @record_domain = options[:record_domain]
@raise_exceptions = options.has_key?(:raise_exceptions) ? options[:raise_exceptions] : true
end
def error(exception)
raise exception if @raise_exceptions
@@ -115,10 +116,12 @@
def parse_domain_spec(required = false)
if @parse_text.sub!(/^(#{DOMAIN_SPEC_PATTERN})/x, '')
domain_spec = $1
domain_spec.sub!(/^(.*?)\.?$/, $1)
@domain_spec = SPF::MacroString.new({:text => domain_spec})
+ elsif record_domain
+ @domain_spec = SPF::MacroString.new({:text => record_domain})
elsif required
error(SPF::TermDomainSpecExpectedError.new(
"Missing required domain-spec in '#{@text}'"))
end
end
@@ -842,10 +845,11 @@
@parse_text = (@text = options[:text] if not self.instance_variable_defined?(:@parse_text)).dup
@terms ||= []
@global_mods ||= {}
@errors = []
@ip_netblocks = []
+ @record_domain = options[:record_domain]
@raise_exceptions = options.has_key?(:raise_exceptions) ? options[:raise_exceptions] : true
end
def self.new_from_string(text, options = {})
options[:text] = text
@@ -912,10 +916,14 @@
unless mech_class
exception = SPF::InvalidMechError.new("Unknown mechanism type '#{mech_name}' in '#{self.version_tag}' record")
error(exception)
mech_class = SPF::Mech
end
- term = mech = mech_class.new_from_string(mech_text, {:raise_exceptions => @raise_exceptions})
+ options = {:raise_exceptions => @raise_exceptions}
+ if instance_variable_defined?("@record_domain")
+ options[:record_domain] = @record_domain
+ end
+ term = mech = mech_class.new_from_string(mech_text, options)
term.errors << exception if exception
@ip_netblocks << mech.ip_netblocks if mech.ip_netblocks
@terms << mech
if mech_class == SPF::Mech
raise SPF::InvalidMechError.new("Unknown mechanism type '#{mech_name}' in '#{self.version_tag}' record")