| 1 | # -*- mode: cperl; cperl-indent-level: 4; -*- | ||||||||||||||||||||||||||||||||||
| 2 | # vi:ai:sm:et:sw=4:ts=4 | ||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||
| 4 | # $Id: Procmail.pm,v 1.3 2004/11/12 06:11:27 paulv Exp $ | ||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||
| 6 | package POE::Filter::Log::Procmail; | ||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use POE::Filter::Line; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||
| 14 | 1 | our $VERSION = '0.03'; | |||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||
| 16 | # sub get_one_start { | ||||||||||||||||||||||||||||||||||
| 17 | # my $self = shift; | ||||||||||||||||||||||||||||||||||
| 18 | # my $chunk = shift; | ||||||||||||||||||||||||||||||||||
| 19 | # | ||||||||||||||||||||||||||||||||||
| 20 | # my $lines = $self->{line}->get($chunk); | ||||||||||||||||||||||||||||||||||
| 21 | # | ||||||||||||||||||||||||||||||||||
| 22 | # foreach my $line (@$lines) { | ||||||||||||||||||||||||||||||||||
| 23 | # $self->_debug("line is *$line*"); | ||||||||||||||||||||||||||||||||||
| 24 | # | ||||||||||||||||||||||||||||||||||
| 25 | # if ($self->_wantLine($line)) { | ||||||||||||||||||||||||||||||||||
| 26 | # push(@{$self->{queue}}, $line); | ||||||||||||||||||||||||||||||||||
| 27 | # } else { | ||||||||||||||||||||||||||||||||||
| 28 | # $self->_debug("got a bad line: $line"); | ||||||||||||||||||||||||||||||||||
| 29 | # } | ||||||||||||||||||||||||||||||||||
| 30 | # } | ||||||||||||||||||||||||||||||||||
| 31 | # } | ||||||||||||||||||||||||||||||||||
| 32 | # sub get_one { $self->_debug("get_one"); return []; } | ||||||||||||||||||||||||||||||||||
| 33 | # sub put { $self->_debug("put"); return; } | ||||||||||||||||||||||||||||||||||
| 34 | # sub get_pending { } | ||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||
| 36 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=17.1
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 37 | 1 | my $class = shift; | |||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||
| 39 | 1 | ▶ | croak "$class requires an even number of parameters" if @_ and @_ & 1; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ and @_ & 1
MC/DC0%0/2
@_ and @_ & 1
@_
@_ & 1
Truth table33%1/3
A and B
A= @_B= @_ & 1
| |||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||
| 41 | 1 | my %params = @_; | |||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||
| 43 | 1 | my $self = {}; | |||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||
| 45 | 1 | ▶ | if (defined $params{Debug} and $params{Debug} > 0) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $params{"Debug"} and $params{"Debug"} > 0
MC/DC0%0/2
defined $params{"Debug"} and $params{"Debug"} > 0
defined $params{"Debug"}
$params{"Debug"} > 0
Truth table33%1/3
A and B
A= defined $params{"Debug"}B= $params{"Debug"} > 0
| |||||||||||||||||||||||||||||||||||
| 46 | 0 | $self->{debug} = 1; | |||||||||||||||||||||||||||||||||
| 47 | } else { | ||||||||||||||||||||||||||||||||||
| 48 | 1 | $self->{debug} = 0; | |||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||
| 51 | 1 | $self->{line} = POE::Filter::Line->new(); | |||||||||||||||||||||||||||||||||
| 52 | 1 | $self->{queue} = []; | |||||||||||||||||||||||||||||||||
| 53 | 1 | $self->{count} = 0; | |||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||
| 55 | 1 | $self->{dow} = qr/(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun)/o; | |||||||||||||||||||||||||||||||||
| 56 | 1 | $self->{mon} = qr/(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)/o; | |||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||
| 58 | # the regexps in $self->{match} match the following lines of procmail log | ||||||||||||||||||||||||||||||||||
| 59 | # | ||||||||||||||||||||||||||||||||||
| 60 | # From paulv@cpan.org Tue Oct 19 13:00:02 2004 | ||||||||||||||||||||||||||||||||||
| 61 | # Subject: whatever | ||||||||||||||||||||||||||||||||||
| 62 | # Folder: mail/paulv 6809 | ||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||
| 64 | $self->{match} = [ | ||||||||||||||||||||||||||||||||||
| 65 | 1 | qr/^From (.+)\s\s($self->{dow}) ($self->{mon}) ([ \d]\d) (\d{2}:\d{2}:\d{2}) (\d{4})$/, | |||||||||||||||||||||||||||||||||
| 66 | qr/^\sSubject: ?(.+)?$/i, | ||||||||||||||||||||||||||||||||||
| 67 | qr/^\s\sFolder: (.+?)\s+(\d+)$/, | ||||||||||||||||||||||||||||||||||
| 68 | ]; | ||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||
| 70 | 1 | bless ($self, $class); | |||||||||||||||||||||||||||||||||
| 71 | 1 | return $self; | |||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||
| 74 | 8 | ▶ | sub get { | ||||||||||||||||||||||||||||||||
|
Subroutine
get: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 75 | 8 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 76 | 8 | my $chunk = shift; | |||||||||||||||||||||||||||||||||
| 77 | 8 | my @objects; | |||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||
| 79 | 8 | my $lines = $self->{line}->get($chunk); | |||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||
| 81 | 8 | foreach my $line (@$lines) { | |||||||||||||||||||||||||||||||||
| 82 | 33 | $self->_debug("line is *$line*"); | |||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||
| 84 | 33 | my $test = $self->_wantLine($line); | |||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||
| 86 | 33 | ▶ | if ($test == 1) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 87 | 20 | push(@{$self->{queue}}, $line); | |||||||||||||||||||||||||||||||||
| 88 | } elsif ($test == 2) { | ||||||||||||||||||||||||||||||||||
| 89 | # if test is 2, it means we need to fake a Subject line. | ||||||||||||||||||||||||||||||||||
| 90 | 2 | push(@{$self->{queue}}, "Subject:\n"); | |||||||||||||||||||||||||||||||||
| 91 | 2 | push(@{$self->{queue}}, $line); | |||||||||||||||||||||||||||||||||
| 92 | } else { | ||||||||||||||||||||||||||||||||||
| 93 | 11 | $self->_debug("got a bad line: $line"); | |||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||
| 97 | # loop while there are 3 or more elements in the queue | ||||||||||||||||||||||||||||||||||
| 98 | 8 | ▶ | while (@{$self->{queue}} > 2) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 99 | 8 | push(@objects, $self->_makeHRef()); | |||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||
| 102 | 8 | return \@objects; | |||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||
| 105 | 33 | ▶ | sub _wantLine { | ||||||||||||||||||||||||||||||||
|
Subroutine
_wantLine: called CC=7 SCAR=19.6
| |||||||||||||||||||||||||||||||||||
| 106 | 33 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 107 | 33 | my $line = shift; | |||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||
| 109 | 33 | my $count = $self->{count}; | |||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||
| 111 | 33 | ▶ | if ($line =~ /^$/) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 112 | 0 | $self->_debug("Skipping: blank line"); | |||||||||||||||||||||||||||||||||
| 113 | 0 | return 0; | |||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||
| 116 | 33 | ▶ | if ($line =~ $self->{match}->[$count]) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 117 | 20 | ▶ | $self->{count} = ($count == 2) ? 0 : ++$count; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 118 | 20 | $self->_debug("$line matched $self->{match}->[$count]"); | |||||||||||||||||||||||||||||||||
| 119 | 20 | $self->_debug("setting count to $self->{count}"); | |||||||||||||||||||||||||||||||||
| 120 | 20 | return 1; | |||||||||||||||||||||||||||||||||
| 121 | ▶ | } elsif ($count == 1 and | |||||||||||||||||||||||||||||||||
|
Condition83%5/6
$count == 1 and not $line =~ /$self->{"match"}[$count]/i and $line =~ /$self->{"match"}[$count + 1]/
$count == 1 and not $line =~ /$self->{"match"}[$count]/i
MC/DC66%2/3
$count == 1 and not $line =~ /$self->{"match"}[$count]/i and $line =~ /$self->{"match"}[$count + 1]/
$count == 1
not $line =~ /$self->{"match"}[$count]/i
$line =~ /$self->{"match"}[$count + 1]/
Truth table75%3/4
A and not(B) and C
A= $count == 1B= not $line =~ /$self->{"match"}[$count]/iC= $line =~ /$self->{"match"}[$count + 1]/
| |||||||||||||||||||||||||||||||||||
| 122 | $line !~ $self->{match}->[$count] and | ||||||||||||||||||||||||||||||||||
| 123 | $line =~ $self->{match}->[$count + 1]) | ||||||||||||||||||||||||||||||||||
| 124 | { | ||||||||||||||||||||||||||||||||||
| 125 | # this is if we get a non-existant Subject line. | ||||||||||||||||||||||||||||||||||
| 126 | 2 | $self->_debug("No Subject!"); | |||||||||||||||||||||||||||||||||
| 127 | 2 | $self->{count} = 0; | |||||||||||||||||||||||||||||||||
| 128 | 2 | return 2; | |||||||||||||||||||||||||||||||||
| 129 | } else { | ||||||||||||||||||||||||||||||||||
| 130 | 11 | $self->_debug("$line didn't match $self->{match}->[$self->{count}]"); | |||||||||||||||||||||||||||||||||
| 131 | 11 | return 0; | |||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||
| 135 | 8 | ▶ | sub _makeHRef { | ||||||||||||||||||||||||||||||||
|
Subroutine
_makeHRef: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||
| 136 | 8 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 137 | 8 | my $href; | |||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||
| 139 | 8 | my @lines = ( shift(@{$self->{queue}}), | |||||||||||||||||||||||||||||||||
| 140 | 8 | shift(@{$self->{queue}}), | |||||||||||||||||||||||||||||||||
| 141 | 8 | shift(@{$self->{queue}}), | |||||||||||||||||||||||||||||||||
| 142 | ); | ||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||
| 144 | 8 | ▶ | if ($lines[0] =~ $self->{match}->[0]) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 145 | 8 | $href->{from} = $1; | |||||||||||||||||||||||||||||||||
| 146 | 8 | $href->{dow} = $2; | |||||||||||||||||||||||||||||||||
| 147 | 8 | $href->{mon} = $3; | |||||||||||||||||||||||||||||||||
| 148 | 8 | $href->{date} = $4; | |||||||||||||||||||||||||||||||||
| 149 | 8 | $href->{time} = $5; | |||||||||||||||||||||||||||||||||
| 150 | 8 | $href->{year} = $6; | |||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||
| 152 | # date could be ' 1' | ||||||||||||||||||||||||||||||||||
| 153 | 8 | $href->{date} =~ s/\s+//g; | |||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||
| 156 | 8 | ▶ | if ($lines[1] =~ $self->{match}->[1]) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 157 | 6 | $href->{subject} = $1; | |||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||
| 160 | 8 | ▶ | if ($lines[2] =~ $self->{match}->[2]) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 161 | 8 | $href->{folder} = $1; | |||||||||||||||||||||||||||||||||
| 162 | 8 | $href->{size} = $2; | |||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||
| 165 | 8 | return $href; | |||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||
| 168 | 97 | ▶ | sub _debug { | ||||||||||||||||||||||||||||||||
|
Subroutine
_debug: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||
| 169 | 97 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 170 | 97 | my @args = @_; | |||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||
| 172 | 97 | ▶ | print STDERR "@args\n" if $self->{debug}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||
| 175 | 1 | 1; | |||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||
| 177 | __END__ | ||||||||||||||||||||||||||||||||||