table of contents
Mail::SPF::Mech(3) | User Contributed Perl Documentation | Mail::SPF::Mech(3) |
NAME¶
Mail::SPF::Mech - SPF record mechanism base class
DESCRIPTION¶
An object of class Mail::SPF::Mech represents a mechanism within an SPF record. Mail::SPF::Mech cannot be instantiated directly. Create an instance of a concrete sub-class instead.
Constructors¶
The following constructors are provided:
- new(%options): returns Mail::SPF::Mech
- Abstract. Creates a new SPF record mechanism object.
%options is a list of key/value pairs representing any of the following options:
- text
- A string denoting the unparsed text of the mechanism.
- qualifier
- A single-character string denoting the qualifier of the mechanism. Any of the following may be specified: '+' ("Pass"), '-' ("Fail"), '~' ("SoftFail"), '?' ("Neutral"). See RFC 4408, 4.6.2 and 2.5, for their meanings. Defaults to '+'.
- name
- A string denoting the name of the mechanism. Required if a generic Mail::SPF::Mech object (as opposed to a specific sub-class) is being constructed.
- ip_network
- A NetAddr::IP object denoting an optional IP address network parameter of the mechanism. Can be either an IPv4 or an IPv6 address, with an optional network prefix length. IPv4-mapped IPv6 addresses (e.g. '::ffff:192.168.0.1') must not be specified directly, but as plain IPv4 addresses.
- domain_spec
- Either a plain string or a Mail::SPF::MacroString object denoting an optional "domain-spec" parameter of the mechanism.
- ipv4_prefix_length
- ipv6_prefix_length
- A string denoting an optional IPv4 or IPv6 network prefix length for the "domain_spec" of the mechanism. Note that these options do not apply to the "ip_network" option, which already includes an optional network prefix length.
Other options may be specified by sub-classes of Mail::SPF::Mech.
- new_from_string($text, %options): returns Mail::SPF::Mech; throws Mail::SPF::ENothingToParse, Mail::SPF::EInvalidMech
- Abstract. Creates a new SPF record mechanism object by parsing the string and any options given.
Class methods¶
The following class methods are provided:
- default_qualifier: returns string
- Returns the default qualifier, i.e. '+'.
- default_ipv4_prefix_length: returns integer
- Returns the default IPv4 network prefix length, i.e. 32.
- default_ipv6_prefix_length: returns integer
- Returns the default IPv6 network prefix length, i.e. 128.
- qualifier_pattern: returns Regexp
- Returns a regular expression that matches any legal mechanism qualifier, i.e. '+', '-', '~', or '?'.
- name: returns string
- Abstract. Returns the name of the mechanism.
This method is abstract and must be implemented by sub-classes of Mail::SPF::Mech.
- name_pattern: returns Regexp
- Returns a regular expression that matches any legal mechanism name.
Instance methods¶
The following instance methods are provided:
- text: returns string; throws Mail::SPF::ENoUnparsedText
- Returns the unparsed text of the mechanism. Throws a Mail::SPF::ENoUnparsedText exception if the mechanism was created synthetically instead of being parsed, and no text was provided.
- qualifier: returns string
- Returns the qualifier of the mechanism. See the description of the "new" constructor's "qualifier" option.
- params: returns string
- Abstract. Returns the mechanism's parameters formatted as a string.
A sub-class of Mail::SPF::Mech does not have to implement this method if it supports no parameters.
- stringify: returns string
- Formats the mechanism's qualifier, name, and parameters as a string and returns it. (A qualifier that matches the default of '+' is omitted.) You can simply use a Mail::SPF::Mech object as a string for the same effect, see "OVERLOADING".
- domain($server, $request): returns string
- Returns the target domain of the mechanism. Depending on whether the mechanism does have an explicit "domain_spec" parameter, this is either the macro-expanded "domain_spec" parameter, or the request's authority domain (see "authority_domain" in Mail::SPF::Request) otherwise. Both a Mail::SPF::Server and a Mail::SPF::Request object are required for resolving the target domain.
- match($server, $request): returns boolean; throws Mail::SPF::Result::Error
- Abstract. Checks whether the mechanism matches the parameters of
the given request (see Mail::SPF::Request) and returns true if it
does, or false otherwise. In any case, takes both a
Mail::SPF::Server and a Mail::SPF::Request object.
This method is abstract and must be implemented by sub-classes of Mail::SPF::Mech.
- match_in_domain($server, $request): returns boolean; throws Mail::SPF::Result::Error
- match_in_domain($server, $request, $domain): returns boolean; throws Mail::SPF::Result::Error
- Checks whether the mechanism's target domain name (that is, any of its DNS
"A" or
"AAAA" records) matches the given
request's IP address (see "ip_address" in Mail::SPF::Request),
and returns true if it does, or false otherwise. If an
explicit domain is specified, it is used instead of the mechanism's target
domain. The mechanism's IP network prefix lengths are respected when
matching DNS address records against the request's IP address. See RFC
4408, 5, for the exact algorithm used.
This method exists mainly for the convenience of sub-classes of Mail::SPF::Mech.
- explain($server, $request, $result)
- Locally generates an explanation for why the mechanism caused the given
result, and stores it in the given request object's state.
There is no need to override this method in sub-classes. See the "explanation_template" method.
- explanation_template($server, $request, $result): returns string
- Returns a macro string template for a locally generated explanation for
why the mechanism caused the given result object.
Sub-classes should either define an "explanation_templates_by_result_code" hash constant with their own templates, or override this method.
OVERLOADING¶
If a Mail::SPF::Mech object is used as a string, the "stringify" method is used to convert the object into a string.
SEE ALSO¶
Mail::SPF::Mech::All, Mail::SPF::Mech::IP4, Mail::SPF::Mech::IP6, Mail::SPF::Mech::A, Mail::SPF::Mech::MX, Mail::SPF::Mech::PTR, Mail::SPF::Mech::Exists, Mail::SPF::Mech::Include
Mail::SPF, Mail::SPF::Record, Mail::SPF::Term
<http://tools.ietf.org/html/rfc4408>
For availability, support, and license information, see the README file included with Mail::SPF.
AUTHORS¶
Julian Mehnle <julian@mehnle.net>, Shevek <cpan@anarres.org>
2021-08-09 | perl v5.32.1 |