| 1 | # | ||||||||||
| 2 | # Mail::SPF::Mod::Exp | ||||||||||
| 3 | # SPF record "exp" modifier class. | ||||||||||
| 4 | # | ||||||||||
| 5 | # (C) 2005-2012 Julian Mehnle <julian@mehnle.net> | ||||||||||
| 6 | # 2005 Shevek <cpan@anarres.org> | ||||||||||
| 7 | # $Id: Exp.pm 57 2012-01-30 08:15:31Z julian $ | ||||||||||
| 8 | # | ||||||||||
| 9 | ############################################################################## | ||||||||||
| 10 | |||||||||||
| 11 | package Mail::SPF::Mod::Exp; | ||||||||||
| 12 | |||||||||||
| 13 | =head1 NAME | ||||||||||
| 14 | |||||||||||
| 15 | Mail::SPF::Mod::Exp - SPF record C<exp> modifier class | ||||||||||
| 16 | |||||||||||
| 17 | =head1 VERSION | ||||||||||
| 18 | |||||||||||
| 19 | version 3.20261105 | ||||||||||
| 20 | |||||||||||
| 21 | =cut | ||||||||||
| 22 | |||||||||||
| 23 | 5 | our $VERSION = '3.20261105'; # VERSION | |||||||||
| 24 | |||||||||||
| 25 | 5 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 26 | 5 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 27 | |||||||||||
| 28 | 5 | ▶ | use Mail::SPF::Mod; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 29 | 5 | ▶ | use base 'Mail::SPF::GlobalMod'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 30 | |||||||||||
| 31 | 5 | ▶ | use Error ':try'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 32 | |||||||||||
| 33 | 5 | ▶ | use Mail::SPF::MacroString; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 34 | |||||||||||
| 35 | 5 | ▶ | use constant TRUE => (0 == 0); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 36 | 5 | ▶ | use constant FALSE => not TRUE; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 37 | |||||||||||
| 38 | 5 | ▶ | use constant name => 'exp'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 39 | 5 | ▶ | use constant name_pattern => qr/${\name}/i; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 40 | |||||||||||
| 41 | 5 | ▶ | use constant precedence => 0.2; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 42 | |||||||||||
| 43 | =head1 DESCRIPTION | ||||||||||
| 44 | |||||||||||
| 45 | An object of class B<Mail::SPF::Mod::Exp> represents an SPF record modifier of | ||||||||||
| 46 | type C<exp>. | ||||||||||
| 47 | |||||||||||
| 48 | =head2 Constructors | ||||||||||
| 49 | |||||||||||
| 50 | The following constructors are provided: | ||||||||||
| 51 | |||||||||||
| 52 | =over | ||||||||||
| 53 | |||||||||||
| 54 | =item B<new(%options)>: returns I<Mail::SPF::Mod::Exp> | ||||||||||
| 55 | |||||||||||
| 56 | Creates a new SPF record C<exp> modifier object. | ||||||||||
| 57 | |||||||||||
| 58 | %options is a list of key/value pairs representing any of the following | ||||||||||
| 59 | options: | ||||||||||
| 60 | |||||||||||
| 61 | =over | ||||||||||
| 62 | |||||||||||
| 63 | =item B<domain_spec> | ||||||||||
| 64 | |||||||||||
| 65 | See L<Mail::SPF::Mod/new>. | ||||||||||
| 66 | |||||||||||
| 67 | =back | ||||||||||
| 68 | |||||||||||
| 69 | =item B<new_from_string($text, %options)>: returns I<Mail::SPF::Mod::Exp>; | ||||||||||
| 70 | throws I<Mail::SPF::ENothingToParse>, I<Mail::SPF::EInvalidMod> | ||||||||||
| 71 | |||||||||||
| 72 | Creates a new SPF record C<exp> modifier object by parsing the string and | ||||||||||
| 73 | any options given. | ||||||||||
| 74 | |||||||||||
| 75 | =back | ||||||||||
| 76 | |||||||||||
| 77 | =head2 Class methods | ||||||||||
| 78 | |||||||||||
| 79 | The following class methods are provided: | ||||||||||
| 80 | |||||||||||
| 81 | =over | ||||||||||
| 82 | |||||||||||
| 83 | =item B<name>: returns I<string> | ||||||||||
| 84 | |||||||||||
| 85 | Returns B<'exp'>. | ||||||||||
| 86 | |||||||||||
| 87 | =item B<name_pattern>: returns I<Regexp> | ||||||||||
| 88 | |||||||||||
| 89 | Returns a regular expression that matches a modifier name of B<'exp'>. | ||||||||||
| 90 | |||||||||||
| 91 | =item B<precedence>: returns I<real> | ||||||||||
| 92 | |||||||||||
| 93 | Returns a precedence value of B<0.2>. See L<Mail::SPF::Mod/precedence>. | ||||||||||
| 94 | |||||||||||
| 95 | =back | ||||||||||
| 96 | |||||||||||
| 97 | =head2 Instance methods | ||||||||||
| 98 | |||||||||||
| 99 | The following instance methods are provided: | ||||||||||
| 100 | |||||||||||
| 101 | =over | ||||||||||
| 102 | |||||||||||
| 103 | =cut | ||||||||||
| 104 | |||||||||||
| 105 | 6 | ▶ | sub parse_params { | ||||||||
|
Subroutine
parse_params: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 106 | 6 | my ($self) = @_; | |||||||||
| 107 | 6 | $self->parse_domain_spec(TRUE); | |||||||||
| 108 | 6 | return; | |||||||||
| 109 | } | ||||||||||
| 110 | |||||||||||
| 111 | =item B<params> | ||||||||||
| 112 | |||||||||||
| 113 | See L<Mail::SPF::Mod/params>. | ||||||||||
| 114 | |||||||||||
| 115 | =cut | ||||||||||
| 116 | |||||||||||
| 117 | 0 | ▶ | sub params { | ||||||||
|
Subroutine
params: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 118 | 0 | my ($self) = @_; | |||||||||
| 119 | 0 | return $self->{domain_spec}; | |||||||||
| 120 | } | ||||||||||
| 121 | |||||||||||
| 122 | =item B<domain_spec>: returns I<Mail::SPF::MacroString> | ||||||||||
| 123 | |||||||||||
| 124 | Returns the C<domain-spec> parameter of the modifier. | ||||||||||
| 125 | |||||||||||
| 126 | =cut | ||||||||||
| 127 | |||||||||||
| 128 | # Make read-only accessor: | ||||||||||
| 129 | 5 | __PACKAGE__->make_accessor('domain_spec', TRUE); | |||||||||
| 130 | |||||||||||
| 131 | =item B<process($server, $request, $result)> | ||||||||||
| 132 | |||||||||||
| 133 | If the given SPF result is a C<fail> result, retrieves the authority domain's | ||||||||||
| 134 | explanation string from the modifier's target domain and attaches it to the SPF | ||||||||||
| 135 | result. If an error occurs during the retrieval of the explanation string, | ||||||||||
| 136 | does nothing, as if the modifier was not present. See RFC 4408, 6.2, for | ||||||||||
| 137 | details. | ||||||||||
| 138 | |||||||||||
| 139 | =cut | ||||||||||
| 140 | |||||||||||
| 141 | 6 | ▶ | sub process { | ||||||||
|
Subroutine
process: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 142 | 6 | my ($self, $server, $request, $result) = @_; | |||||||||
| 143 | |||||||||||
| 144 | 6 | ▶ | try { | ||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.4
| |||||||||||
| 145 | 6 | my $exp_domain = $self->{domain_spec}->new(server => $server, request => $request); | |||||||||
| 146 | 6 | my $txt_packet = $server->dns_lookup($exp_domain, 'TXT'); | |||||||||
| 147 | 6 | my @txt_rrs = grep($_->type eq 'TXT', $txt_packet->answer); | |||||||||
| 148 | 6 | ▶ | @txt_rrs > 0 | ||||||||
|
Branch: 1 branch
| |||||||||||
| 149 | or $server->throw_result('permerror', $request, | ||||||||||
| 150 | "No authority explanation string available at domain '$exp_domain'"); # RFC 4408, 6.2/4 | ||||||||||
| 151 | 6 | ▶ | @txt_rrs == 1 | ||||||||
|
Branch: 1 branch
| |||||||||||
| 152 | or $server->throw_result('permerror', $request, | ||||||||||
| 153 | "Redundant authority explanation strings found at domain '$exp_domain'"); # RFC 4408, 6.2/4 | ||||||||||
| 154 | |||||||||||
| 155 | # char_str_list method is 'historical', use as a fallback for Net::DNS prior to 0.69 | ||||||||||
| 156 | # where txtdata is not available. | ||||||||||
| 157 | # join with no intervening spaces, RFC 6376 | ||||||||||
| 158 | # must call txtdata() in a list context | ||||||||||
| 159 | 6 | ▶ | my $text = $txt_rrs[0]->can('txtdata') | ||||||||
|
Branch: 1 branch
| |||||||||||
| 160 | ? join('', $txt_rrs[0]->txtdata) | ||||||||||
| 161 | : join('', $txt_rrs[0]->char_str_list); | ||||||||||
| 162 | # The explanation string may contain printable ASCII and spaces only | ||||||||||
| 163 | # (RFC 7208, 6.2), so e.g. no CR/LF can end up in an SMTP reply: | ||||||||||
| 164 | 6 | ▶ | $text !~ /[^\x20-\x7e]/ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 165 | or $server->throw_result('permerror', $request, | ||||||||||
| 166 | "Invalid characters in authority explanation string at domain '$exp_domain'"); | ||||||||||
| 167 | 2 | my $explanation = Mail::SPF::MacroString->new( | |||||||||
| 168 | text => $text, | ||||||||||
| 169 | server => $server, | ||||||||||
| 170 | request => $request, | ||||||||||
| 171 | is_explanation => TRUE | ||||||||||
| 172 | ); | ||||||||||
| 173 | |||||||||||
| 174 | 2 | $request->state('authority_explanation', $explanation); | |||||||||
| 175 | } | ||||||||||
| 176 | # Ignore DNS and other errors: | ||||||||||
| 177 | 0 | ▶ | catch Mail::SPF::EDNSError with {} | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||
| 178 | 6 | ▶ | catch Mail::SPF::Result::Error with {}; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 179 | |||||||||||
| 180 | 6 | return; | |||||||||
| 181 | } | ||||||||||
| 182 | |||||||||||
| 183 | =back | ||||||||||
| 184 | |||||||||||
| 185 | See L<Mail::SPF::Mod> for other supported instance methods. | ||||||||||
| 186 | |||||||||||
| 187 | =head1 SEE ALSO | ||||||||||
| 188 | |||||||||||
| 189 | L<Mail::SPF>, L<Mail::SPF::Mod>, L<Mail::SPF::Term>, L<Mail::SPF::Record> | ||||||||||
| 190 | |||||||||||
| 191 | L<http://tools.ietf.org/html/rfc4408> | ||||||||||
| 192 | |||||||||||
| 193 | For availability, support, and license information, see the README file | ||||||||||
| 194 | included with Mail::SPF. | ||||||||||
| 195 | |||||||||||
| 196 | =head1 AUTHORS | ||||||||||
| 197 | |||||||||||
| 198 | Julian Mehnle <julian@mehnle.net>, Shevek <cpan@anarres.org> | ||||||||||
| 199 | |||||||||||
| 200 | =cut | ||||||||||
| 201 | |||||||||||
| 202 | 5 | TRUE; | |||||||||