Audit/KillDups.pm

filter: Statementstmt 40.4% 19 / 47 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 80.0% 4 / 5 Podpod 0.0% 0 / 1 totaltotal 26.7% 23 / 86 CC 12 SCAR 47.6
CC
12
Cov
26%
killdups
156.0
BEGIN
1.0
BEGIN
1.0
CRAP 117.2
↑ Summary Audit.pm »
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 package Mail::Audit::KillDups;
3 {
4 1 $Mail::Audit::KillDups::VERSION = '2.228';
5 }
6 # ABSTRACT: Mail::Audit plugin for duplicate suppression
7 1 ▶use Mail::Audit;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 our $dupfile = ".msgid-cache";
9 1 our $cache_bytes = 10000;
10  
11 package Mail::Audit;
12 {
13 1 $Mail::Audit::VERSION = '2.228';
14 }
15 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Fcntl;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 0 ▶sub killdups {
Subroutine killdups: not called CC=12 SCAR=50.5
Pod undocumented
19 0 my $self = shift;
20 0 ▶ my $mid = shift || $self->get("Message-Id");
Condition0%0/3
shift() || $self->get('Message-Id')
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $self->get('Message-Id')
shift() $self->get('Message-Id')
Truth table0%0/3
A || B
A= shift()B= $self->get('Message-Id')
ABresult
1X1
011
000
21 0 my $end_of_ring = 0;
22 0 my $current_pos;
23  
24 0 ▶ unless (length $mid) {
Branch: 1 branch
BranchTrueFalseTotal
unless (length $mid) 0 0 0
25 0 $self->_log(1, "message has no message-id; skipping duplicate check");
26 0 return;
27 }
28  
29 0 ▶ unless (sysopen MSGID, $Mail::Audit::KillDups::dupfile, O_RDWR | O_CREAT) {
Branch: 1 branch
BranchTrueFalseTotal
unless (sysopen MSGID, $Mail::Audit::KillDups::dupfile, 66) 0 0 0
30 0 $self->_log(1, "Error opening $Mail::Audit::KillDups::dupfile: $!");
31 0 return 1;
32 }
33  
34 0 chomp $mid;
35 0 ▶ while (<MSGID>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline MSGID)) 0 0 0
36 0 chomp;
37 0 ▶ if ($_ eq $mid) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ eq $mid) 0 0 0
38 0 $self->_log(1, "Duplicate, ignoring");
39 0 $self->ignore;
40 0 return -1;
41 }
42  
43 0 $current_pos = tell MSGID;
44 0 ▶ if ($current_pos > $Mail::Audit::KillDups::cache_bytes && $end_of_ring == 0)
Branch: 2 branches
BranchTrueFalseTotal
if ($current_pos > $Mail::Audit::KillDups::cache_bytes and $end_of_ring == 0) { } 0 0 0
elsif ($_ eq '' and $end_of_ring == 0 and $current_pos > 0) { } 0 0 0
Condition0%0/3
$current_pos > $Mail::Audit::KillDups::cache_bytes and $end_of_ring == 0
!ll&&!rl&&r
000
MC/DC0%0/2
$current_pos > $Mail::Audit::KillDups::cache_bytes and $end_of_ring == 0
$current_pos > $Mail::Audit::KillDups::cache_bytes $end_of_ring == 0
Truth table0%0/3
A and B
A= $current_pos > $Mail::Audit::KillDups::cache_bytesB= $end_of_ring == 0
ABresult
0X0
100
111
45 {
46 # we've gotten too big, write this mid back at the top of the file
47 0 last;
48 ▶ } elsif ($_ eq "" && $end_of_ring == 0 && $current_pos > 0) {
Condition0%0/6
$_ eq "" and $end_of_ring == 0 and $current_pos > 0
!ll&&!rl&&r
000
$_ eq "" and $end_of_ring == 0
!ll&&!rl&&r
000
MC/DC0%0/3
$_ eq "" and $end_of_ring == 0 and $current_pos > 0
$_ eq "" $end_of_ring == 0 $current_pos > 0
Truth table0%0/4
A and B and C
A= $_ eq ""B= $end_of_ring == 0C= $current_pos > 0
ABCresult
0XX0
10X0
1100
1111
49 # Found the end of the ring buffer, so save position.
50 0 $end_of_ring = $current_pos - 1;
51 }
52 }
53  
54 # Didn't find mid, so write it to the end of the ring buffer
55 0 ▶ unless (seek MSGID, $end_of_ring, 0) {
Branch: 1 branch
BranchTrueFalseTotal
unless (seek MSGID, $end_of_ring, 0) 0 0 0
56 0 $self->_log(1, "seek to position $end_of_ring failed: $!");
57 0 close MSGID;
58 0 return 1;
59 }
60  
61 0 print MSGID "$mid\n\n";
62 0 close MSGID;
63  
64 0 return;
65 }
66  
67 1 1;
68  
69 __END__
↑ Summary Audit.pm »