« blib/lib/Mail/DMARC/Report/Aggregate/Record/Auth_Results/DKIM.pm
↑ Summary
blib/lib/Mail/DMARC/Report/Aggregate/Record.pm »
| 1 | package Mail::DMARC::Report::Aggregate::Record::Auth_Results::SPF; | ||
| 2 | our $VERSION = '2.20260827'; | ||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | use feature 'signatures'; | ||
| 6 | no warnings 'experimental::args_array_with_signatures'; ## no critic (ProhibitNoWarnings) | ||
| 7 | |||
| 8 | use Carp; | ||
| 9 | use parent 'Mail::DMARC::Base'; | ||
| 10 | |||
| 11 | sub new( $class, @args ) { | ||
| 12 | |||
| 13 | my $self = bless {}, $class; | ||
| 14 | |||
| 15 | if ( !@args ) { | ||
| 16 | return $self; | ||
| 17 | } | ||
| 18 | |||
| 19 | # a bare hash | ||
| 20 | return $self->_from_hash(@args) if @args > 1; | ||
| 21 | |||
| 22 | my $spf = shift @args; | ||
| 23 | return $spf if ref $spf eq $class; | ||
| 24 | |||
| 25 | return $self->_from_hashref($spf) if 'HASH' eq ref $spf; | ||
| 26 | |||
| 27 | croak "invalid spf argument"; | ||
| 28 | } | ||
| 29 | |||
| 30 | sub domain( $self, $value = undef ) { | ||
| 31 | return $self->{domain} if @_ == 1; | ||
| 32 | return $self->{domain} = lc $value; | ||
| 33 | } | ||
| 34 | |||
| 35 | sub result( $self, $value = undef ) { | ||
| 36 | return $self->{result} if @_ == 1; | ||
| 37 | croak if !$self->is_valid_spf_result($value); | ||
| 38 | return $self->{result} = $value; | ||
| 39 | } | ||
| 40 | |||
| 41 | sub scope( $self, $value = undef ) { | ||
| 42 | return $self->{scope} if @_ == 1; | ||
| 43 | croak if !$self->is_valid_spf_scope($value); | ||
| 44 | return $self->{scope} = $value; | ||
| 45 | } | ||
| 46 | |||
| 47 | sub _from_hash( $self, %args ) { | ||
| 48 | |||
| 49 | foreach my $key ( keys %args ) { | ||
| 50 | |||
| 51 | # scope is frequently absent on received reports | ||
| 52 | next if ( $key eq 'scope' && !$args{$key} ); | ||
| 53 | $self->$key( $args{$key} ); | ||
| 54 | } | ||
| 55 | |||
| 56 | $self->is_valid; | ||
| 57 | return $self; | ||
| 58 | } | ||
| 59 | |||
| 60 | sub _from_hashref( $self, $spf ) { | ||
| 61 | return $self->_from_hash( %{$spf} ); | ||
| 62 | } | ||
| 63 | |||
| 64 | sub is_valid($self) { | ||
| 65 | |||
| 66 | foreach my $f (qw/ domain result scope /) { | ||
| 67 | next if $self->{$f}; | ||
| 68 | if ( $f ne 'scope' ) { | ||
| 69 | |||
| 70 | # quite a few DMARC reporters don't include scope | ||
| 71 | warn "SPF $f is required but missing!\n"; | ||
| 72 | } | ||
| 73 | return 0; | ||
| 74 | } | ||
| 75 | |||
| 76 | if ( $self->{result} =~ /^pass$/i && !$self->{domain} ) { | ||
| 77 | warn "SPF pass MUST include the RFC5321.MailFrom domain!\n"; | ||
| 78 | return 0; | ||
| 79 | } | ||
| 80 | |||
| 81 | return 1; | ||
| 82 | } | ||
| 83 | |||
| 84 | 1; | ||
| 85 | |||
| 86 | __END__ | ||
| 87 | |||
| 88 | =pod | ||
| 89 | |||
| 90 | =head1 NAME | ||
| 91 | |||
| 92 | Mail::DMARC::Report::Aggregate::Record::Auth_Results::SPF - auth_results/spf section of a DMARC aggregate record | ||
| 93 | |||
| 94 | =head1 VERSION | ||
| 95 | |||
| 96 | version 2.20260827 | ||
| 97 | |||
| 98 | =head1 AUTHORS | ||
| 99 | |||
| 100 | =over 4 | ||
| 101 | |||
| 102 | =item * | ||
| 103 | |||
| 104 | Matt Simerson <msimerson@cpan.org> | ||
| 105 | |||
| 106 | =item * | ||
| 107 | |||
| 108 | Davide Migliavacca <shari@cpan.org> | ||
| 109 | |||
| 110 | =item * | ||
| 111 | |||
| 112 | Marc Bradshaw <marc@marcbradshaw.net> | ||
| 113 | |||
| 114 | =back | ||
| 115 | |||
| 116 | =head1 COPYRIGHT AND LICENSE | ||
| 117 | |||
| 118 | This software is copyright (c) 2026 by Matt Simerson. | ||
| 119 | |||
| 120 | This is free software; you can redistribute it and/or modify it under | ||
| 121 | the same terms as the Perl 5 programming language system itself. | ||
| 122 | |||
| 123 | =cut |