Class: MailerToGo::SPF::Sender

Inherits:
Object
  • Object
show all
Defined in:
lib/mailertogo/spf/sender.rb

Overview

The sender you are asking about: "which names in a customer's SPF record mean me?"

It is deliberately a set, not a single string. A sending service usually publishes a chain — an outer alias that customers are told to include, and a leaf that actually lists the addresses:

mailertogo.net       TXT  v=spf1 include:_spf.mailertogo.net ~all
_spf.mailertogo.net  TXT  v=spf1 ip4:… ip4:… ~all

A customer who publishes include:mailertogo.net is authorised just as surely as one who publishes include:_spf.mailertogo.net; both must count, or you report a false failure against a domain that passes at every real receiver. Staging/regional spellings of the same zone belong here too.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(include_name, aliases: []) ⇒ Sender

include_name — the mechanism you tell customers to publish. aliases — any other name that is equally you (outer alias, staging zone, a legacy name you still honour).

Raises:

  • (ArgumentError)


27
28
29
30
31
32
33
34
35
36
# File 'lib/mailertogo/spf/sender.rb', line 27

def initialize(include_name, aliases: [])
  @include_name = Record.normalize_name(include_name)
  raise ArgumentError, "include name is required" if @include_name.empty?

  @names = ([@include_name] + Array(aliases).map { |n| Record.normalize_name(n) })
           .reject(&:empty?)
           .uniq
           .freeze
  freeze
end

Instance Attribute Details

#include_nameObject (readonly)

Returns the value of attribute include_name.



22
23
24
# File 'lib/mailertogo/spf/sender.rb', line 22

def include_name
  @include_name
end

#namesObject (readonly)

Returns the value of attribute names.



22
23
24
# File 'lib/mailertogo/spf/sender.rb', line 22

def names
  @names
end

Instance Method Details

#covers?(name) ⇒ Boolean

Does this name in someone's record mean us?

Returns:

  • (Boolean)


39
40
41
# File 'lib/mailertogo/spf/sender.rb', line 39

def covers?(name)
  names.include?(Record.normalize_name(name))
end

#record(all: "~all") ⇒ Object

The standalone record a domain with no SPF of its own should publish.



44
45
46
# File 'lib/mailertogo/spf/sender.rb', line 44

def record(all: "~all")
  "v=spf1 include:#{include_name} #{all}"
end

#to_sObject



48
49
50
# File 'lib/mailertogo/spf/sender.rb', line 48

def to_s
  include_name
end