| 1 | # Copyrights 2001-2022 by [Mark Overmeer <markov@cpan.org>]. | ||||||||||||||||||||||||||||
| 2 | # For other contributors see ChangeLog. | ||||||||||||||||||||||||||||
| 3 | # See the manual pages for details on the licensing terms. | ||||||||||||||||||||||||||||
| 4 | # Pod stripped from pm file by OODoc 2.03. | ||||||||||||||||||||||||||||
| 5 | # This code is part of distribution Mail-Message. Meta-POD processed with | ||||||||||||||||||||||||||||
| 6 | # OODoc into POD and HTML manual-pages. See README.md | ||||||||||||||||||||||||||||
| 7 | # Copyright Mark Overmeer. Licensed under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | package Mail::Message::Head::SpamGroup; | ||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use vars '$VERSION'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 2 | $VERSION = '3.012'; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use base 'Mail::Message::Head::FieldGroup'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 2 | ▶ | use Carp 'confess'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | #------------------------------------------ | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 2 | my %fighters; | |||||||||||||||||||||||||||
| 25 | my $fighterfields; # one regexp for all fields | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 0 | ▶ | sub knownFighters() { keys %fighters } | ||||||||||||||||||||||||||
|
Subroutine
knownFighters: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | #------------------------------------------ | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | sub fighter($;@) | ||||||||||||||||||||||||||||
| 33 | 6 | ▶ | { my ($thing, $name) = (shift, shift); | ||||||||||||||||||||||||||
|
Subroutine
fighter: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 6 | ▶ | if(@_) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | 6 | { my %args = @_; | |||||||||||||||||||||||||||
| 37 | 6 | ▶ | defined $args{fields} or confess "Spamfighters require fields\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 6 | ▶ | defined $args{isspam} or confess "Spamfighters require isspam\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 6 | $fighters{$name} = \%args; | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 6 | my @fields = map { $_->{fields} } values %fighters; | |||||||||||||||||||||||||||
| 42 | 6 | local $" = '|'; | |||||||||||||||||||||||||||
| 43 | 6 | $fighterfields = qr/@fields/; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 6 | %{$fighters{$name}}; | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | BEGIN | ||||||||||||||||||||||||||||
| 51 | { __PACKAGE__->fighter( SpamAssassin => | ||||||||||||||||||||||||||||
| 52 | fields => qr/^X-Spam-/i | ||||||||||||||||||||||||||||
| 53 | , isspam => | ||||||||||||||||||||||||||||
| 54 | 0 | ▶ | sub { my ($sg, $head) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 55 | 0 | ▶ | my $f = $head->get('X-Spam-Flag') || $head->get('X-Spam-Status') | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$head->get('X-Spam-Flag') || $head->get('X-Spam-Status')
MC/DC0%0/2
$head->get('X-Spam-Flag') || $head->get('X-Spam-Status')
$head->get('X-Spam-Flag')
$head->get('X-Spam-Status')
Truth table0%0/3
A || B
A= $head->get('X-Spam-Flag')B= $head->get('X-Spam-Status')
| |||||||||||||||||||||||||||||
| 56 | or return 0; | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 0 | $f =~ m/^yes\b/i; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | , version => | ||||||||||||||||||||||||||||
| 61 | 0 | ▶ | sub { my ($sg, $head) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 62 | 0 | ▶ | my $assin = $head->get('X-Spam-Checker-Version') or return (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 0 | my ($software, $version) = $assin =~ m/^(.*)\s+(.*?)\s*$/; | |||||||||||||||||||||||||||
| 64 | 0 | ($software, $version); | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | 2 | ▶ | ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=2.2
| |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | __PACKAGE__->fighter( 'Habeas-SWE' => | ||||||||||||||||||||||||||||
| 69 | fields => qr/^X-Habeas-SWE/i | ||||||||||||||||||||||||||||
| 70 | , isspam => | ||||||||||||||||||||||||||||
| 71 | 0 | ▶ | sub { my ($sg, $head) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 72 | 0 | not $sg->habeasSweFieldsCorrect; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | 2 | ); | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | __PACKAGE__->fighter( MailScanner => | ||||||||||||||||||||||||||||
| 77 | fields => qr/^X-MailScanner/i | ||||||||||||||||||||||||||||
| 78 | , isspam => | ||||||||||||||||||||||||||||
| 79 | 0 | ▶ | sub { my ($sg, $head) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 80 | 0 | my $subject = $head->get('subject'); | |||||||||||||||||||||||||||
| 81 | 0 | $subject =~ m/^\{ (?:spam|virus)/xi; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | 2 | ); | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | #------------------------------------------ | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | sub from($@) | ||||||||||||||||||||||||||||
| 91 | 0 | ▶ | { my ($class, $from, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
from: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 92 | 0 | ▶ | my $head = $from->isa('Mail::Message::Head') ? $from : $from->head; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | 0 | my ($self, @detected); | |||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 0 | ▶ | my @types = defined $args{types} ? @{$args{types}} : $class->knownFighters; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 0 | foreach my $type (@types) | |||||||||||||||||||||||||||
| 98 | 0 | ▶ | { $self = $class->new(head => $head) unless defined $self; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | 0 | ▶ | next unless $self->collectFields($type); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 0 | my %fighter = $self->fighter($type); | |||||||||||||||||||||||||||
| 102 | my ($software, $version) | ||||||||||||||||||||||||||||
| 103 | 0 | ▶ | = defined $fighter{version} ? $fighter{version}->($self, $head) : (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 0 | $self->detected($type, $software, $version); | |||||||||||||||||||||||||||
| 106 | 0 | $self->spamDetected( $fighter{isspam}->($self, $head) ); | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 0 | push @detected, $self; | |||||||||||||||||||||||||||
| 109 | 0 | undef $self; # create a new one | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 0 | @detected; | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | #------------------------------------------ | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | sub collectFields($) | ||||||||||||||||||||||||||||
| 118 | 0 | ▶ | { my ($self, $set) = @_; | ||||||||||||||||||||||||||
|
Subroutine
collectFields: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 119 | 0 | ▶ | my %fighter = $self->fighter($set) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | or confess "ERROR: No spam set $set."; | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 0 | my @names = map { $_->name } $self->head->grepNames( $fighter{fields} ); | |||||||||||||||||||||||||||
| 123 | 0 | ▶ | return () unless @names; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 0 | $self->addFields(@names); | |||||||||||||||||||||||||||
| 126 | 0 | @names; | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | #------------------------------------------ | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 0 | ▶ | sub isSpamGroupFieldName($) { $_[1] =~ $fighterfields } | ||||||||||||||||||||||||||
|
Subroutine
isSpamGroupFieldName: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | #------------------------------------------ | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 2 | my @habeas_lines = | |||||||||||||||||||||||||||
| 138 | ( 'winter into spring', 'brightly anticipated', 'like Habeas SWE (tm)' | ||||||||||||||||||||||||||||
| 139 | , 'Copyright 2002 Habeas (tm)' | ||||||||||||||||||||||||||||
| 140 | , 'Sender Warranted Email (SWE) (tm). The sender of this' | ||||||||||||||||||||||||||||
| 141 | , 'email in exchange for a license for this Habeas' | ||||||||||||||||||||||||||||
| 142 | , 'warrant mark warrants that this is a Habeas Compliant' | ||||||||||||||||||||||||||||
| 143 | , 'Message (HCM) and not spam. Please report use of this' | ||||||||||||||||||||||||||||
| 144 | , 'mark in spam to <http://www.habeas.com/report/>.' | ||||||||||||||||||||||||||||
| 145 | ); | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | sub habeasSweFieldsCorrect(;$) | ||||||||||||||||||||||||||||
| 148 | 0 | ▶ | { my $self; | ||||||||||||||||||||||||||
|
Subroutine
habeasSweFieldsCorrect: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 0 | ▶ | if(@_ > 1) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 151 | 0 | { my ($class, $thing) = @_; | |||||||||||||||||||||||||||
| 152 | 0 | ▶ | my $head = $thing->isa('Mail::Message::Head') ? $thing : $thing->head; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 153 | 0 | ▶ | $self = $head->spamGroups('Habeas-SWE') or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | else | ||||||||||||||||||||||||||||
| 156 | 0 | { $self = shift; | |||||||||||||||||||||||||||
| 157 | 0 | my $type = $self->type; | |||||||||||||||||||||||||||
| 158 | 0 | ▶ | return unless defined $type && $type eq 'Habeas-SWE'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $type and $type eq "Habeas-SWE"
MC/DC0%0/2
defined $type and $type eq "Habeas-SWE"
defined $type
$type eq "Habeas-SWE"
Truth table0%0/3
A and B
A= defined $typeB= $type eq "Habeas-SWE"
| |||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 0 | my $head = $self->head; | |||||||||||||||||||||||||||
| 162 | 0 | ▶ | return if $self->fields != @habeas_lines; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 0 | ▶ | for(my $nr=1; $nr <= $#habeas_lines; $nr++) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 165 | 0 | ▶ | { my $f = $head->get("X-Habeas-SWE-$nr") or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 166 | 0 | ▶ | return if $f->unfoldedBody ne $habeas_lines[$nr-1]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | 0 | 1; | |||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | #------------------------------------------ | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | sub spamDetected(;$) | ||||||||||||||||||||||||||||
| 176 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
spamDetected: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 177 | 0 | ▶ | @_? ($self->{MMFS_spam} = shift) : $self->{MMFS_spam}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | #------------------------------------------ | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | 2 | 1; | |||||||||||||||||||||||||||