Saftpresse/Plugin/Postfix/Utils.pm

filter: Statementstmt 39.0% 16 / 41 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 50.0% 4 / 8 Podpod 0.0% 0 / 4 totaltotal 25.3% 20 / 79 SCAR 41.1
CC
11
Cov
25%
said_string_trimmer
20.0
postfix_remote
20.0
string_trimmer
12.0
CRAP 61.2
« Saftpresse/Slurp.pm ↑ Summary Saftpresse/Output/JSON.pm »
1 package Log::Saftpresse::Plugin::Postfix::Utils;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 # ABSTRACT: class with collection of some utility functions
7 1 our $VERSION = '1.5'; # VERSION
8  
9 1 ▶use Log::Saftpresse::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 our (@ISA, @EXPORT_OK);
12  
13 BEGIN {
14 1 ▶ require Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 @ISA = qw(Exporter);
17 1 @EXPORT_OK = qw(
18 &string_trimmer &said_string_trimmer
19 &gimme_domain &postfix_remote &verp_mung
20 );
21 }
22  
23 # Trim a "said:" string, if necessary. Add elipses to show it.
24 # FIXME: This sometimes elides The Wrong Bits, yielding
25 # summaries that are less useful than they could be.
26 sub said_string_trimmer {
27 0 ▶ my($trimmedString, $maxLen) = @_;
Subroutine said_string_trimmer: not called CC=4 SCAR=30.0
Pod undocumented
28  
29 0 ▶ while(length($trimmedString) > $maxLen) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $trimmedString > $maxLen) 0 0 0
30 0 ▶ if($trimmedString =~ /^.* said: /) {
Branch: 2 branches
BranchTrueFalseTotal
if ($trimmedString =~ /^.* said: /) { } 0 0 0
elsif ($trimmedString =~ /^.*: */) { } 0 0 0
31 0 $trimmedString =~ s/^.* said: //;
32 } elsif($trimmedString =~ /^.*: */) {
33 0 $trimmedString =~ s/^.*?: *//;
34 } else {
35 0 $trimmedString = substr($trimmedString, 0, $maxLen - 3) . "...";
36 0 last;
37 }
38 }
39  
40 0 return $trimmedString;
41 }
42  
43 # Trim a string, if necessary. Add elipses to show it.
44 sub string_trimmer {
45 0 ▶ my($trimmedString, $maxLen, $doNotTrim) = @_;
Subroutine string_trimmer: not called CC=3 SCAR=24.8
Pod undocumented
46  
47 0 ▶ $trimmedString = substr($trimmedString, 0, $maxLen - 3) . "..."
Branch: 1 branch
BranchTrueFalseTotal
if not $doNotTrim and length $trimmedString > $maxLen 0 0 0
Condition0%0/3
not $doNotTrim and length $trimmedString > $maxLen
!ll&&!rl&&r
000
MC/DC0%0/2
not $doNotTrim and length $trimmedString > $maxLen
not $doNotTrim length $trimmedString > $maxLen
Truth table0%0/3
not(A) and B
A= not $doNotTrimB= length $trimmedString > $maxLen
ABresult
0X0
100
111
48 if(! $doNotTrim && (length($trimmedString) > $maxLen));
49 0 return $trimmedString;
50 }
51  
52 # if there's a real domain: uses that. Otherwise uses the IP addr.
53 # Lower-cases returned domain name.
54 #
55 # Optional bit of code elides the last octet of an IPv4 address.
56 # (In case one wants to assume an IPv4 addr. is a dialup or other
57 # dynamic IP address in a /24.)
58 # Does nothing interesting with IPv6 addresses.
59 # FIXME: I think the IPv6 address parsing may be weak
60  
61 sub postfix_remote {
62 0 ▶ $_ = $_[0];
Subroutine postfix_remote: not called CC=4 SCAR=30.0
Pod undocumented
63 0 my($domain, $ipAddr);
64  
65 # split domain/ipaddr into separates
66 # newer versions of Postfix have them "dom.ain[i.p.add.ress]"
67 # older versions of Postfix have them "dom.ain/i.p.add.ress"
68 0 ▶ unless((($domain, $ipAddr) = /^([^\[]+)\[((?:\d{1,3}\.){3}\d{1,3})\]/) == 2 ||
Branch: 1 branch
BranchTrueFalseTotal
unless ((() = /^([^\[]+)\[((?:\d{1,3}\.){3}\d{1,3})\]/) == 2 or (() = m[^([^/]+)/([0-9a-f.:]+)]i) == 2) 0 0 0
Condition0%0/3
(() = /^([^\[]+)\[((?:\d{1,3}\.){3}\d{1,3})\]/) == 2 or (() = m[^([^/]+)/([0-9a-f.:]+)]i) == 2
l!l&&r!l&&!r
000
MC/DC0%0/2
(() = /^([^\[]+)\[((?:\d{1,3}\.){3}\d{1,3})\]/) == 2 or (() = m[^([^/]+)/([0-9a-f.:]+)]i) == 2
(() = /^([^\[]+)\[((?:\d{1,3}\.){3}\d{1,3})\]/) == 2 (() = m[^([^/]+)/([0-9a-f.:]+)]i) == 2
Truth table0%0/3
A or B
A= (() = /^([^\[]+)\[((?:\d{1,3}\.){3}\d{1,3})\]/) == 2B= (() = m[^([^/]+)/([0-9a-f.:]+)]i) == 2
ABresult
1X1
011
000
69 (($domain, $ipAddr) = /^([^\/]+)\/([0-9a-f.:]+)/i) == 2) {
70 # more exhaustive method
71 0 ($domain, $ipAddr) = /^([^\[\(\/]+)[\[\(\/]([^\]\)]+)[\]\)]?:?\s*$/;
72 }
73  
74 # "mach.host.dom"/"mach.host.do.co" to "host.dom"/"host.do.co"
75 0 ▶ if($domain eq 'unknown') {
Branch: 1 branch
BranchTrueFalseTotal
if ($domain eq 'unknown') { } 0 0 0
76 0 $domain = $ipAddr;
77 # For identifying the host part on a Class C network (commonly
78 # seen with dial-ups) the following is handy.
79 # $domain =~ s/\.\d+$//;
80 } else {
81 0 $domain =~
82 s/^(.*)\.([^\.]+)\.([^\.]{3}|[^\.]{2,3}\.[^\.]{2})$/\L$2.$3/;
83 }
84  
85 0 return($domain, $ipAddr);
86 }
87 1 *gimme_domain = \&postfix_remote;
88  
89 # Hack for VERP (?) - convert address from somthing like
90 # "list-return-36-someuser=someplace.com@lists.domain.com"
91 # to "list-return-ID-someuser=someplace.com@lists.domain.com"
92 # to prevent per-user listing "pollution." More aggressive
93 # munging converts to something like
94 # "list-return@lists.domain.com" (Instead of "return," there
95 # may be numeric list name/id, "warn", "error", etc.?)
96 sub verp_mung {
97 0 ▶ my ( $level, $addr )= @_;
Subroutine verp_mung: not called CC=3 SCAR=24.8
Pod undocumented
98  
99 0 ▶ if( $level ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($level) 0 0 0
100 0 $addr =~ s/((?:bounce[ds]?|no(?:list|reply|response)|return|sentto|\d+).*?)(?:[\+_\.\*-]\d+\b)+/$1-ID/i;
101 0 ▶ if($level > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($level > 1) 0 0 0
102 0 $addr =~ s/[\*-](\d+[\*-])?[^=\*-]+[=\*][^\@]+\@/\@/;
103 }
104 }
105  
106 0 return $addr;
107 }
108  
109 1 1;
110  
111 __END__
112  
113 =pod
114  
115 =encoding UTF-8
116  
117 =head1 NAME
118  
119 Log::Saftpresse::Plugin::Postfix::Utils - class with collection of some utility functions
120  
121 =head1 VERSION
122  
123 version 1.5
124  
125 =head1 AUTHOR
126  
127 Markus Benning <ich@markusbenning.de>
128  
129 =head1 COPYRIGHT AND LICENSE
130  
131 This software is Copyright (c) 1998 by James S. Seymour, 2015 by Markus Benning.
132  
133 This is free software, licensed under:
134  
135 The GNU General Public License, Version 2, June 1991
136  
137 =cut
« Saftpresse/Slurp.pm ↑ Summary Saftpresse/Output/JSON.pm »