| 1 | package Log::Saftpresse::Plugin::Postfix::Delivered; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | # ABSTRACT: plugin to gather postfix delivered messages statistics | ||||||||||||||||||||||||||||
| 6 | 1 | our $VERSION = '1.5'; # VERSION | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Log::Saftpresse::Plugin::Postfix::Utils qw( verp_mung ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | requires 'deferred_detail'; | |||||||||||||||||||||||||||
| 11 | 1 | requires 'ignore_case'; | |||||||||||||||||||||||||||
| 12 | 1 | requires 'deferred_detail'; | |||||||||||||||||||||||||||
| 13 | 1 | requires 'message_detail'; | |||||||||||||||||||||||||||
| 14 | 1 | requires 'bounce_detail'; | |||||||||||||||||||||||||||
| 15 | 1 | requires 'extended'; | |||||||||||||||||||||||||||
| 16 | 1 | requires 'uucp_mung'; | |||||||||||||||||||||||||||
| 17 | 1 | requires 'ignore_case'; | |||||||||||||||||||||||||||
| 18 | 1 | requires 'verp_mung'; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | sub process_delivered { | ||||||||||||||||||||||||||||
| 21 | 0 | ▶ | my ( $self, $stash, $notes ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
process_delivered: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 22 | 0 | my $service = $stash->{'service'}; | |||||||||||||||||||||||||||
| 23 | 0 | my $message = $stash->{'message'}; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 0 | ▶ | if( $service eq 'smtpd') { return; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 0 | my ($addr, $size, $relay, $delay, $status, $text); | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 0 | ▶ | if(( ($addr, $size) = $message =~ /from=<([^>]*)>, size=(\d+)/) == 2) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 30 | 0 | $stash->{'size'} = $size; | |||||||||||||||||||||||||||
| 31 | 0 | $stash->{'from'} = $addr; | |||||||||||||||||||||||||||
| 32 | 0 | $self->process_from( $stash, $notes ); | |||||||||||||||||||||||||||
| 33 | } elsif( ( | ||||||||||||||||||||||||||||
| 34 | ($addr, $relay, $delay, $status, $text) = $message =~ | ||||||||||||||||||||||||||||
| 35 | /to=<([^>]*)>, (?:orig_to=<[^>]*>, )?relay=([^,]+), (?:conn_use=[^,]+, )?delay=([^,]+), (?:delays=[^,]+, )?(?:dsn=[^,]+, )?status=(\S+)(.*)$/ | ||||||||||||||||||||||||||||
| 36 | ) >= 4) { | ||||||||||||||||||||||||||||
| 37 | 0 | $stash->{'to'} = $addr; | |||||||||||||||||||||||||||
| 38 | 0 | $stash->{'relay'} = $relay; | |||||||||||||||||||||||||||
| 39 | 0 | $stash->{'delay'} = $delay; | |||||||||||||||||||||||||||
| 40 | 0 | $stash->{'status'} = $status; | |||||||||||||||||||||||||||
| 41 | 0 | ▶ | if( $text =~ /forwarded as / ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | 0 | $stash->{'forwarded'} = 'true'; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | 0 | $self->process_to( $stash, $notes ); | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 0 | return; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | sub process_to { | ||||||||||||||||||||||||||||
| 51 | 0 | ▶ | my ( $self, $stash, $notes ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
process_to: not called CC=16 SCAR=56.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 52 | 0 | my $message = $stash->{'message'}; | |||||||||||||||||||||||||||
| 53 | 0 | my $qid = $stash->{'queue_id'}; | |||||||||||||||||||||||||||
| 54 | 0 | my $delay = $stash->{'delay'}; | |||||||||||||||||||||||||||
| 55 | 0 | my $status = $stash->{'status'}; | |||||||||||||||||||||||||||
| 56 | 0 | my $time = $stash->{'time'}; | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 0 | my $addr = $stash->{'to'} = $self->_get_addr_str( $stash->{'to'} ); | |||||||||||||||||||||||||||
| 59 | 0 | (my $domAddr = $addr) =~ s/^[^@]+\@//; # get domain only | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 0 | my $relay = $stash->{'relay'}; | |||||||||||||||||||||||||||
| 62 | 0 | ▶ | $relay = lc($relay) if( $self->ignore_case ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | ▶ | if( $self->extended && ( my $from = $notes->get('from-'.$qid) ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->extended and my $from = $notes->get('from-' . $qid)
MC/DC0%0/2
$self->extended and my $from = $notes->get('from-' . $qid)
$self->extended
my $from = $notes->get('from-' . $qid)
Truth table0%0/3
A and B
A= $self->extendedB= my $from = $notes->get('from-' . $qid)
| |||||||||||||||||||||||||||||
| 65 | 0 | $stash->{'from'} = $from; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | ▶ | if($status eq 'sent') { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 69 | # was it actually forwarded, rather than delivered? | ||||||||||||||||||||||||||||
| 70 | 0 | ▶ | if( defined $stash->{'forwarded'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 0 | $self->incr_host_one($stash, 'forwarded'); | |||||||||||||||||||||||||||
| 72 | 0 | return; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | 0 | $self->incr_host_one( $stash, 'sent', 'total'); | |||||||||||||||||||||||||||
| 75 | 0 | $self->incr_host_one( $stash, 'sent', 'by_domain', $domAddr); | |||||||||||||||||||||||||||
| 76 | 0 | $self->incr_host( $stash, 'sent', 'delay', 'by_domain', $domAddr, $delay); | |||||||||||||||||||||||||||
| 77 | 0 | $self->incr_host_max( $stash, 'sent', 'max_delay', 'by_domain', $domAddr, $delay); | |||||||||||||||||||||||||||
| 78 | 0 | $self->incr_host_one( $stash, 'sent', 'by_rcpt', $addr); | |||||||||||||||||||||||||||
| 79 | 0 | ▶ | if( $self->saftsumm_mode ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | 0 | $self->incr_host_one( $stash, 'sent', 'per_hr', $time->hour); | |||||||||||||||||||||||||||
| 81 | 0 | $self->incr_host_one( $stash, 'sent', 'per_day', $time->ymd); | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 0 | ▶ | if( my $size = $notes->get('size-'.$qid) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | 0 | $stash->{'size'} = $size; | |||||||||||||||||||||||||||
| 86 | 0 | $self->incr_host( $stash, 'sent', 'size', 'by_domain', $domAddr, $size); | |||||||||||||||||||||||||||
| 87 | 0 | $self->incr_host( $stash, 'sent', 'size', 'by_rcpt', $addr, $size); | |||||||||||||||||||||||||||
| 88 | 0 | $self->incr_host( $stash, 'sent', 'size', 'total', $size); | |||||||||||||||||||||||||||
| 89 | } else { | ||||||||||||||||||||||||||||
| 90 | 0 | $self->incr_host_one( $stash, 'sent', 'size', 'no_size'); | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | # [benning] hum? | ||||||||||||||||||||||||||||
| 93 | # push(@{$msgDetail{$qid}}, "(sender not in log)") if($opts{'e'}); | ||||||||||||||||||||||||||||
| 94 | # push(@{$msgDetail{$qid}}, $addr) if($opts{'e'}); | ||||||||||||||||||||||||||||
| 95 | } elsif($status eq 'deferred') { | ||||||||||||||||||||||||||||
| 96 | 0 | ▶ | if( $self->deferred_detail > 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | 0 | my ($deferredReas) = $message =~ /, status=deferred \(([^\)]+)/; | |||||||||||||||||||||||||||
| 98 | 0 | ▶ | unless( $self->message_detail ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | 0 | $deferredReas = said_string_trimmer($deferredReas, 65); | |||||||||||||||||||||||||||
| 100 | 0 | $deferredReas =~ s/^\d{3} //; | |||||||||||||||||||||||||||
| 101 | 0 | $deferredReas =~ s/^connect to //; | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | 0 | $self->incr_host_one( $stash, 'deferred', $stash->{'service'}, $deferredReas); | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | 0 | $self->incr_host_one( $stash, 'deferred', 'total'); | |||||||||||||||||||||||||||
| 106 | 0 | ▶ | if( $self->saftsumm_mode ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | 0 | $self->incr_host_one( $stash, 'deferred', 'per_hr', $time->hour); | |||||||||||||||||||||||||||
| 108 | 0 | $self->incr_host_one( $stash, 'deferred', 'per_day', $time->ymd); | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | 0 | $self->incr_host_one( $stash, 'deferred', 'by_domain', $domAddr); | |||||||||||||||||||||||||||
| 111 | 0 | $self->incr_host_max( $stash, 'deferred', 'max_delay', 'by_domain', $domAddr, $delay); | |||||||||||||||||||||||||||
| 112 | } elsif($status eq 'bounced') { | ||||||||||||||||||||||||||||
| 113 | 0 | ▶ | if( $self->bounce_detail > 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | 0 | my ($bounceReas) = $message =~ /, status=bounced \((.+)\)/; | |||||||||||||||||||||||||||
| 115 | 0 | ▶ | unless( $self->message_detail ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | 0 | $bounceReas = said_string_trimmer($bounceReas, 66); | |||||||||||||||||||||||||||
| 117 | 0 | $bounceReas =~ s/^\d{3} //; | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | 0 | $self->incr_host_one( $stash, 'bounced', $relay, $bounceReas); | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | 0 | $self->incr_host_one( $stash, 'bounced', 'total'); | |||||||||||||||||||||||||||
| 122 | 0 | ▶ | if( $self->saftsumm_mode ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | 0 | $self->incr_host_one( $stash, 'bounced', 'per_hr', $time->hour); | |||||||||||||||||||||||||||
| 124 | 0 | $self->incr_host_one( $stash, 'bounced', 'per_day', $time->ymd); | |||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | sub process_from { | ||||||||||||||||||||||||||||
| 130 | 0 | ▶ | my ( $self, $stash, $notes ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
process_from: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 131 | 0 | my $qid = $stash->{'queue_id'}; | |||||||||||||||||||||||||||
| 132 | 0 | my $addr = $stash->{'from'} = $self->_get_addr_str( $stash->{'from'} ); | |||||||||||||||||||||||||||
| 133 | 0 | my $size = $stash->{'size'}; | |||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 0 | ▶ | return if( $notes->get('size-'.$qid) ); # avoid double-counting! | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | 0 | $notes->set('size-'.$qid => $size); | |||||||||||||||||||||||||||
| 137 | 0 | ▶ | $notes->set('from-'.$qid => $addr) if( $self->extended ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | # Avoid counting forwards | ||||||||||||||||||||||||||||
| 140 | 0 | ▶ | if( my $client = $notes->get('client-'.$qid) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 141 | # Get the domain out of the sender's address. If there is | ||||||||||||||||||||||||||||
| 142 | # none: Use the client hostname/IP-address | ||||||||||||||||||||||||||||
| 143 | 0 | my $domAddr; | |||||||||||||||||||||||||||
| 144 | 0 | ▶ | unless((($domAddr = $addr) =~ s/^[^@]+\@(.+)$/$1/) == 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 145 | 0 | ▶ | $domAddr = $client eq "pickup"? $addr : $client; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 0 | $self->incr_host_one( $stash, 'recieved', 'total'); | |||||||||||||||||||||||||||
| 149 | 0 | $self->incr_host( $stash, 'recieved', 'size', 'total', $size); | |||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 0 | $self->incr_host_one( $stash, 'recieved', 'by_domain', $domAddr); | |||||||||||||||||||||||||||
| 152 | 0 | $self->incr_host( $stash, 'recieved', 'size', 'by_domain', $domAddr, $size); | |||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 0 | $self->incr_host_one( $stash, 'recieved', 'by_sender', $addr); | |||||||||||||||||||||||||||
| 155 | 0 | $self->incr_host( $stash, 'recieved', 'size', 'by_sender', $addr, $size); | |||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||
| 157 | 0 | return; | |||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | sub _get_addr_str { | ||||||||||||||||||||||||||||
| 161 | 0 | ▶ | my ( $self, $addr ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_get_addr_str: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | 0 | ▶ | if($addr) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 164 | 0 | ▶ | if( $self->uucp_mung && | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->uucp_mung and $addr =~ /^(.*!)*([^!]+)!([^!\@]+)@([^\.]+)$/
MC/DC0%0/2
$self->uucp_mung and $addr =~ /^(.*!)*([^!]+)!([^!\@]+)@([^\.]+)$/
$self->uucp_mung
$addr =~ /^(.*!)*([^!]+)!([^!\@]+)@([^\.]+)$/
Truth table0%0/3
A and B
A= $self->uucp_mungB= $addr =~ /^(.*!)*([^!]+)!([^!\@]+)@([^\.]+)$/
| |||||||||||||||||||||||||||||
| 165 | $addr =~ /^(.*!)*([^!]+)!([^!@]+)@([^\.]+)$/) { | ||||||||||||||||||||||||||||
| 166 | 0 | ▶ | $addr = "$4!" . ($1? "$1" : "") . $3 . "\@$2"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | 0 | ▶ | $addr =~ s/(@.+)/\L$1/ unless( $self->ignore_case ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 169 | 0 | ▶ | $addr = lc($addr) if( $self->ignore_case ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 170 | 0 | $addr = verp_mung( $self->verp_mung, $addr); | |||||||||||||||||||||||||||
| 171 | } else { | ||||||||||||||||||||||||||||
| 172 | 0 | $addr = "<>" | |||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | 0 | return( $addr ); | |||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | 1 | 1; | |||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | __END__ | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | =pod | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | =encoding UTF-8 | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | =head1 NAME | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | Log::Saftpresse::Plugin::Postfix::Delivered - plugin to gather postfix delivered messages statistics | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | =head1 VERSION | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | version 1.5 | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | Markus Benning <ich@markusbenning.de> | ||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | This software is Copyright (c) 1998 by James S. Seymour, 2015 by Markus Benning. | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | This is free software, licensed under: | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | The GNU General Public License, Version 2, June 1991 | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | =cut | ||||||||||||||||||||||||||||