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