/usr/share/perl5/Mail/SPF/Mod.pm is in libmail-spf-perl 2.9.0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 | #
# Mail::SPF::Mod
# SPF record modifier class.
#
# (C) 2005-2012 Julian Mehnle <julian@mehnle.net>
# 2005 Shevek <cpan@anarres.org>
# $Id: Mod.pm 57 2012-01-30 08:15:31Z julian $
#
##############################################################################
package Mail::SPF::Mod;
=head1 NAME
Mail::SPF::Mod - SPF record modifier base class
=cut
use warnings;
use strict;
use utf8; # Hack to keep Perl 5.6 from whining about /[\p{}]/.
use base 'Mail::SPF::Term';
use Mail::SPF::MacroString;
use constant TRUE => (0 == 0);
use constant FALSE => not TRUE;
use constant name_pattern => qr/ ${\__PACKAGE__->SUPER::name_pattern} (?= = ) /x;
=head1 DESCRIPTION
An object of class B<Mail::SPF::Mod> represents a modifier within an SPF
record. Mail::SPF::Mod cannot be instantiated directly. Create an instance of
a concrete sub-class instead.
=head2 Constructors
The following constructors are provided:
=over
=item B<new(%options)>: returns I<Mail::SPF::Mod>
I<Abstract>. Creates a new SPF record modifier object.
%options is a list of key/value pairs representing any of the following
options:
=over
=item B<text>
A I<string> denoting the unparsed text of the modifier.
=item B<name>
A I<string> denoting the name of the modifier. I<Required> if a generic
I<Mail::SPF::Mod> object (as opposed to a specific sub-class) is being
constructed.
=item B<domain_spec>
Either a plain I<string> or a I<Mail::SPF::MacroString> object denoting an
optional C<domain-spec> parameter of the mechanism.
=back
=cut
sub new {
my ($self, %options) = @_;
$self->class ne __PACKAGE__
or throw Mail::SPF::EAbstractClass;
$self = $self->SUPER::new(%options);
$self->{parse_text} = $self->{text} if not defined($self->{parse_text});
$self->{domain_spec} = Mail::SPF::MacroString->new(text => $self->{domain_spec})
if defined($self->{domain_spec})
and not UNIVERSAL::isa($self->{domain_spec}, 'Mail::SPF::MacroString');
return $self;
}
=item B<new_from_string($text, %options)>: returns I<Mail::SPF::Mod>;
throws I<Mail::SPF::ENothingToParse>, I<Mail::SPF::EInvalidMod>
I<Abstract>. Creates a new SPF record modifier object by parsing the string and
any options given.
=back
=head2 Class methods
The following class methods are provided:
=over
=item B<name_pattern>: returns I<Regexp>
Returns a regular expression that matches any legal modifier name.
=back
=head2 Instance methods
The following instance methods are provided:
=over
=cut
sub parse {
my ($self) = @_;
defined($self->{parse_text})
or throw Mail::SPF::ENothingToParse('Nothing to parse for modifier');
$self->parse_name();
$self->parse_params(TRUE);
$self->parse_end();
return;
}
sub parse_name {
my ($self) = @_;
if ($self->{parse_text} =~ s/^(${\$self->name_pattern})=//) {
$self->{name} = $1;
}
else {
throw Mail::SPF::EInvalidMod(
"Unexpected modifier name encountered in '" . $self->text . "'");
}
return;
}
sub parse_params {
my ($self, $required) = @_;
# Parse generic macro string of parameters text (should be overridden in sub-classes):
if ($self->{parse_text} =~ s/^(${\$self->macro_string_pattern})$//) {
$self->{params_text} = $1;
}
elsif ($required) {
throw Mail::SPF::EInvalidMacroString(
"Invalid macro string encountered in '" . $self->text . "'");
}
return;
}
sub parse_end {
my ($self) = @_;
$self->{parse_text} eq ''
or throw Mail::SPF::EJunkInTerm("Junk encountered in modifier '" . $self->text . "'");
delete($self->{parse_text});
return;
}
=item B<text>: returns I<string>; throws I<Mail::SPF::ENoUnparsedText>
Returns the unparsed text of the modifier. Throws a
I<Mail::SPF::ENoUnparsedText> exception if the modifier was created
synthetically instead of being parsed, and no text was provided.
=item B<name>: returns I<string>
Returns the name of the modifier.
=cut
# Read-only accessor:
__PACKAGE__->make_accessor('name', TRUE);
=item B<params>: returns I<string>
I<Abstract>. Returns the modifier's parameters formatted as a string.
A sub-class of Mail::SPF::Mod does not have to implement this method if it
supports no parameters, although this is highly unlikely.
=item B<stringify>: returns I<string>
Formats the modifier's name and parameters as a string and returns it. You can
simply use a Mail::SPF::Mod object as a string for the same effect, see
L<"OVERLOADING">.
=cut
sub stringify {
my ($self) = @_;
my $params = $self->can('params') ? $self->params : undef;
return sprintf(
'%s=%s',
$self->name,
defined($params) ? $params : ''
);
}
=item B<process>: throws I<Mail::SPF::Result>, I<Mail::SPF::Result::Error>,
I<Mail::SPF::Exception>
I<Abstract>. Processes the modifier. What that means depends on the actual
implementation in sub-classes. See L</MODIFIER TYPES> below.
This method is abstract and must be implemented by sub-classes of
Mail::SPF::Mod.
=back
=head1 MODIFIER TYPES
There are different basic types of modifiers, which are described below. All
of them are provided by the B<Mail::SPF::Mod> module.
=head2 Global modifiers - B<Mail::SPF::GlobalMod>
B<SPFv1> (RFC 4408) only knows "global" modifiers. A global modifier may
appear anywhere in an SPF record, but only once. During evaluation of the
record, global modifiers are processed after the last mechanism has been
evaluated and an SPF result has been determined.
=cut
package Mail::SPF::GlobalMod;
our @ISA = 'Mail::SPF::Mod';
sub new {
my ($self, %options) = @_;
$self->class ne __PACKAGE__
or throw Mail::SPF::EAbstractClass;
return $self->SUPER::new(%options);
}
=pod
The following additional class method is provided by B<Mail::SPF::GlobalMod>:
=over
=item B<precedence>: returns I<real>
I<Abstract>. Returns a I<real> number between B<0> and B<1> denoting the
precedence of the type of the global modifier. Global modifiers present in an
SPF record are processed in the order of their precedence values, B<0> meaning
"first".
This method is abstract and must be implemented by sub-classes of
Mail::SPF::GlobalMod.
=back
The following specific instance method is provided by B<Mail::SPF::GlobalMod>:
=over
=item B<process($server, $request, $result)>: throws I<Mail::SPF::Result>
I<Abstract>. Processes the modifier. What that means depends on the actual
implementation in sub-classes. Takes both a I<Mail::SPF::Server> and a
I<Mail::SPF::Request> object. As global modifiers are generally processed
I<after> an SPF result has already been determined, takes also the current
I<Mail::SPF::Result>. If the modifier wishes to modify the SPF result, it may
throw a different I<Mail::SPF::Result> object.
This method is abstract and must be implemented by sub-classes of
Mail::SPF::GlobalMod.
=back
=head2 Positional modifiers - B<Mail::SPF::PositionalMod>
B<Sender ID> (RFC 4406) introduces the concept of "positional" modifiers.
According to RFC 4406, a positional modifier must follow a mechanism and
applies to that, and only that, mechanism. However, because this definition is
not very useful, and because no positional modifiers have been defined based on
it as of yet, B<Mail::SPF> deviates from RFC 4406 as follows:
A positional modifier may appear anywhere in an SPF record, and it is stateful,
i.e. it applies to all mechanisms and modifiers that follow it. Positional
modifiers are generally multiple, i.e. they may appear any number of times
throughout the record. During evaluation of the record, positional modifiers
are processed at exactly the time when they are encountered by the evaluator.
Consequently, all positional modifiers are processed before an SPF result is
determined.
=cut
package Mail::SPF::PositionalMod;
our @ISA = 'Mail::SPF::Mod';
sub new {
my ($self, %options) = @_;
$self->class ne __PACKAGE__
or throw Mail::SPF::EAbstractClass;
return $self->SUPER::new(%options);
}
=pod
The following specific instance method is provided by
B<Mail::SPF::PositionalMod>:
=over
=item B<process($server, $request)>: throws I<Mail::SPF::Result::Error>, I<Mail::SPF::Exception>
I<Abstract>. Processes the modifier. What that means depends on the actual
implementation in sub-classes. Takes both a I<Mail::SPF::Server> and a
I<Mail::SPF::Request> object. As global modifiers are generally processed
I<before> an SPF result has been determined, no result object is available to
the modifier. The modifier can (at least at this time) not directly modify the
final SPF result, however it may throw an exception to signal an error
condition.
This method is abstract and must be implemented by sub-classes of
Mail::SPF::PositionalMod.
=back
=head2 Unknown modifiers - B<Mail::SPF::UnknownMod>
Both B<SPFv1> and B<Sender ID> allow unknown modifiers to appear in SPF records
in order to allow new modifiers to be introduced without breaking existing
implementations. Obviously, unknown modifiers are neither global nor
positional, but they may appear any number of times throughout the record and
are simply ignored during evaluation of the record.
=cut
package Mail::SPF::UnknownMod;
our @ISA = 'Mail::SPF::Mod';
=pod
Also obviously, B<Mail::SPF::UnknownMod> does not support a C<process> method.
The following specific instance method is provided by
B<Mail::SPF::UnknownMod>:
=over
=item B<params>: returns I<string>
Returns the modifier's unparsed value as a string.
=cut
sub params {
my ($self) = @_;
return $self->{params_text};
}
=back
=cut
package Mail::SPF::Mod;
=head1 OVERLOADING
If a Mail::SPF::Mod object is used as a I<string>, the C<stringify> method is
used to convert the object into a string.
=head1 SEE ALSO
L<Mail::SPF::Mod::Redirect>, L<Mail::SPF::Mod::Exp>
L<Mail::SPF>, L<Mail::SPF::Record>, L<Mail::SPF::Term>
L<http://tools.ietf.org/html/rfc4408>
For availability, support, and license information, see the README file
included with Mail::SPF.
=head1 AUTHORS
Julian Mehnle <julian@mehnle.net>, Shevek <cpan@anarres.org>
=cut
TRUE;
|