File Coverage

blib/lib/SyslogScan/SendmailUtil.pm
Criterion Covered Total %
statement 1 4 25.0
branch n/a
condition n/a
subroutine 1 2 50.0
pod n/a
total 2 6 33.3


line stmt bran cond sub pod time code
1             # SendmailUtil.pm: exports utilities for use with syslog
2             # sendmail parsing.
3              
4             package SyslogScan::SendmailUtil;
5              
6             $VERSION = 0.20;
7              
8 0     0     sub Version { $VERSION };
9              
10 5     5   4118 use SyslogScan::SyslogEntry;
  0            
  0            
11             use SyslogScan::SendmailLine;
12             use strict;
13              
14             # getNextMailTransfer: given a filehandle, gets the next SyslogEntry
15             # which is also a SendmailLineTrans
16             sub getNextMailTransfer
17             {
18             my $fh = shift;
19              
20             my ($pLogLine, $lineClass);
21             while ($pLogLine = new SyslogScan::SyslogEntry $fh)
22             {
23             my $executable = $$pLogLine{'executable'};
24             next unless ($executable eq 'sendmail');
25              
26             $lineClass = ref $pLogLine;
27              
28             # do not tolerate errors in sendmail module except
29             # for unbalanced parens and i/o errors
30             if ($lineClass =~ /BotchedEntry/)
31             {
32             next if $$pLogLine{errorString} =~ /unbalanced paren/;
33             next if $$pLogLine{suspectIOError};
34             die "parsing error: $$pLogLine{'errorString'}";
35             }
36              
37             die "sanity check of class failed for $lineClass"
38             unless ($lineClass =~ /^SyslogScan::SendmailLine/);
39              
40             last if (($lineClass =~ /From/) || ($lineClass =~ /To/)
41             || ($lineClass =~ /Clone/));
42             }
43             return $pLogLine; # either a Transfer, or undefined at EOF
44             }
45              
46             sub canonAddress
47             {
48             my $address = shift;
49              
50             $address =~ s/^\<(.+)\>$/$1/;
51             $address =~ tr/A-Z/a-z/;
52             $address =~ /[\!\@]/ or $address .= '@localhost';
53             $address;
54             }
55              
56             1;
57              
58             __END__