| 1 | # This code is part of Perl distribution Mail-Message version 4.05. | ||||||||||||||||||||||||||||
| 2 | # The POD got stripped from this file by OODoc version 3.06. | ||||||||||||||||||||||||||||
| 3 | # For contributors see file ChangeLog. | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | # This software is copyright (c) 2001-2026 by Mark Overmeer. | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | # This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 8 | # the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 9 | # SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | package Mail::Message::Head::SpamGroup;{ | ||||||||||||||||||||||||||||
| 13 | 2 | our $VERSION = '4.05'; | |||||||||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use parent 'Mail::Message::Head::FieldGroup'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 2 | ▶ | use Log::Report 'mail-message', import => [ qw/panic/ ]; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | #-------------------- | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 2 | my %fighters; | |||||||||||||||||||||||||||
| 26 | my $fighterfields; # one regexp for all fields | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 25 | ▶ | sub knownFighters() { keys %fighters } | ||||||||||||||||||||||||||
|
Subroutine
knownFighters: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | sub fighter($;@) | ||||||||||||||||||||||||||||
| 32 | 134 | ▶ | { my ($thing, $name) = (shift, shift); | ||||||||||||||||||||||||||
|
Subroutine
fighter: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 134 | ▶ | if(@_) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 6 | { my %args = @_; | |||||||||||||||||||||||||||
| 36 | 6 | ▶ | defined $args{fields} or panic "requires fields"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 6 | ▶ | defined $args{isspam} or panic "requires isspam"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 6 | $fighters{$name} = \%args; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 6 | my @fields = map $_->{fields}, values %fighters; | |||||||||||||||||||||||||||
| 41 | 6 | local $" = '|'; | |||||||||||||||||||||||||||
| 42 | 6 | $fighterfields = qr/@fields/; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 134 | %{$fighters{$name}}; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | BEGIN | ||||||||||||||||||||||||||||
| 50 | 2 | ▶ | { __PACKAGE__->fighter( SpamAssassin => | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.2
| |||||||||||||||||||||||||||||
| 51 | fields => qr/^X-Spam-/i, | ||||||||||||||||||||||||||||
| 52 | 8 | ▶ | isspam => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.4
| |||||||||||||||||||||||||||||
| 53 | 8 | my ($sg, $head) = @_; | |||||||||||||||||||||||||||
| 54 | 8 | ▶ | my $f = $head->get('X-Spam-Flag') || $head->get('X-Spam-Status'); | ||||||||||||||||||||||||||
|
Condition66%2/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 table66%2/3
A || B
A= $head->get('X-Spam-Flag')B= $head->get('X-Spam-Status')
| |||||||||||||||||||||||||||||
| 55 | 8 | ▶ | $f ? $f =~ m/^yes\b/i : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | }, | ||||||||||||||||||||||||||||
| 57 | 8 | ▶ | version => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 58 | 8 | my ($sg, $head) = @_; | |||||||||||||||||||||||||||
| 59 | 8 | ▶ | my $assin = $head->get('X-Spam-Checker-Version') or return (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 8 | my ($software, $version) = $assin =~ m/^(.*)\s+(.*?)\s*$/; | |||||||||||||||||||||||||||
| 61 | 8 | ($software, $version); | |||||||||||||||||||||||||||
| 62 | }, | ||||||||||||||||||||||||||||
| 63 | 2 | ); | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | __PACKAGE__->fighter( 'Habeas-SWE' => | ||||||||||||||||||||||||||||
| 66 | fields => qr/^X-Habeas-SWE/i, | ||||||||||||||||||||||||||||
| 67 | 26 | ▶ | isspam => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 68 | 26 | my ($sg, $head) = @_; | |||||||||||||||||||||||||||
| 69 | 26 | not $sg->habeasSweFieldsCorrect; | |||||||||||||||||||||||||||
| 70 | }, | ||||||||||||||||||||||||||||
| 71 | 2 | ); | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | __PACKAGE__->fighter( MailScanner => | ||||||||||||||||||||||||||||
| 74 | fields => qr/^X-MailScanner/i, | ||||||||||||||||||||||||||||
| 75 | 0 | ▶ | isspam => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 76 | 0 | my ($sg, $head) = @_; | |||||||||||||||||||||||||||
| 77 | 0 | my $subject = $head->get('subject'); | |||||||||||||||||||||||||||
| 78 | 0 | $subject =~ m/^\{ (?:spam|virus)/xi; | |||||||||||||||||||||||||||
| 79 | }, | ||||||||||||||||||||||||||||
| 80 | 2 | ); | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | sub from($@) | ||||||||||||||||||||||||||||
| 85 | 44 | ▶ | { my ($class, $from, %args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
from: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||
| 86 | 44 | ▶ | my $head = $from->isa('Mail::Message::Head') ? $from : $from->head; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | 44 | my ($self, @detected); | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 44 | ▶ | my @types = defined $args{types} ? @{$args{types}} : $class->knownFighters; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 44 | foreach my $type (@types) | |||||||||||||||||||||||||||
| 92 | 94 | ▶ | { $self = $class->new(head => $head) unless defined $self; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | 94 | ▶ | $self->collectFields($type) or next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 34 | my %fighter = $self->fighter($type); | |||||||||||||||||||||||||||
| 96 | 34 | ▶ | my ($software, $version) = defined $fighter{version} ? $fighter{version}->($self, $head) : (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 34 | $self->detected($type, $software, $version); | |||||||||||||||||||||||||||
| 99 | 34 | $self->spamDetected( $fighter{isspam}->($self, $head) ); | |||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 34 | push @detected, $self; | |||||||||||||||||||||||||||
| 102 | 34 | undef $self; # create a new one | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 44 | @detected; | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | sub collectFields($) | ||||||||||||||||||||||||||||
| 109 | 94 | ▶ | { my ($self, $set) = @_; | ||||||||||||||||||||||||||
|
Subroutine
collectFields: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 110 | 94 | ▶ | my %fighter = $self->fighter($set) or panic "no spam set $set"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 94 | my @names = map $_->name, $self->head->grepNames($fighter{fields}); | |||||||||||||||||||||||||||
| 113 | 94 | ▶ | $self->addFields(@names) if @names; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | 94 | @names; | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 0 | ▶ | sub isSpamGroupFieldName($) { $_[1] =~ $fighterfields } | ||||||||||||||||||||||||||
|
Subroutine
isSpamGroupFieldName: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 2 | my @habeas_lines = ( | |||||||||||||||||||||||||||
| 122 | 'winter into spring', 'brightly anticipated', 'like Habeas SWE (tm)', | ||||||||||||||||||||||||||||
| 123 | 'Copyright 2002 Habeas (tm)', | ||||||||||||||||||||||||||||
| 124 | 'Sender Warranted Email (SWE) (tm). The sender of this', | ||||||||||||||||||||||||||||
| 125 | 'email in exchange for a license for this Habeas', | ||||||||||||||||||||||||||||
| 126 | 'warrant mark warrants that this is a Habeas Compliant', | ||||||||||||||||||||||||||||
| 127 | 'Message (HCM) and not spam. Please report use of this', | ||||||||||||||||||||||||||||
| 128 | 'mark in spam to <http://www.habeas.com/report/>.', | ||||||||||||||||||||||||||||
| 129 | ); | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | sub habeasSweFieldsCorrect(;$) | ||||||||||||||||||||||||||||
| 132 | 46 | ▶ | { my $self; | ||||||||||||||||||||||||||
|
Subroutine
habeasSweFieldsCorrect: called CC=10 SCAR=23.4
Pod
documented
| |||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 46 | ▶ | if(@_ > 1) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 135 | 12 | { my ($class, $thing) = @_; | |||||||||||||||||||||||||||
| 136 | 12 | ▶ | my $head = $thing->isa('Mail::Message::Head') ? $thing : $thing->head; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 137 | 12 | ▶ | $self = $head->spamGroups('Habeas-SWE') or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | else | ||||||||||||||||||||||||||||
| 140 | 34 | { $self = shift; | |||||||||||||||||||||||||||
| 141 | 34 | my $type = $self->type; | |||||||||||||||||||||||||||
| 142 | 34 | ▶ | defined $type && $type eq 'Habeas-SWE' or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/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 table33%1/3
A and B
A= defined $typeB= $type eq "Habeas-SWE"
| |||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | 46 | my $head = $self->head; | |||||||||||||||||||||||||||
| 146 | 46 | ▶ | $self->fields == @habeas_lines or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 32 | ▶ | for(my $nr=1; $nr <= $#habeas_lines; $nr++) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 149 | 228 | ▶ | { my $f = $head->get("X-Habeas-SWE-$nr") or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 150 | 228 | ▶ | $f->unfoldedBody eq $habeas_lines[$nr-1] or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 25 | 1; | |||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | sub spamDetected(;$) | ||||||||||||||||||||||||||||
| 158 | 34 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
spamDetected: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 159 | 34 | ▶ | @_? ($self->{MMFS_spam} = shift) : $self->{MMFS_spam}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 2 | 1; | |||||||||||||||||||||||||||