class DMARC::Record
Attributes
‘p` field.
@return [:none, :quarantine, :reject]
‘rua` field.
@return [Array<Uri>]
‘rua` field.
@return [Array<Uri>]
‘sp` field.
@return [:none, :quarantine, :reject]
‘v` field.
@return [:DMARC1]
Public Class Methods
@deprecated use {parse} instead.
# File lib/dmarc/record.rb, line 282 def self.from_txt(rec) parse(rec) end
Initializes the record.
@param [Hash{Symbol => Object}] attributes
Attributes for the record.
@option attributes [:r, :s] :adkim (:r)
@option attributes [:r, :s] :aspf (:r)
@option attributes [Array<‘0’, ‘1’, ‘d’, ‘s’>] :fo (‘0’)
@option attributes [:none, :quarantine, :reject] :p
@option attributes [Integer] :pct (100)
@option attributes [:afrf, :iodef] :rf (:afrf)
@option attributes [Integer] :ri (86400)
@option attributes [Array<Uri>] :rua
@option attributes [Array<Uri>] :ruf
@option attributes [:none, :quarantine, :reject] :sp
@option attributes [:DMARC1] :v
# File lib/dmarc/record.rb, line 63 def initialize(attributes={}) @v = attributes.fetch(:v) @adkim = attributes[:adkim] @aspf = attributes[:aspf] @fo = attributes[:fo] @p = attributes[:p] @pct = attributes[:pct] @rf = attributes[:rf] @ri = attributes[:ri] @rua = attributes[:rua] @ruf = attributes[:ruf] @sp = attributes[:sp] end
Parses a DMARC
record.
@param [String] record
The raw DMARC record.
@return [Record]
The parsed DMARC record.
@raise [InvalidRecord]
The DMARC record could not be parsed.
@since 0.3.0
@api public
# File lib/dmarc/record.rb, line 273 def self.parse(record) new(Parser.parse(record)) rescue Parslet::ParseFailed => error raise(InvalidRecord.new(error.message,error.cause)) end
Queries and parses the DMARC
record for a domain.
@param [String] domain
The domain to query DMARC for.
@param [Resolv::DNS] resolver
The resolver to use.
@return [Record, nil]
The parsed DMARC record. If no DMARC record was found, `nil` will be returned.
@raise [InvalidRecord]
The DMARC record could not be parsed.
@since 0.3.0
@api public
# File lib/dmarc/record.rb, line 306 def self.query(domain,resolver=Resolv::DNS.new) if (dmarc = DMARC.query(domain,resolver)) parse(dmarc) end end
Public Instance Methods
‘adkim=` field.
@return [:r, :s]
The value of the `adkim=` field, or `:r` if the field was omitted.
# File lib/dmarc/record.rb, line 115 def adkim @adkim || :r end
Determines whether the ‘adkim=` field was specified.
@return [Boolean]
@since 0.4.0
# File lib/dmarc/record.rb, line 105 def adkim? !@adkim.nil? end
‘aspf` field.
@return [:r, :s]
The value of the `aspf=` field, or `:r` if the field was omitted.
# File lib/dmarc/record.rb, line 136 def aspf @aspf || :r end
Determines whether the ‘aspf=` field was specified.
@return [Boolean]
@since 0.4.0
# File lib/dmarc/record.rb, line 126 def aspf? !@aspf.nil? end
‘fo` field.
@return [Array<‘0’, ‘1’, ‘d’, ‘s’>]
The value of the `fo=` field, or `["0"]` if the field was omitted.
# File lib/dmarc/record.rb, line 157 def fo @fo || %w[0] end
Determines whether the ‘fo=` field was specified.
@return [Boolean]
@since 0.4.0
# File lib/dmarc/record.rb, line 147 def fo? !@fo.nil? end
Determines if the ‘p=` field was specified?
@return [Boolean]
@since 0.4.0
# File lib/dmarc/record.rb, line 168 def p? !@p.nil? end
‘pct` field.
@return [Integer]
The value of the `pct=` field, or `100` if the field was omitted.
# File lib/dmarc/record.rb, line 189 def pct @pct || 100 end
Determines whether the ‘pct=` field was specified.
@return [Boolean]
@since 0.4.0
# File lib/dmarc/record.rb, line 179 def pct? !@pct.nil? end
‘rf` field.
@return [:afrf, :iodef]
The value of the `rf=` field, or `:afrf` if the field was omitted.
# File lib/dmarc/record.rb, line 210 def rf @rf || :afrf end
Determines whether the ‘rf=` field was specified.
@return [Boolean]
@since 0.4.0
# File lib/dmarc/record.rb, line 200 def rf? !@rf.nil? end
‘ri` field.
@return [Integer]
The value of the `ri=` field, or `86400` if the field was omitted.
# File lib/dmarc/record.rb, line 231 def ri @ri || 86400 end
Determines whether the ‘ri=` field was specified.
@return [Boolean]
@since 0.4.0
# File lib/dmarc/record.rb, line 221 def ri? !@ri.nil? end
Determines if the ‘rua=` field was specified?
@return [Boolean]
@since 0.4.0
# File lib/dmarc/record.rb, line 242 def rua? !@rua.nil? end
Determines if the ‘ruf=` field was specified?
@return [Boolean]
@since 0.4.0
# File lib/dmarc/record.rb, line 253 def ruf? !@ruf.nil? end
Determines if the ‘sp=` field was specified?
@return [Boolean]
@since 0.4.0
# File lib/dmarc/record.rb, line 84 def sp? !@sp.nil? end
Converts the record to a Hash.
@return [Hash{Symbol => Object}]
@since 0.4.0
# File lib/dmarc/record.rb, line 319 def to_h hash = {} hash[:v] = @v if @v hash[:p] = @p if @p hash[:sp] = @sp if @sp hash[:rua] = @rua if @rua hash[:ruf] = @ruf if @ruf hash[:adkim] = @adkim if @adkim hash[:aspf] = @aspf if @aspf hash[:ri] = @ri if @ri hash[:fo] = @fo if @fo hash[:rf] = @rf if @rf hash[:pct] = @pct if @pct return hash end
Converts the record back to a DMARC
String.
@return [String]
# File lib/dmarc/record.rb, line 342 def to_s tags = [] tags << "v=#{@v}" if @v tags << "p=#{@p}" if @p tags << "sp=#{@sp}" if @sp tags << "rua=#{@rua.join(',')}" if @rua tags << "ruf=#{@ruf.join(',')}" if @ruf tags << "adkim=#{@adkim}" if @adkim tags << "aspf=#{@aspf}" if @aspf tags << "ri=#{@ri}" if @ri tags << "fo=#{@fo.join(':')}" if @fo tags << "rf=#{@rf}" if @rf tags << "pct=#{@pct}" if @pct return tags.join('; ') end