| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | # | 
| 2 |  |  |  |  |  |  | # Mail::SPF::Mod::Exp | 
| 3 |  |  |  |  |  |  | # SPF record "exp" modifier class. | 
| 4 |  |  |  |  |  |  | # | 
| 5 |  |  |  |  |  |  | # (C) 2005-2012 Julian Mehnle | 
| 6 |  |  |  |  |  |  | #     2005      Shevek | 
| 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 modifier class | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | =cut | 
| 18 |  |  |  |  |  |  |  | 
| 19 | 1 |  |  | 1 |  | 1086 | use warnings; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 25 |  | 
| 20 | 1 |  |  | 1 |  | 5 | use strict; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 23 |  | 
| 21 |  |  |  |  |  |  |  | 
| 22 | 1 |  |  | 1 |  | 5 | use Mail::SPF::Mod; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 19 |  | 
| 23 | 1 |  |  | 1 |  | 5 | use base 'Mail::SPF::GlobalMod'; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 576 |  | 
| 24 |  |  |  |  |  |  |  | 
| 25 | 1 |  |  | 1 |  | 5 | use Error ':try'; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 7 |  | 
| 26 |  |  |  |  |  |  |  | 
| 27 | 1 |  |  | 1 |  | 167 | use Mail::SPF::MacroString; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 22 |  | 
| 28 |  |  |  |  |  |  |  | 
| 29 | 1 |  |  | 1 |  | 4 | use constant TRUE   => (0 == 0); | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 57 |  | 
| 30 | 1 |  |  | 1 |  | 5 | use constant FALSE  => not TRUE; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 35 |  | 
| 31 |  |  |  |  |  |  |  | 
| 32 | 1 |  |  | 1 |  | 4 | use constant name           => 'exp'; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 50 |  | 
| 33 | 1 |  |  | 1 |  | 4 | use constant name_pattern   => qr/${\name}/i; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 55 |  | 
| 34 |  |  |  |  |  |  |  | 
| 35 | 1 |  |  | 1 |  | 5 | use constant precedence     => 0.2; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 379 |  | 
| 36 |  |  |  |  |  |  |  | 
| 37 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 38 |  |  |  |  |  |  |  | 
| 39 |  |  |  |  |  |  | An object of class B represents an SPF record modifier of | 
| 40 |  |  |  |  |  |  | type C. | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | =head2 Constructors | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | The following constructors are provided: | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | =over | 
| 47 |  |  |  |  |  |  |  | 
| 48 |  |  |  |  |  |  | =item B: returns I | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  | Creates a new SPF record C modifier object. | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | %options is a list of key/value pairs representing any of the following | 
| 53 |  |  |  |  |  |  | options: | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | =over | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | =item B | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | See L. | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | =back | 
| 62 |  |  |  |  |  |  |  | 
| 63 |  |  |  |  |  |  | =item B: returns I; | 
| 64 |  |  |  |  |  |  | throws I, I | 
| 65 |  |  |  |  |  |  |  | 
| 66 |  |  |  |  |  |  | Creates a new SPF record C modifier object by parsing the string and | 
| 67 |  |  |  |  |  |  | any options given. | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | =back | 
| 70 |  |  |  |  |  |  |  | 
| 71 |  |  |  |  |  |  | =head2 Class methods | 
| 72 |  |  |  |  |  |  |  | 
| 73 |  |  |  |  |  |  | The following class methods are provided: | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | =over | 
| 76 |  |  |  |  |  |  |  | 
| 77 |  |  |  |  |  |  | =item B: returns I | 
| 78 |  |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  | Returns B<'exp'>. | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | =item B: returns I | 
| 82 |  |  |  |  |  |  |  | 
| 83 |  |  |  |  |  |  | Returns a regular expression that matches a modifier name of B<'exp'>. | 
| 84 |  |  |  |  |  |  |  | 
| 85 |  |  |  |  |  |  | =item B: returns I | 
| 86 |  |  |  |  |  |  |  | 
| 87 |  |  |  |  |  |  | Returns a precedence value of B<0.2>.  See L. | 
| 88 |  |  |  |  |  |  |  | 
| 89 |  |  |  |  |  |  | =back | 
| 90 |  |  |  |  |  |  |  | 
| 91 |  |  |  |  |  |  | =head2 Instance methods | 
| 92 |  |  |  |  |  |  |  | 
| 93 |  |  |  |  |  |  | The following instance methods are provided: | 
| 94 |  |  |  |  |  |  |  | 
| 95 |  |  |  |  |  |  | =over | 
| 96 |  |  |  |  |  |  |  | 
| 97 |  |  |  |  |  |  | =cut | 
| 98 |  |  |  |  |  |  |  | 
| 99 |  |  |  |  |  |  | sub parse_params { | 
| 100 | 0 |  |  | 0 | 0 |  | my ($self) = @_; | 
| 101 | 0 |  |  |  |  |  | $self->parse_domain_spec(TRUE); | 
| 102 | 0 |  |  |  |  |  | return; | 
| 103 |  |  |  |  |  |  | } | 
| 104 |  |  |  |  |  |  |  | 
| 105 |  |  |  |  |  |  | =item B | 
| 106 |  |  |  |  |  |  |  | 
| 107 |  |  |  |  |  |  | See L. | 
| 108 |  |  |  |  |  |  |  | 
| 109 |  |  |  |  |  |  | =cut | 
| 110 |  |  |  |  |  |  |  | 
| 111 |  |  |  |  |  |  | sub params { | 
| 112 | 0 |  |  | 0 | 1 |  | my ($self) = @_; | 
| 113 | 0 |  |  |  |  |  | return $self->{domain_spec}; | 
| 114 |  |  |  |  |  |  | } | 
| 115 |  |  |  |  |  |  |  | 
| 116 |  |  |  |  |  |  | =item B: returns I | 
| 117 |  |  |  |  |  |  |  | 
| 118 |  |  |  |  |  |  | Returns the C parameter of the modifier. | 
| 119 |  |  |  |  |  |  |  | 
| 120 |  |  |  |  |  |  | =cut | 
| 121 |  |  |  |  |  |  |  | 
| 122 |  |  |  |  |  |  | # Make read-only accessor: | 
| 123 |  |  |  |  |  |  | __PACKAGE__->make_accessor('domain_spec', TRUE); | 
| 124 |  |  |  |  |  |  |  | 
| 125 |  |  |  |  |  |  | =item B | 
| 126 |  |  |  |  |  |  |  | 
| 127 |  |  |  |  |  |  | If the given SPF result is a C result, retrieves the authority domain's | 
| 128 |  |  |  |  |  |  | explanation string from the modifier's target domain and attaches it to the SPF | 
| 129 |  |  |  |  |  |  | result.  If an error occurs during the retrieval of the explanation string, | 
| 130 |  |  |  |  |  |  | does nothing, as if the modifier was not present.  See RFC 4408, 6.2, for | 
| 131 |  |  |  |  |  |  | details. | 
| 132 |  |  |  |  |  |  |  | 
| 133 |  |  |  |  |  |  | =cut | 
| 134 |  |  |  |  |  |  |  | 
| 135 |  |  |  |  |  |  | sub process { | 
| 136 | 0 |  |  | 0 | 1 |  | my ($self, $server, $request, $result) = @_; | 
| 137 |  |  |  |  |  |  |  | 
| 138 |  |  |  |  |  |  | try { | 
| 139 | 0 |  |  | 0 |  |  | my $exp_domain = $self->{domain_spec}->new(server => $server, request => $request); | 
| 140 | 0 |  |  |  |  |  | my $txt_packet = $server->dns_lookup($exp_domain, 'TXT'); | 
| 141 | 0 |  |  |  |  |  | my @txt_rrs = grep($_->type eq 'TXT', $txt_packet->answer); | 
| 142 | 0 | 0 |  |  |  |  | @txt_rrs > 0 | 
| 143 |  |  |  |  |  |  | or $server->throw_result('permerror', $request, | 
| 144 |  |  |  |  |  |  | "No authority explanation string available at domain '$exp_domain'");  # RFC 4408, 6.2/4 | 
| 145 | 0 | 0 |  |  |  |  | @txt_rrs == 1 | 
| 146 |  |  |  |  |  |  | or $server->throw_result('permerror', $request, | 
| 147 |  |  |  |  |  |  | "Redundant authority explanation strings found at domain '$exp_domain'");  # RFC 4408, 6.2/4 | 
| 148 | 0 |  |  |  |  |  | my $explanation = Mail::SPF::MacroString->new( | 
| 149 |  |  |  |  |  |  | text            => join('', $txt_rrs[0]->char_str_list), | 
| 150 |  |  |  |  |  |  | server          => $server, | 
| 151 |  |  |  |  |  |  | request         => $request, | 
| 152 |  |  |  |  |  |  | is_explanation  => TRUE | 
| 153 |  |  |  |  |  |  | ); | 
| 154 | 0 |  |  |  |  |  | $request->state('authority_explanation', $explanation); | 
| 155 |  |  |  |  |  |  | } | 
| 156 |  |  |  |  |  |  | # Ignore DNS and other errors: | 
| 157 | 0 |  |  | 0 |  |  | catch Mail::SPF::EDNSError with {} | 
| 158 | 0 |  |  | 0 |  |  | catch Mail::SPF::Result::Error with {}; | 
|  | 0 |  |  |  |  |  |  | 
| 159 |  |  |  |  |  |  |  | 
| 160 | 0 |  |  |  |  |  | return; | 
| 161 |  |  |  |  |  |  | } | 
| 162 |  |  |  |  |  |  |  | 
| 163 |  |  |  |  |  |  | =back | 
| 164 |  |  |  |  |  |  |  | 
| 165 |  |  |  |  |  |  | See L for other supported instance methods. | 
| 166 |  |  |  |  |  |  |  | 
| 167 |  |  |  |  |  |  | =head1 SEE ALSO | 
| 168 |  |  |  |  |  |  |  | 
| 169 |  |  |  |  |  |  | L, L, L, L | 
| 170 |  |  |  |  |  |  |  | 
| 171 |  |  |  |  |  |  | L | 
| 172 |  |  |  |  |  |  |  | 
| 173 |  |  |  |  |  |  | For availability, support, and license information, see the README file | 
| 174 |  |  |  |  |  |  | included with Mail::SPF. | 
| 175 |  |  |  |  |  |  |  | 
| 176 |  |  |  |  |  |  | =head1 AUTHORS | 
| 177 |  |  |  |  |  |  |  | 
| 178 |  |  |  |  |  |  | Julian Mehnle , Shevek | 
| 179 |  |  |  |  |  |  |  | 
| 180 |  |  |  |  |  |  | =cut | 
| 181 |  |  |  |  |  |  |  | 
| 182 |  |  |  |  |  |  | TRUE; |