| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
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
|
|
|
1
|
|
50170
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
39
|
|
|
9
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
28
|
|
|
10
|
1
|
|
|
1
|
|
5
|
use Data::Dumper; |
|
|
1
|
|
|
|
|
5
|
|
|
|
1
|
|
|
|
|
58
|
|
|
11
|
1
|
|
|
1
|
|
589
|
use POE::Filter::Line; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
use Carp qw(croak); |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
sub new { |
|
37
|
|
|
|
|
|
|
my $class = shift; |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
croak "$class requires an even number of parameters" if @_ and @_ & 1; |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
my %params = @_; |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
my $self = {}; |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
if (defined $params{Debug} and $params{Debug} > 0) { |
|
46
|
|
|
|
|
|
|
$self->{debug} = 1; |
|
47
|
|
|
|
|
|
|
} else { |
|
48
|
|
|
|
|
|
|
$self->{debug} = 0; |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
$self->{line} = POE::Filter::Line->new(); |
|
52
|
|
|
|
|
|
|
$self->{queue} = []; |
|
53
|
|
|
|
|
|
|
$self->{count} = 0; |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
$self->{dow} = qr/(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun)/o; |
|
56
|
|
|
|
|
|
|
$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
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
bless ($self, $class); |
|
71
|
|
|
|
|
|
|
return $self; |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub get { |
|
75
|
|
|
|
|
|
|
my $self = shift; |
|
76
|
|
|
|
|
|
|
my $chunk = shift; |
|
77
|
|
|
|
|
|
|
my @objects; |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
my $lines = $self->{line}->get($chunk); |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
foreach my $line (@$lines) { |
|
82
|
|
|
|
|
|
|
$self->_debug("line is *$line*"); |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
my $test = $self->_wantLine($line); |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
if ($test == 1) { |
|
87
|
|
|
|
|
|
|
push(@{$self->{queue}}, $line); |
|
88
|
|
|
|
|
|
|
} elsif ($test == 2) { |
|
89
|
|
|
|
|
|
|
# if test is 2, it means we need to fake a Subject line. |
|
90
|
|
|
|
|
|
|
push(@{$self->{queue}}, "Subject:\n"); |
|
91
|
|
|
|
|
|
|
push(@{$self->{queue}}, $line); |
|
92
|
|
|
|
|
|
|
} else { |
|
93
|
|
|
|
|
|
|
$self->_debug("got a bad line: $line"); |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
# loop while there are 3 or more elements in the queue |
|
98
|
|
|
|
|
|
|
while (@{$self->{queue}} > 2) { |
|
99
|
|
|
|
|
|
|
push(@objects, $self->_makeHRef()); |
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
return \@objects; |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub _wantLine { |
|
106
|
|
|
|
|
|
|
my $self = shift; |
|
107
|
|
|
|
|
|
|
my $line = shift; |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
my $count = $self->{count}; |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
if ($line =~ /^$/) { |
|
112
|
|
|
|
|
|
|
$self->_debug("Skipping: blank line"); |
|
113
|
|
|
|
|
|
|
return 0; |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
if ($line =~ $self->{match}->[$count]) { |
|
117
|
|
|
|
|
|
|
$self->{count} = ($count == 2) ? 0 : ++$count; |
|
118
|
|
|
|
|
|
|
$self->_debug("$line matched $self->{match}->[$count]"); |
|
119
|
|
|
|
|
|
|
$self->_debug("setting count to $self->{count}"); |
|
120
|
|
|
|
|
|
|
return 1; |
|
121
|
|
|
|
|
|
|
} elsif ($count == 1 and |
|
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
|
|
|
|
|
|
|
$self->_debug("No Subject!"); |
|
127
|
|
|
|
|
|
|
$self->{count} = 0; |
|
128
|
|
|
|
|
|
|
return 2; |
|
129
|
|
|
|
|
|
|
} else { |
|
130
|
|
|
|
|
|
|
$self->_debug("$line didn't match $self->{match}->[$self->{count}]"); |
|
131
|
|
|
|
|
|
|
return 0; |
|
132
|
|
|
|
|
|
|
} |
|
133
|
|
|
|
|
|
|
} |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub _makeHRef { |
|
136
|
|
|
|
|
|
|
my $self = shift; |
|
137
|
|
|
|
|
|
|
my $href; |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
my @lines = ( shift(@{$self->{queue}}), |
|
140
|
|
|
|
|
|
|
shift(@{$self->{queue}}), |
|
141
|
|
|
|
|
|
|
shift(@{$self->{queue}}), |
|
142
|
|
|
|
|
|
|
); |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
if ($lines[0] =~ $self->{match}->[0]) { |
|
145
|
|
|
|
|
|
|
$href->{from} = $1; |
|
146
|
|
|
|
|
|
|
$href->{dow} = $2; |
|
147
|
|
|
|
|
|
|
$href->{mon} = $3; |
|
148
|
|
|
|
|
|
|
$href->{date} = $4; |
|
149
|
|
|
|
|
|
|
$href->{time} = $5; |
|
150
|
|
|
|
|
|
|
$href->{year} = $6; |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
# date could be ' 1' |
|
153
|
|
|
|
|
|
|
$href->{date} =~ s/\s+//g; |
|
154
|
|
|
|
|
|
|
} |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
if ($lines[1] =~ $self->{match}->[1]) { |
|
157
|
|
|
|
|
|
|
$href->{subject} = $1; |
|
158
|
|
|
|
|
|
|
} |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
if ($lines[2] =~ $self->{match}->[2]) { |
|
161
|
|
|
|
|
|
|
$href->{folder} = $1; |
|
162
|
|
|
|
|
|
|
$href->{size} = $2; |
|
163
|
|
|
|
|
|
|
} |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
return $href; |
|
166
|
|
|
|
|
|
|
} |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
sub _debug { |
|
169
|
|
|
|
|
|
|
my $self = shift; |
|
170
|
|
|
|
|
|
|
my @args = @_; |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
print STDERR "@args\n" if $self->{debug}; |
|
173
|
|
|
|
|
|
|
} |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
1; |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
__END__ |