| 1 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # Mail::SPF::MacroString | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # SPF record macro string class. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # (C) 2005-2012 Julian Mehnle <julian@mehnle.net> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # 2005 Shevek <cpan@anarres.org> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # $Id: MacroString.pm 57 2012-01-30 08:15:31Z julian $ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | ############################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | package Mail::SPF::MacroString; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | Mail::SPF::MacroString - SPF record macro string class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | version 3.20261105 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 7 | our $VERSION = '3.20261105'; # VERSION | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 7 | ▶ | use utf8; # Hack to keep Perl 5.6 from whining about /[\p{}]/. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 7 | ▶ | use base 'Mail::SPF::Base'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | use overload | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 7 | ▶ | '""' => 'stringify', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 7 | fallback => 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 7 | ▶ | use Error ':try'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 7 | ▶ | use URI::Escape 1.13 (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 7 | ▶ | use Mail::SPF::Util; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 7 | ▶ | use constant TRUE => (0 == 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 7 | ▶ | use constant FALSE => not TRUE; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 7 | ▶ | use constant default_split_delimiters => '.'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 7 | ▶ | use constant default_join_delimiter => '.'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 7 | ▶ | use constant uri_unreserved_chars => 'A-Za-z0-9\-._~'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | # "unreserved" characters according to RFC 3986 -- not the "uric" chars! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | # This deliberately deviates from what RFC 4408 says. This is a bug in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | # RFC 4408. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 7 | ▶ | use constant macos_epoch_offset => ((1970 - 1904) * 365 + 17) * 24 * 3600; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | # This is a hack because the MacOS Classic epoch is relative to the local | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | # timezone. Get a real OS! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | # Interface: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | ############################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | =head2 Providing the expansion context early | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | use Mail::SPF::MacroString; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | my $macrostring = Mail::SPF::MacroString->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | text => '%{ir}.%{v}._spf.%{d2}', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | server => $server, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | request => $request | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | my $expanded = $macrostring->expand; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | =head2 Providing the expansion context late | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | use Mail::SPF::MacroString; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | my $macrostring = Mail::SPF::MacroString->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | text => '%{ir}.%{v}._spf.%{d2}' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | my $expanded1 = $macrostring->expand($server, $request1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | $macrostring->context($server, $request2); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | my $expanded2 = $macrostring->expand; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | # Implementation: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | ############################################################################## | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | An object of class B<Mail::SPF::MacroString> represents a macro string that | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | can be expanded to a plain string in the context of an SPF request. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | =head2 Constructor | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | The following constructor is provided: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | =over | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | =item B<new(%options)>: returns I<Mail::SPF::MacroString> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | Creates a new SPF record macro string object. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | %options is a list of key/value pairs representing any of the following | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | options: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | =over | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | =item B<text> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | I<Required>. The unexpanded text of the new macro string. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | =item B<server> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | The I<Mail::SPF::Server> object that is to be used when expanding the macro | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | string. A server object need not be attached statically to the macro string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | it can be specified dynamically when calling the C<expand> method. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | =item B<request> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | The I<Mail::SPF::Request> object that is to be used when expanding the macro | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | string. A request object need not be attached statically to the macro string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | it can be specified dynamically when calling the C<expand> method. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | =item B<is_explanation> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | A I<boolean> denoting whether the macro string is an explanation string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | obtained via an C<exp> modifier. If B<true>, the C<c>, C<r>, and C<t> macros | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | may appear in the macro string, otherwise they may not, and if they do, a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | I<Mail::SPF::EInvalidMacro> exception will be thrown when the macro string is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | expanded. Defaults to B<false>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 84 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 84 | my ($self, %options) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 84 | $self = $self->SUPER::new(%options); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | defined($self->{text}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 84 | ▶ | or throw Mail::SPF::EOptionRequired("Missing required 'text' option"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 84 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | =head2 Instance methods | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | The following instance methods are provided: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | =over | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | =item B<text>: returns I<string> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | Returns the unexpanded text of the macro string. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | # Read-only accessor: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 7 | __PACKAGE__->make_accessor('text', TRUE); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | =item B<context($server, $request)>: throws I<Mail::SPF::EOptionRequired> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | Attaches the given I<Mail::SPF::Server> and I<Mail::SPF::Request> objects as | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | the context for the macro string. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 1 | ▶ | sub context { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
context: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 1 | my ($self, $server, $request) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 1 | $self->_is_valid_context(TRUE, $server, $request); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 1 | $self->{server} = $server; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 1 | $self->{request} = $request; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 1 | $self->{expanded} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | =item B<expand>: returns I<string>; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | throws I<Mail::SPF::EMacroExpansionCtxRequired>, I<Mail::SPF::EInvalidMacroString>, I<Mail::SPF::Result::PermError> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | =item B<expand($server, $request)>: returns I<string>; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | throws I<Mail::SPF::EMacroExpansionCtxRequired>, I<Mail::SPF::EInvalidMacroString>, I<Mail::SPF::Result::PermError> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | Expands the text of the macro string using either the context specified through | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | an earlier call to the C<context()> method, or the given context, and returns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | the resulting string. See RFC 4408, 8, for how macros are expanded. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 53 | ▶ | sub expand { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
expand: called CC=49 SCAR=53.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 53 | my ($self, @context) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | return $self->{expanded} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 53 | ▶ | if defined($self->{expanded}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 35 | my $text = $self->{text}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | return undef | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 35 | ▶ | if not defined($text); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 35 | ▶ | return $self->{expanded} = $text | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | if $text !~ /%/; # Short-circuit expansion if text has no '%' character. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 16 | ▶ | my ($server, $request) = @context ? @context : ($self->{server}, $self->{request}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 16 | $self->_is_valid_context(TRUE, $server, $request); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 15 | my $expanded = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 15 | pos($text) = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 15 | ▶ | while ($text =~ m/ \G (.*?) %(.) /cgsx) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 70 | $expanded .= $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 70 | my $key = $2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 70 | my $pos = pos($text) - 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 70 | ▶ | if ($key eq '{') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 69 | ▶ | if ($text =~ m/ \G (\w|_\p{IsAlpha}+) ([0-9]+)? (r)? ([.\-+,\/_=]*)? } /cgx) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 69 | my ($char, $rh_parts, $reverse, $delimiters) = ($1, $2, $3, $4); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | # Upper-case macro chars trigger URL-escaping AKA percent-encoding | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | # (RFC 4408, 8.1/26): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 69 | my $do_percent_encode = $char =~ tr/A-Z/a-z/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 69 | my $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 69 | ▶ | if ($char eq 's') { # RFC 4408, 8.1/19 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 12 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | $value = $request->identity; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | elsif ($char eq 'l') { # RFC 4408, 8.1/19 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 4 | $value = $request->localpart; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | elsif ($char eq 'o') { # RFC 4408, 8.1/19 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | $value = $request->domain; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | elsif ($char eq 'd') { # RFC 4408, 8.1/6/4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 6 | $value = $request->authority_domain; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | elsif ($char eq 'i') { # RFC 4408, 8.1/20, 8.1/21 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 3 | my $ip_address = $request->ip_address; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 3 | ▶ | $ip_address = Mail::SPF::Util->ipv6_address_to_ipv4($ip_address) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | if Mail::SPF::Util->ipv6_address_is_ipv4_mapped($ip_address); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 3 | my $ip_address_version = $ip_address->version; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 3 | ▶ | if ($ip_address_version == 4) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 3 | $value = $ip_address->addr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | elsif ($ip_address_version == 6) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | $value = join(".", split(//, unpack("H32", $ip_address->aton))); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | # Unexpected IP address version. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | $server->throw_result('permerror', $request, | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | "Unexpected IP address version '$ip_address_version' in request"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | elsif ($char eq 'p') { # RFC 4408, 8.1/22 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | # Cache the validated domain name per SPF check, as each | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | # look-up costs a PTR and up to 10 A/AAAA queries, which | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | # (in explanation strings) are not subject to any limit: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 53 | ▶ | my $p_macro_cache = $request->root_request->state('p_macro_cache') | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$request->root_request->state('p_macro_cache') || $request->root_request->state('p_macro_cache', {})
MC/DC0%0/2
$request->root_request->state('p_macro_cache') || $request->root_request->state('p_macro_cache', {})
$request->root_request->state('p_macro_cache')
$request->root_request->state('p_macro_cache', {})
Truth table66%2/3
A || B
A= $request->root_request->state('p_macro_cache')B= $request->root_request->state('p_macro_cache', {})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | || $request->root_request->state('p_macro_cache', {}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 53 | my $cache_key = join(' ', $request->ip_address, lc($request->authority_domain)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 53 | ▶ | if (not exists($p_macro_cache->{$cache_key})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 4 | ▶ | try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 4 | $value = Mail::SPF::Util->valid_domain_for_ip_address( | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | $server, $request, $request->ip_address, $request->authority_domain, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | TRUE, TRUE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 4 | ▶ | catch Mail::SPF::EDNSError with {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 3 | ▶ | $p_macro_cache->{$cache_key} = $value || 'unknown'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$value || 'unknown'
MC/DC100%1/1
$value || 'unknown'
$value
Truth table100%2/2
A
A= $value
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 52 | $value = $p_macro_cache->{$cache_key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | elsif ($char eq 'v') { # RFC 4408, 8.1/6/7 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 3 | my $ip_address_version = $request->ip_address->version; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 3 | ▶ | if ($ip_address_version == 4) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 3 | $value = 'in-addr'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | elsif ($ip_address_version == 6) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | $value = 'ip6'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | # Unexpected IP address version. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | $server->throw_result('permerror', $request, | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | "Unexpected IP address version '$ip_address_version' in request"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | elsif ($char eq 'h') { # RFC 4408, 8.1/6/8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | ▶ | $value = $request->helo_identity || 'unknown'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$request->helo_identity || 'unknown'
MC/DC0%0/1
$request->helo_identity || 'unknown'
$request->helo_identity
Truth table0%0/2
A
A= $request->helo_identity
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | elsif ($char eq 'c') { # RFC 4408, 8.1/20, 8.1/21 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | $self->{is_explanation} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | ▶ | or throw Mail::SPF::EInvalidMacro( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | "Illegal 'c' macro in non-explanation macro string '$text'"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | my $ip_address = $request->ip_address; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | ▶ | $ip_address = Mail::SPF::Util->ipv6_address_to_ipv4($ip_address) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | if Mail::SPF::Util->ipv6_address_is_ipv4_mapped($ip_address); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | $value = Mail::SPF::Util->ip_address_to_string($ip_address); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | elsif ($char eq 'r') { # RFC 4408, 8.1/23 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | $self->{is_explanation} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | ▶ | or throw Mail::SPF::EInvalidMacro( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | "Illegal 'r' macro in non-explanation macro string '$text'"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | ▶ | $value = $server->hostname || 'unknown'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$server->hostname || 'unknown'
MC/DC0%0/1
$server->hostname || 'unknown'
$server->hostname
Truth table0%0/2
A
A= $server->hostname
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | elsif ($char eq 't') { # RFC 4408, 8.1/24 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | $self->{is_explanation} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | ▶ | or throw Mail::SPF::EInvalidMacro( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | "Illegal 't' macro in non-explanation macro string '$text'"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | ▶ | $value = $^O ne 'MacOS' ? time() : time() + $self->macos_epoch_offset; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | elsif ($char eq '_scope') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | # Scope pseudo macro for internal use only! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | $value = $request->scope; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | # Unknown macro character. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | throw Mail::SPF::EInvalidMacro( | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | "Unknown macro character '$char' at pos $pos in macro string '$text'"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 68 | ▶ | if (defined($rh_parts) or defined($reverse)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $rh_parts or defined $reverse
MC/DC100%2/2
defined $rh_parts or defined $reverse
defined $rh_parts
defined $reverse
Truth table100%3/3
A or B
A= defined $rh_partsB= defined $reverse
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 7 | ▶ | $delimiters ||= $self->default_split_delimiters; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$delimiters ||= $self->default_split_delimiters
MC/DC0%0/2
$delimiters ||= $self->default_split_delimiters
$delimiters
$self->default_split_delimiters
Truth table33%1/3
A ||= B
A= $delimitersB= $self->default_split_delimiters
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 7 | my @list = split(/[\Q$delimiters\E]/, $value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 7 | ▶ | @list = reverse(@list) if defined($reverse); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | # Extract desired parts: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 7 | ▶ | if (defined($rh_parts) and $rh_parts > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $rh_parts and $rh_parts > 0
MC/DC50%1/2
defined $rh_parts and $rh_parts > 0
defined $rh_parts
$rh_parts > 0
Truth table66%2/3
A and B
A= defined $rh_partsB= $rh_parts > 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 4 | ▶ | splice(@list, 0, @list >= $rh_parts ? @list - $rh_parts : 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 7 | ▶ | if (defined($rh_parts) and $rh_parts == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $rh_parts and $rh_parts == 0
MC/DC0%0/2
defined $rh_parts and $rh_parts == 0
defined $rh_parts
$rh_parts == 0
Truth table66%2/3
A and B
A= defined $rh_partsB= $rh_parts == 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | throw Mail::SPF::EInvalidMacro( | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | "Illegal selection of 0 (zero) right-hand parts at pos $pos in macro string '$text'"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 7 | $value = join($self->default_join_delimiter, @list); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 68 | ▶ | $value = URI::Escape::uri_escape($value, '^' . $self->uri_unreserved_chars) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | # Note the comment about the set of safe/unsafe characters at the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | # definition of the "uri_unreserved_chars" constant above. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | if $do_percent_encode; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 68 | $expanded .= $value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | # Invalid macro expression. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | throw Mail::SPF::EInvalidMacro( | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | "Invalid macro expression at pos $pos in macro string '$text'"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | elsif ($key eq '-') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | $expanded .= '%20'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | elsif ($key eq '_') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | $expanded .= ' '; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | elsif ($key eq '%') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | $expanded .= '%'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | # Invalid macro expression. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 1 | throw Mail::SPF::EInvalidMacro( | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | "Invalid macro expression at pos $pos in macro string '$text'"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 13 | $expanded .= substr($text, pos($text)); # Append remaining unmatched characters. | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | #print("DEBUG: Expand $text -> $expanded\n"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | #printf("DEBUG: Caller: %s() (line %d)\n", (caller(1))[3, 2]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 13 | ▶ | return @context ? $expanded : ($self->{expanded} = $expanded); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | =item B<is_explanation>: returns I<boolean> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | Returns B<true> if the macro string is an explanation string obtained via an | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | C<exp> modifier. See the description of the L</new> constructor's | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | C<is_explanation> option. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | # Make read-only accessor: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 7 | __PACKAGE__->make_accessor('is_explanation', TRUE); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | =item B<stringify>: returns I<string> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | Returns the expanded text of the macro string if a context is attached to the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | object. Returns the unexpanded text otherwise. You can simply use a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | Mail::SPF::MacroString object as a string for the same effect, see | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | L<"OVERLOADING">. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 21 | ▶ | sub stringify { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stringify: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 21 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 21 | ▶ | $self->_is_valid_context(FALSE, $self->{server}, $self->{request}) ? | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | $self->expand # Context availabe, expand. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | : $self->text; # Context unavailable, do not expand. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 38 | ▶ | sub _is_valid_context { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_valid_context: called CC=5 SCAR=17.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 38 | my ($self, $require, $server, $request) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 38 | ▶ | if (not UNIVERSAL::isa($server, 'Mail::SPF::Server')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 4 | ▶ | throw Mail::SPF::EMacroExpansionCtxRequired('Mail::SPF server object required') if $require; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 3 | return FALSE; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 34 | ▶ | if (not UNIVERSAL::isa($request, 'Mail::SPF::Request')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 0 | ▶ | throw Mail::SPF::EMacroExpansionCtxRequired('Request object required') if $require; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | return FALSE; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 34 | return TRUE; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | =head1 OVERLOADING | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | If a Mail::SPF::MacroString object is used as a I<string>, the C<stringify> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | method is used to convert the object into a string. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | L<Mail::SPF>, L<Mail::SPF::Record>, L<Mail::SPF::Server>, L<Mail::SPF::Request> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | L<http://tools.ietf.org/html/rfc4408> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | For availability, support, and license information, see the README file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | included with Mail::SPF. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | =head1 AUTHORS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | Julian Mehnle <julian@mehnle.net>, Shevek <cpan@anarres.org> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 7 | TRUE; | |||||||||||||||||||||||||||||||||||||||||||||||||||||