lib/QMail/QueueHandler.pm

filter: Statementstmt 10.2% 50 / 487 Branchbran 2.5% 4 / 158 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 22.2% 14 / 63 Podpod 92.0% 23 / 25 totaltotal 12.0% 91 / 753 CC 110 SCAR 35.1
CC
110
Cov
8%
trash_msgs
90.0
del_msg_body_r
90.0
del_msg_header_r
72.0
CRAP 33.6
↑ Summary
1 =head1 NAME
2  
3 QMail::QueueHandler - Module to manage QMail message queues
4  
5 =head1 DESCRIPTION
6  
7 This is all the code behind the qmHandle command line program.
8  
9 =head1 SYNOPSIS
10  
11 use QMail::QueueHandler;
12  
13 QMail::QueueHandler->new->run;
14  
15 =cut
16  
17 package QMail::QueueHandler;
18  
19 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 1 ▶use Term::ANSIColor;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use Getopt::Std;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 1 our $VERSION = '2.0.5';
26 1 my $me = basename $0;
27  
28 # Where qmail stores all of its files
29 1 has queue => (
30 is => 'ro',
31 isa => 'Str',
32 default => '/var/qmail/queue/',
33 );
34  
35 # Which todo format do we have?
36 has bigtodo => (
37 is => 'ro',
38 isa => 'Bool',
39 lazy => 1,
40 0 ▶ default => sub { -d $_[0]->queue . 'todo/0' },
Subroutine __ANON__: not called CC=1 SCAR=6.9
41 1 );
42  
43 # Various commands that we use
44 has commands => (
45 is => 'ro',
46 isa => 'HashRef',
47 1 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
48 {
49 1 start => '/sbin/service qmail start',
50 stop => '/sbin/service qmail stop',
51 pid => '/sbin/pidof qmail-send',
52 };
53 },
54 1 );
55  
56 # Colours for output.
57 # Default is non-coloured. These values can be changed in parse_args.
58 has colours => (
59 is => 'ro',
60 isa => 'HashRef',
61 1 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
62 {
63 1 msg => '',
64 stat => '',
65 end => '',
66 };
67 },
68 1 );
69  
70 # Are we showing a summary?
71 1 has summary => (
72 is => 'ro',
73 isa => 'Bool',
74 default => 0,
75 );
76  
77 # Are we supposed to be deleting things?
78 1 has deletions => (
79 is => 'rw',
80 isa => 'Bool',
81 );
82  
83 # What actions are we carrying out.
84 # Each element in this array is another array.
85 # The first element in these second level arrays is a code ref.
86 # The other elements are arguments to be passed to the code ref.
87 has actions => (
88 is => 'ro',
89 traits => ['Array'],
90 isa => 'ArrayRef',
91 1 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
92 1 handles => {
93 add_action => 'push',
94 all_actions => 'elements',
95 },
96 );
97  
98 # Do we need to restart QMail once we have finished?
99 1 has restart => (
100 is => 'rw',
101 isa => 'Bool',
102 default => 0,
103 );
104  
105 # List of messages to delete
106 has to_delete => (
107 is => 'rw',
108 traits => ['Array'],
109 isa => 'ArrayRef',
110 1 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
111 1 handles => {
112 add_to_delete => 'push',
113 all_to_delete => 'elements',
114 to_delete_count => 'count',
115 },
116 );
117  
118 0 ▶before add_to_delete => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
119 0 my $self = shift;
120 0 my ($msg_id) = @_;
121  
122 0 warn "Message [$msg_id] queued for deletion.\n";
123 1 };
124  
125 # List of messages to flag
126 has to_flag => (
127 is => 'rw',
128 traits => ['Array'],
129 isa => 'ArrayRef',
130 1 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
131 1 handles => {
132 add_to_flag => 'push',
133 all_to_flag => 'elements',
134 },
135 );
136  
137 # Hash containing details of the messages in the queue
138 1 has msglist => (
139 is => 'rw',
140 isa => 'HashRef',
141 lazy_build => 1,
142 );
143  
144 1 ▶sub BUILD {
Subroutine BUILD: called CC=1 SCAR=0.0
Pod undocumented
145 1 my $self = shift;
146  
147 # Get command line options
148 1 $self->parse_args;
149 }
150  
151 =head1 METHODS
152  
153 =head2 run()
154  
155 Main driver method.
156  
157 =cut
158  
159 0 ▶sub run {
Subroutine run: not called CC=3 SCAR=24.8
Pod documented
160 0 my $self = shift;
161 0 my @args = @_;
162  
163 # (Possibly) stop qmail
164 0 $self->stop_qmail;
165  
166 # Execute actions
167 0 foreach my $action ( $self->all_actions ) {
168 0 my $sub = shift @$action; # First element is the sub
169 0 $self->$sub(@$action); # Others the arguments, if any
170 }
171  
172 # If we have planned deletions, then do them.
173 0 ▶ if ( $self->to_delete_count ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->to_delete_count) 0 0 0
174 0 $self->trash_msgs;
175 }
176  
177 # If we stopped qmail, then restart it
178 0 $self->start_qmail;
179 }
180  
181 0 ▶sub _get_todo {
Subroutine _get_todo: not called CC=5 SCAR=34.0
182 0 my $self = shift;
183 0 my ($todohash, $msglist) = @_;
184  
185 0 my $queue = $self->queue;
186  
187 0 opendir( my $tododir, "${queue}todo" );
188  
189 0 ▶ if ( $self->bigtodo ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->bigtodo) { } 0 0 0
190 0 foreach my $todofile ( grep { !/\./ } readdir $tododir ) {
191 0 $todohash->{$todofile} = $todofile;
192 }
193 }
194 else {
195 0 foreach my $tododir ( grep { !/\./ } readdir $tododir ) {
196 0 opendir( my $subdir, "${queue}todo/$tododir" );
197 0 foreach my $todofile (
198 0 grep { !/\./ }
199 0 map { "$tododir/$_" } readdir $subdir
200 ) {
201 0 $msglist->{$todofile}{'todo'} = $todofile;
202 }
203 }
204 }
205 0 closedir $tododir;
206 }
207  
208 0 ▶sub _get_info {
Subroutine _get_info: not called CC=2 SCAR=17.9
209 0 my $self = shift;
210 0 my ($dir, $msglist) = @_;
211  
212 0 my $queue = $self->queue;
213  
214 0 opendir( my $infosubdir, "${queue}info/$dir" );
215  
216 0 foreach my $infofile (
217 0 grep { !/\./ }
218 0 map { "$dir/$_" } readdir $infosubdir
219 ) {
220 0 $msglist->{$infofile}{sender} = 'S';
221 }
222  
223 0 close $infosubdir;
224 }
225  
226 0 ▶sub _get_local {
Subroutine _get_local: not called CC=2 SCAR=17.9
227 0 my $self = shift;
228 0 my ($dir, $msglist) = @_;
229  
230 0 my $queue = $self->queue;
231  
232 0 opendir( my $localsubdir, "${queue}local/$dir" );
233  
234 0 foreach my $localfile (
235 0 grep { !/\./ }
236 0 map { "$dir/$_" } readdir $localsubdir
237 ) {
238 0 $msglist->{$localfile}{local} = 'L';
239 }
240  
241 0 close $localsubdir;
242 }
243  
244 0 ▶sub _get_remote {
Subroutine _get_remote: not called CC=2 SCAR=17.9
245 0 my $self = shift;
246 0 my ($dir, $msglist) = @_;
247  
248 0 my $queue = $self->queue;
249  
250 0 opendir( my $remotesubdir, "${queue}remote/$dir" );
251  
252 0 foreach my $remotefile (
253 0 grep { !/\./ }
254 0 map { "$dir/$_" } readdir $remotesubdir
255 ) {
256 0 $msglist->{$remotefile}{remote} = 'R';
257 }
258  
259 0 close $remotesubdir;
260 }
261  
262 0 ▶sub _get_subdir {
Subroutine _get_subdir: not called CC=5 SCAR=34.0
263 0 my $self = shift;
264 0 my ($dir, $msglist, $todohash, $bouncehash) = @_;
265  
266 0 my $queue = $self->queue;
267  
268 0 opendir( my $subdir, "${queue}mess/$dir" );
269  
270 0 foreach my $file (
271 0 grep { !/\./ }
272 0 map { "$dir/$_" } readdir $subdir
273 ) {
274 0 my $msgno = ( split( /\//, $file ) )[1];
275 0 ▶ if ( $bouncehash->{$msgno} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bouncehash->{$msgno}) 0 0 0
276 0 $msglist->{$file}{bounce} = 'B';
277 }
278 0 ▶ if ( $self->bigtodo ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->bigtodo) 0 0 0
279 0 ▶ if ( $todohash->{$msgno} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($todohash->{$msgno}) 0 0 0
280 0 $msglist->{$file}{todo} = $msgno;
281 }
282 }
283 }
284  
285 0 closedir $subdir;
286 }
287  
288 0 ▶sub _build_msglist {
Subroutine _build_msglist: not called CC=3 SCAR=24.8
289 0 my $self = shift;
290  
291 0 my $queue = $self->queue;
292  
293 0 my ( $todohash, $bouncehash );
294 0 my $msglist = {};
295  
296 0 $self->_get_todo($todohash, $msglist);
297  
298 0 opendir( my $bouncedir, "${queue}bounce" );
299 0 foreach my $bouncefile ( grep { !/\./ } readdir $bouncedir ) {
300 0 $bouncehash->{$bouncefile} = 'B';
301 }
302 0 closedir $bouncedir;
303  
304 0 opendir( my $messdir, "${queue}mess" );
305  
306 0 foreach my $dir ( grep { !/\./ } readdir $messdir ) {
307 0 $self->_get_info($dir);
308 0 $self->_get_local($dir);
309 0 $self->_get_remote($dir);
310 0 $self->_get_subdir($dir);
311 }
312 0 closedir $messdir;
313  
314 0 return $msglist;
315 }
316  
317 =head2 parse_args()
318  
319 Parse the command line arguments and set any required attributes.
320  
321 =cut
322  
323 1 ▶sub parse_args {
Subroutine parse_args: called CC=8 SCAR=37.1
Pod documented
324 1 my $self = shift;
325  
326 1 ▶ @ARGV or $self->usage;
Branch: 1 branch
BranchTrueFalseTotal
@ARGV or $self->usage 0 1 1
327  
328 1 my %opt;
329  
330 my %option = (
331 # (Attempt to) send all queued messages
332 a => {
333 arg => 0,
334 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
335 0 $self->add_action( [ \&send_msgs ] );
336 },
337 },
338 # List message queues
339 l => {
340 arg => 0,
341 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
342 0 $self->add_action( [ \&list_msg, 'A' ] );
343 },
344 },
345 # List local message queue
346 L => {
347 arg => 0,
348 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
349 0 $self->add_action( [ \&list_msg, 'L' ] );
350 },
351 },
352 # List remote message queue
353 R => {
354 arg => 0,
355 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
356 0 $self->add_action( [ \&list_msg, 'R' ] );
357 },
358 },
359 # List message numbers only
360 N => {
361 arg => 0,
362 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
363 0 $self->summary(1);
364 },
365 },
366 # Coloured output
367 c => {
368 arg => 0,
369 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
370 0 @{ $self->colours }{qw[msg stat end]} = (
371 color('bold bright_blue'),
372 color('bold bright_red'),
373 color('reset'),
374 );
375 },
376 },
377 # Show statistics of queues
378 s => {
379 arg => 0,
380 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
381 0 $self->add_action( [ \&stats ] );
382 },
383 },
384 # Display message with given number
385 m => {
386 arg => 1,
387 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
388 0 $self->add_action( [ \&view_msg, @_ ] );
389 },
390 },
391 # Delete messages from given sender
392 f => {
393 arg => 1,
394 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
395 0 $self->add_action( [ \&del_msg_from_sender, @_ ] );
396 0 $self->deletions(1);
397 },
398 },
399 # Delete messages from given sender (regex match)
400 F => {
401 arg => 1,
402 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
403 0 $self->add_action( [ \&del_msg_from_sender_r, @_ ] );
404 0 $self->deletions(1);
405 },
406 },
407 # Delete message with given number
408 d => {
409 arg => 1,
410 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
411 0 $self->add_action( [ \&del_msg, @_ ] );
412 0 $self->deletions(1);
413 },
414 },
415 # Delete messages with matching subject
416 S => {
417 arg => 1,
418 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
419 0 $self->add_action( [ \&del_msg_subj, @_ ] );
420 0 $self->deletions(1);
421 },
422 },
423 # Delete messages with matching header (case insensitive)
424 h => {
425 arg => 1,
426 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
427 0 $self->add_action( [ \&del_msg_header_r, @_, 1 ] );
428 0 $self->deletions(1);
429 },
430 },
431 # Delete messages with matching body (case insensitive)
432 b => {
433 arg => 1,
434 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
435 0 $self->add_action( [ \&del_msg_body_r, @_, 1 ] );
436 0 $self->deletions(1);
437 },
438 },
439 # Delete messages with matching header (case sensitive)
440 H => {
441 arg => 1,
442 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
443 0 $self->add_action( [ \&del_msg_header_r, @_, 0 ] );
444 0 $self->deletions(1);
445 },
446 },
447 # Delete messages with matching body (case sensitive)
448 B => {
449 arg => 1,
450 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
451 0 $self->add_action( [ \&del_msg_body_r, @_, 0 ] );
452 0 $self->deletions(1);
453 },
454 },
455 # Flag messages with matching recipients
456 t => {
457 arg => 1,
458 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
459 0 $self->add_actions( [ \&flag_remote, @_ ] );
460 },
461 },
462 # Delete all messages in queues
463 D => {
464 arg => 0,
465 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
466 0 $self->add_action( [ \&del_all ] );
467 0 $self->deletions(1);
468 },
469 },
470 # Display program version
471 V => {
472 arg => 0,
473 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
474 0 $self->add_action( [ \&version ] );
475 },
476 },
477 # Display help
478 '?' => {
479 arg => 0,
480 0 ▶ code => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
481 0 $self->usage;
482 },
483 },
484 1 );
485  
486 1 ▶ my $optstring = join '', map { $_ . ( $option{$_}{arg} ? ':' : '' ) }
Branch: 1 branch
BranchTrueFalseTotal
$option{$_}{'arg'} ? : 10 10 20
487 keys %option;
488  
489 1 getopts( $optstring, \%opt );
490  
491 1 foreach my $opt ( keys %opt ) {
492 0 ▶ if (! exists $option{$opt}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $option{$opt}) 0 0 0
493 0 warn "$opt is not a valid option\n";
494 0 next;
495 }
496 0 ▶ if ( $option{$opt}{arg} and not $opt{$opt} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($option{$opt}{"arg"} and not $opt{$opt}) 0 0 0
Condition0%0/3
$option{$opt}{"arg"} and not $opt{$opt}
!ll&&!rl&&r
000
MC/DC0%0/2
$option{$opt}{"arg"} and not $opt{$opt}
$option{$opt}{"arg"} not $opt{$opt}
Truth table0%0/3
A and not(B)
A= $option{$opt}{"arg"}B= not $opt{$opt}
ABresult
0X0
100
111
497 0 die "Option $opt must have an argument\n";
498 }
499  
500 0 ▶ if ($option{$opt}{arg}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($option{$opt}{'arg'}) { } 0 0 0
501 0 $option{$opt}{code}->($opt{$opt});
502 } else {
503 0 $option{$opt}{code}->();
504 }
505 }
506  
507 1 return;
508 }
509  
510 =head2 stop_qmail()
511  
512 Optionally stop the qmail daemon.
513  
514 =cut
515  
516 1 ▶sub stop_qmail {
Subroutine stop_qmail: called CC=7 SCAR=37.2
Pod documented
517 1 my $self = shift;
518  
519 # Don't need to stop qmail if we're not planning to delete stuff
520 1 ▶ return unless $self->deletions;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->deletions 1 0 1
521  
522 # If qmail is running, we stop it
523 0 ▶ if ( my $qmpid = $self->qmail_pid ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $qmpid = $self->qmail_pid) { } 0 0 0
524  
525 # If there is a system script available, we use it
526 0 ▶ if ( $self->commands->{stop} ne '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->commands->{'stop'} ne '') { } 0 0 0
527  
528 0 warn "Calling system script to terminate qmail...\n";
529 0 ▶ if ( system( $self->commands->{stop} ) > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (system($self->commands->{"stop"}) > 0) 0 0 0
530 0 die 'Could not stop qmail';
531 }
532 0 ▶ sleep 1 while $self->qmail_pid;
Branch: 1 branch
BranchTrueFalseTotal
$self->qmail_pid and do { sleep 1 } 0 0 0
533  
534 # Otherwise, we're killers!
535 }
536 else {
537 0 warn "Terminating qmail (pid $qmpid)... ",
538 "this might take a while if qmail is working.\n";
539 0 kill 'TERM', $qmpid;
540  
541 0 ▶ sleep 1 while $self->qmail_pid;
Branch: 1 branch
BranchTrueFalseTotal
$self->qmail_pid and do { sleep 1 } 0 0 0
542 }
543  
544 # If it isn't, we don't. We also return a false value so our caller
545 # knows they might not want to restart it later.
546 }
547 else {
548 0 warn "Qmail isn't running... no need to stop it.\n";
549 0 return;
550 }
551  
552 0 $self->restart(1);
553  
554 0 return 1;
555 }
556  
557  
558 =head2 start_qmail()
559  
560 Restart the qmail daemon if it was previously stopped.
561  
562 =cut
563  
564 0 ▶sub start_qmail {
Subroutine start_qmail: not called CC=3 SCAR=24.8
Pod documented
565 0 my $self = shift;
566  
567 0 ▶ return unless $self->restart;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->restart 0 0 0
568  
569 # If qmail is running, why restart it?
570 0 ▶ if ( my $qmpid = $self->qmail_pid ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $qmpid = $self->qmail_pid) 0 0 0
571 0 warn "Qmail is already running again, so it won't be restarted.\n";
572 0 return 1;
573 }
574  
575 # In any other case, we restart it
576 0 warn "Restarting qmail... \n";
577 0 system( $self->commands->{start} );
578 0 warn "Done (hopefully).\n";
579  
580 0 return 1;
581 }
582  
583 =head2 get_subject($msg_id)
584  
585 Given the id of a message, return the subject of that message.
586  
587 =cut
588  
589 0 ▶sub get_subject {
Subroutine get_subject: not called CC=5 SCAR=34.0
Pod documented
590 0 my $self = shift;
591 0 my ($msg_id) = @_;
592  
593 0 my $msgsub;
594 0 my $queue = $self->queue;
595 0 ▶ open( my $msg_fh, '<', "${queue}mess/$msg_id" )
Branch: 1 branch
BranchTrueFalseTotal
open my $msg_fh, "<", "${queue}mess/$msg_id" or die "cannot open message $msg_id! Is qmail-send running?\n" 0 0 0
596 or die("cannot open message $msg_id! Is qmail-send running?\n");
597 0 ▶ while (<$msg_fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $msg_fh)) 0 0 0
598 0 chomp;
599 0 ▶ last if !/\S/; # End of headers
Branch: 1 branch
BranchTrueFalseTotal
unless /\S/ 0 0 0
600 0 ▶ if (/^Subject: (.*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^Subject: (.*)/) 0 0 0
601 0 $msgsub = $1;
602 0 last;
603 }
604 }
605 0 close($msg_fh);
606 0 return $msgsub;
607 }
608  
609 =head2 get_sender($msg_id)
610  
611 Given the id of a message, return the sender of the message.
612  
613 =cut
614  
615 0 ▶sub get_sender {
Subroutine get_sender: not called CC=2 SCAR=17.9
Pod documented
616 0 my $self = shift;
617 0 my ($msg_id) = @_;
618  
619 0 my $queue = $self->queue;
620  
621 0 ▶ open( my $msg_fh, '<', "${queue}/info/$msg_id" )
Branch: 1 branch
BranchTrueFalseTotal
open my $msg_fh, "<", "$queue/info/$msg_id" or die "cannot open info file $queue/info/$msg_id! ", "Is qmail-send running?\n" 0 0 0
622 or die( "cannot open info file ${queue}/info/$msg_id! ",
623 "Is qmail-send running?\n" );
624 0 my $sender = <$msg_fh>;
625 0 substr( $sender, 0, 1 ) = '';
626 0 chomp $sender;
627 0 close($msg_fh);
628 0 return $sender;
629 }
630  
631 =head2 send_msgs()
632  
633 Attempt to send all currently queued messages.
634  
635 It does this by sending SIGALRM to the qmail daemon.
636  
637 =cut
638  
639 0 ▶sub send_msgs {
Subroutine send_msgs: not called CC=2 SCAR=17.9
Pod documented
640 0 my $self = shift;
641  
642 # If qmail is running, we force sending of messages
643 0 ▶ if ( my $qmpid = $self->qmail_pid ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $qmpid = $self->qmail_pid) { } 0 0 0
644  
645 0 kill 'ALRM', $qmpid;
646  
647 }
648 else {
649  
650 0 warn "Qmail isn't running, can't send messages!\n";
651  
652 }
653 0 return;
654 }
655  
656 =head2 show_msg_info($msg_id)
657  
658 Given a message id, display the information about that message.
659  
660 =cut
661  
662 0 ▶sub show_msg_info {
Subroutine show_msg_info: not called CC=7 SCAR=40.3
Pod documented
663 0 my $self = shift;
664 0 my ($msg_id) = @_;
665  
666 0 my %msg;
667 0 my $queue = $self->queue;
668  
669 0 open( my $info_fh, '<', "${queue}info/$msg_id" );
670 0 $msg{ret} = <$info_fh>;
671 0 substr( $msg{ret}, 0, 1 ) = '';
672 0 chomp $msg{ret};
673 0 close($info_fh);
674 0 my ( $dirno, $rmsg ) = split( /\//, $msg_id );
675 0 print "$rmsg ($dirno, $msg_id)\n";
676  
677 # Get message (file) size
678 0 $msg{fsize} = ( stat("${queue}mess/$msg_id") )[7];
679  
680 0 my %header = (
681 Date => 'date',
682 From => 'from',
683 Subject => 'subject',
684 To => 'to',
685 Cc => 'cc',
686 );
687  
688 # Read something from message header (sender, receiver, subject, date)
689 0 open( my $msg_fh, '<', "${queue}mess/$msg_id" );
690 0 ▶ while (<$msg_fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $msg_fh)) 0 0 0
691 0 chomp;
692 # Stop processing at the end of the headers
693 0 ▶ last unless /\S/;
Branch: 1 branch
BranchTrueFalseTotal
unless /\S/ 0 0 0
694 0 foreach my $h ( keys %header ) {
695 0 ▶ if (/^$h: (.*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^$h: (.*)/) 0 0 0
696 0 $msg{ $header{$h} } = $1;
697 0 last;
698 }
699 }
700 }
701 0 close($msg_fh);
702  
703 # Add "pseudo-headers" for output
704 0 $header{'Return-path'} = 'ret';
705 0 $header{Size} = 'fsize';
706  
707 0 my $colours = $self->colours;
708 0 my ( $cmsg, $cend ) = @{$colours}{qw[msg end]};
709  
710 0 for (qw[Return-path From To Cc Subject Date Size]) {
711 0 ▶ next unless exists $msg{ $header{$_} };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $msg{$header{$_}} 0 0 0
712  
713 0 print " ${cmsg}$_${cend}: $msg{$header{$_}}\n";
714 }
715  
716 0 return;
717 }
718  
719 =head2 list_msg($queue)
720  
721 Display information for all messages in a given queue.
722  
723 The $queue parameter should be 'L' to display only local messages, 'R'
724 to display only remote messages or anything else to display all messages.
725  
726 =cut
727  
728 0 ▶sub list_msg {
Subroutine list_msg: not called CC=7 SCAR=40.3
Pod documented
729 0 my $self = shift;
730 0 my ($q) = @_;
731  
732 0 $q = uc $q;
733  
734 0 my $local = $q ne 'R';
735 0 my $remote = $q ne 'L';
736  
737 0 my $msglist = $self->msglist;
738 0 ▶ if ( !$self->summary ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->summary) 0 0 0
739 0 for my $msg ( keys %$msglist ) {
740 0 ▶ next if $local and not $msglist->{$msg}{local};
Branch: 1 branch
BranchTrueFalseTotal
if $local and not $msglist->{$msg}{"local"} 0 0 0
Condition0%0/3
$local and not $msglist->{$msg}{"local"}
!ll&&!rl&&r
000
MC/DC0%0/2
$local and not $msglist->{$msg}{"local"}
$local not $msglist->{$msg}{"local"}
Truth table0%0/3
A and not(B)
A= $localB= not $msglist->{$msg}{"local"}
ABresult
0X0
100
111
741 0 ▶ next if $remote and not $msglist->{$msg}{remote};
Branch: 1 branch
BranchTrueFalseTotal
if $remote and not $msglist->{$msg}{"remote"} 0 0 0
Condition0%0/3
$remote and not $msglist->{$msg}{"remote"}
!ll&&!rl&&r
000
MC/DC0%0/2
$remote and not $msglist->{$msg}{"remote"}
$remote not $msglist->{$msg}{"remote"}
Truth table0%0/3
A and not(B)
A= $remoteB= not $msglist->{$msg}{"remote"}
ABresult
0X0
100
111
742  
743 0 $self->show_msg_info($msg);
744 }
745 }
746  
747 0 $self->stats;
748 0 return;
749 }
750  
751 =head2 view_msg($msg_id)
752  
753 View a message in the queue
754  
755 =cut
756  
757 0 ▶sub view_msg {
Subroutine view_msg: not called CC=6 SCAR=37.4
Pod documented
758 0 my $self = shift;
759 0 my ($msg_id) = @_;
760  
761 0 ▶ if ( $msg_id =~ /\D/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($msg_id =~ /\D/) 0 0 0
762 0 warn "$msg_id is not a valid message number!\n";
763 0 return;
764 }
765  
766 # Search message
767 0 my $ok = 0;
768 0 my $queue = $self->queue;
769 0 for my $msg ( keys %{ $self->msglist } ) {
770 0 ▶ if ( $msg =~ /\/$msg_id$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($msg =~ m[/$msg_id$]) 0 0 0
771 0 $ok = 1;
772 0 print "\n --------------\nMESSAGE NUMBER $msg_id \n --------------\n";
773 0 open( my $msg_fh, '<', "${queue}mess/$msg" );
774 0 ▶ print while <$msg_fh>;
Branch: 1 branch
BranchTrueFalseTotal
defined($_ = readline $msg_fh) and do { print $_ } 0 0 0
775 0 close($msg_fh);
776 0 last;
777 }
778 }
779  
780 # If the message isn't found, print a notice
781 0 ▶ if ( !$ok ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 0 0
782 0 warn "Message $msg_id not found in the queue!\n";
783 }
784  
785 0 return;
786 }
787  
788 =head2 trash_msgs()
789  
790 Delete all of the messages whose ids are in the C<all_to_delete>
791 array.
792  
793 =cut
794  
795 0 ▶sub trash_msgs {
Subroutine trash_msgs: not called CC=9 SCAR=45.0
Pod documented
796 0 my $self = shift;
797  
798 0 my $queue = $self->queue;
799 0 my $msglist = $self->msglist;
800 0 my @todelete = ();
801 0 my $grouped = 0;
802 0 my $deleted = 0;
803 0 foreach my $msg ( $self->all_to_delete ) {
804 0 $grouped++;
805 0 $deleted++;
806 0 my $msgno = ( split( /\//, $msg ) )[1];
807 0 ▶ if ( $msglist->{$msg}{bounce} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($msglist->{$msg}{"bounce"}) 0 0 0
808 0 push @todelete, "${queue}bounce/$msgno";
809 }
810 0 push @todelete, "${queue}mess/$msg", "${queue}info/$msg";
811 0 ▶ if ( $msglist->{$msg}{remote} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($msglist->{$msg}{"remote"}) 0 0 0
812 0 push @todelete, "${queue}remote/$msg";
813 }
814 0 ▶ if ( $msglist->{$msg}{local} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($msglist->{$msg}{"local"}) 0 0 0
815 0 push @todelete, "${queue}local/$msg";
816 }
817 0 ▶ if ( $msglist->{$msg}{todo} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($msglist->{$msg}{"todo"}) 0 0 0
818 0 push @todelete, "${queue}todo/$msglist->{$msg}{'todo'}",
819 "${queue}intd/$msglist->{$msg}{'todo'}";
820 }
821 0 ▶ if ( $grouped == 11 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($grouped == 11) 0 0 0
822 0 unlink @todelete;
823 0 @todelete = ();
824 0 $grouped = 0;
825 }
826 }
827 0 ▶ if ($grouped) {
Branch: 1 branch
BranchTrueFalseTotal
if ($grouped) 0 0 0
828 0 unlink @todelete;
829 }
830 0 ▶ my $msg_str = $deleted == 1 ? 'message' : 'messages';
Branch: 1 branch
BranchTrueFalseTotal
$deleted == 1 ? : 0 0 0
831 0 warn "Deleted $deleted $msg_str from queue\n";
832 0 return;
833 }
834  
835 =head2 flag_msgs()
836  
837 Flag all messages whose ids are in the C<all_to_flag> array.
838  
839 =cut
840  
841 0 ▶sub flag_msgs {
Subroutine flag_msgs: not called CC=4 SCAR=30.0
Pod documented
842 0 my $self = shift;
843  
844 0 my $queue = $self->queue;
845 0 my $now = time;
846 0 my @flagqueue = ();
847 0 my $flagged = 0;
848 0 foreach my $msg ( $self->all_to_flag ) {
849 0 push @flagqueue, "${queue}info/$msg";
850 0 $flagged++;
851 0 ▶ if ( $flagged == 30 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flagged == 30) 0 0 0
852 0 utime $now, $now, @flagqueue;
853 0 $flagged = 0;
854 0 @flagqueue = ();
855 }
856 }
857 0 ▶ if ($flagged) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flagged) 0 0 0
858 0 utime $now, $now, @flagqueue;
859 }
860 0 return;
861 }
862  
863 =head2 del_msg($msg_id)
864  
865 Given a message id, add that message to the list of messages to delete.
866  
867 The actual deletion is carried out by C<trash_msgs>.
868  
869 =cut
870  
871 0 ▶sub del_msg {
Subroutine del_msg: not called CC=5 SCAR=34.0
Pod documented
872 0 my $self = shift;
873 0 my ($msg_id) = @_;
874  
875 0 ▶ if ( $msg_id =~ /\D/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($msg_id =~ /\D/) 0 0 0
876 0 warn "$msg_id is not a valid message number!\n";
877 0 return;
878 }
879  
880 # Search message
881 0 my $ok = 0;
882 0 for my $msg ( keys %{ $self->msglist } ) {
883 0 ▶ if ( $msg =~ /\/$msg_id$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($msg =~ m[/$msg_id$]) 0 0 0
884 0 $ok = 1;
885 0 $self->add_to_delete($msg);
886 0 last;
887 }
888 }
889  
890 # If the message isn't found, print a notice
891 0 ▶ if ( !$ok ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 0 0
892 0 warn "Message $msg_id not found in the queue!\n";
893 }
894  
895 0 return;
896 }
897  
898 =head2 del_msg_from_sender($sender)
899  
900 Given a sender's email address, add all messages from that sender to the
901 list of messages to delete.
902  
903 The actual deletion is carried out by C<trash_msgs>.
904  
905 =cut
906  
907 0 ▶sub del_msg_from_sender {
Subroutine del_msg_from_sender: not called CC=5 SCAR=34.0
Pod documented
908 0 my $self = shift;
909 0 my ($sender) = @_;
910  
911 0 warn "Looking for messages from $sender\n";
912  
913 0 my $ok = 0;
914 0 for my $msg ( keys %{ $self->msglist } ) {
915 0 ▶ if ( $self->msglist->{$msg}{sender} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->msglist->{$msg}{"sender"}) 0 0 0
916 0 my $msg_sender = $self->get_sender($msg);
917 0 ▶ if ( $msg_sender eq $sender ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($msg_sender eq $sender) 0 0 0
918 0 $ok = 1;
919 0 $self->add_to_delete($msg);
920 }
921 }
922 }
923  
924 # If no messages are found, print a notice
925 0 ▶ if ( !$ok ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 0 0
926 0 warn "No messages from $sender found in the queue!\n";
927 }
928  
929 0 return;
930 }
931  
932 =head2 del_msg_from_sender_r($sender)
933  
934 Given a sender's email address, add all messages from that sender to the
935 list of messages to delete.
936  
937 This method treats $sender as a regex.
938  
939 The actual deletion is carried out by C<trash_msgs>.
940  
941 =cut
942  
943 0 ▶sub del_msg_from_sender_r {
Subroutine del_msg_from_sender_r: not called CC=5 SCAR=34.0
Pod documented
944 0 my $self = shift;
945 0 my ($sender_re) = @_;
946  
947 0 warn "Looking for messages from senders matching $sender_re\n";
948  
949 0 my $ok = 0;
950 0 for my $msg ( keys %{ $self->msglist } ) {
951 0 ▶ if ( $self->msglist->{$msg}{sender} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->msglist->{$msg}{"sender"}) 0 0 0
952 0 my $msg_sender = $self->get_sender($msg);
953 0 ▶ if ( $msg_sender =~ /$sender_re/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($msg_sender =~ /$sender_re/) 0 0 0
954 0 $ok = 1;
955 0 $self->add_to_delete($msg);
956 }
957 }
958 }
959  
960 # If no messages are found, print a notice
961 0 ▶ if ( !$ok ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 0 0
962 0 warn "No messages from senders matching ",
963 "$sender_re found in the queue!\n";
964 }
965  
966 0 return;
967 }
968  
969 =head2 del_msg_header($header_re, $is_case_sensitive)
970  
971 Given a regex, add all messages with headers that match the regex to the
972 list of messages to delete.
973  
974 The actual deletion is carried out by C<trash_msgs>.
975  
976 =cut
977  
978 0 ▶sub del_msg_header_r {
Subroutine del_msg_header_r: not called CC=8 SCAR=42.8
Pod undocumented
979 0 my $self = shift;
980 0 my ( $header_re, $is_case_sensitive ) = @_;
981  
982 0 warn "Looking for messages with headers matching $header_re\n";
983  
984 0 ▶ $header_re = "(?i)$header_re" if $is_case_sensitive;
Branch: 1 branch
BranchTrueFalseTotal
if $is_case_sensitive 0 0 0
985  
986 0 my $queue = $self->queue;
987 0 my $ok = 0;
988 0 for my $msg ( keys %{ $self->msglist } ) {
989 0 ▶ open( my $msg_fh, '<', "${queue}mess/$msg" )
Branch: 1 branch
BranchTrueFalseTotal
open my $msg_fh, "<", "${queue}mess/$msg" or die "cannot open message $msg! Is qmail-send running?\n" 0 0 0
990 or die("cannot open message $msg! Is qmail-send running?\n");
991 0 ▶ while (<$msg_fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $msg_fh)) 0 0 0
992 0 chomp;
993 0 ▶ last if ! /\S/; # End of headers
Branch: 1 branch
BranchTrueFalseTotal
unless /\S/ 0 0 0
994 0 ▶ if (/$header_re/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/$header_re/) 0 0 0
995 0 $ok = 1;
996 0 $self->add_to_delete($msg);
997 0 last;
998 }
999 }
1000 0 close($msg_fh);
1001  
1002 }
1003  
1004 # If no messages are found, print a notice
1005 0 ▶ if ( !$ok ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 0 0
1006 0 warn "No messages with headers matching $header_re ",
1007 "found in the queue!\n";
1008 }
1009  
1010 0 return;
1011 }
1012  
1013 =head2 del_msg_body_r($body_re, $is_case_sensitive)
1014  
1015 Given a regex, add all messages with a body that matches the regex to the
1016 list of messages to delete.
1017  
1018 The actual deletion is carried out by C<trash_msgs>.
1019  
1020 =cut
1021  
1022 0 ▶sub del_msg_body_r {
Subroutine del_msg_body_r: not called CC=9 SCAR=45.0
Pod documented
1023 0 my $self = shift;
1024 0 my ( $body_re, $is_case_sensitive ) = @_;
1025  
1026 0 my $queue = $self->queue;
1027  
1028 0 warn "Looking for messages with body matching $body_re\n";
1029  
1030 0 ▶ $body_re = "(?i)$body_re" if $is_case_sensitive;
Branch: 1 branch
BranchTrueFalseTotal
if $is_case_sensitive 0 0 0
1031  
1032 0 my $ok = 0;
1033 0 for my $msg ( keys %{ $self->msglist } ) {
1034 0 ▶ open( my $msg_fh, '<', "${queue}mess/$msg" )
Branch: 1 branch
BranchTrueFalseTotal
open my $msg_fh, "<", "${queue}mess/$msg" or die "cannot open message $msg! Is qmail-send running?\n" 0 0 0
1035 or die("cannot open message $msg! Is qmail-send running?\n");
1036 # Skip headers
1037 0 ▶ while (<$msg_fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $msg_fh)) 0 0 0
1038 0 chomp;
1039 0 ▶ last if !/\S/;
Branch: 1 branch
BranchTrueFalseTotal
unless /\S/ 0 0 0
1040 }
1041 0 ▶ while (<$msg_fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $msg_fh)) 0 0 0
1042 0 ▶ if (/$body_re/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/$body_re/) 0 0 0
1043 0 $ok = 1;
1044 0 $self->add_to_delete($msg);
1045 0 last;
1046 }
1047 }
1048 0 close($msg_fh);
1049 }
1050  
1051 # If no messages are found, print a notice
1052 0 ▶ if ( !$ok ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 0 0
1053 0 warn "No messages with body matching $body_re found in the queue!\n";
1054 }
1055  
1056 0 return;
1057 }
1058  
1059 =head2 del_msg_subj($subject, $is_case_sensitive)
1060  
1061 Given a subject, add all messages with that subject to the list of messages
1062 to delete.
1063  
1064 The actual deletion is carried out by C<trash_msgs>.
1065  
1066 =cut
1067  
1068 0 ▶sub del_msg_subj {
Subroutine del_msg_subj: not called CC=5 SCAR=34.0
Pod documented
1069 0 my $self = shift;
1070 0 my ($subject) = @_;
1071  
1072 0 warn "Looking for messages with Subject: $subject\n";
1073  
1074 # Search messages
1075 0 my $ok = 0;
1076 0 for my $msg ( keys %{ $self->msglist } ) {
1077 0 my $msgsub = $self->get_subject($msg);
1078  
1079 0 ▶ if ( $msgsub and $msgsub =~ /$subject/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($msgsub and $msgsub =~ /$subject/) 0 0 0
Condition0%0/3
$msgsub and $msgsub =~ /$subject/
!ll&&!rl&&r
000
MC/DC0%0/2
$msgsub and $msgsub =~ /$subject/
$msgsub $msgsub =~ /$subject/
Truth table0%0/3
A and B
A= $msgsubB= $msgsub =~ /$subject/
ABresult
0X0
100
111
1080 0 $ok = 1;
1081 0 $self->add_to_delete($msg);
1082 }
1083  
1084 }
1085  
1086 # If no messages are found, print a notice
1087 0 ▶ if ( !$ok ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 0 0
1088 0 warn "No messages matching Subject \"$subject\" found in the queue!\n";
1089 }
1090  
1091 0 return;
1092 }
1093  
1094 =head2 del_all()
1095  
1096 Delete all messages in the queue.
1097  
1098 The actual deletion is carried out by C<trash_msgs>.
1099  
1100 =cut
1101  
1102 0 ▶sub del_all {
Subroutine del_all: not called CC=3 SCAR=24.8
Pod documented
1103 0 my $self = shift;
1104  
1105 # Search messages
1106 0 my $ok = 0;
1107 0 for my $msg ( keys %{ $self->msglist } ) {
1108 0 $ok = 1;
1109 0 $self->add_to_delete($msg);
1110 }
1111  
1112 # If no messages are found, print a notice
1113 0 ▶ if ( !$ok ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 0 0
1114 0 warn "No messages found in the queue!\n";
1115 }
1116  
1117 0 return;
1118 }
1119  
1120 =head2 flag_remote($recipient_re)
1121  
1122 Flag all remote messages whose recipient matches the given regex.
1123  
1124 =cut
1125  
1126 0 ▶sub flag_remote {
Subroutine flag_remote: not called CC=6 SCAR=37.4
Pod documented
1127 0 my $self = shift;
1128 0 my ($recipient_re) = @_;
1129  
1130 0 my $queue = $self->queue;
1131  
1132 0 warn "Looking for messages with recipients in $recipient_re\n";
1133  
1134 0 my $ok = 0;
1135 0 for my $msg ( keys %{ $self->msglist } ) {
1136 0 ▶ if ( $self->msglist->{$msg}{remote} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->msglist->{$msg}{"remote"}) 0 0 0
1137 0 ▶ open( my $msg_fh, '<', "${queue}remote/$msg" )
Branch: 1 branch
BranchTrueFalseTotal
open my $msg_fh, "<", "${queue}remote/$msg" or die "cannot open remote file for message $msg! ", "Is qmail-send running?\n" 0 0 0
1138 or die( "cannot open remote file for message $msg! ",
1139 "Is qmail-send running?\n" );
1140 0 my $recipients = <$msg_fh>;
1141 0 chomp($recipients);
1142 0 close($msg_fh);
1143 0 ▶ if ( $recipients =~ /$recipient_re/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($recipients =~ /$recipient_re/) 0 0 0
1144 0 $ok = 1;
1145 0 $self->add_to_flag($msg);
1146 0 warn "Message $msg being tagged for earlier retry ",
1147 "(and lengthened stay in queue)!\n";
1148 }
1149 }
1150 }
1151  
1152 # If no messages are found, print a notice
1153 0 ▶ if ( !$ok ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 0 0
1154 0 warn "No messages with recipients in $recipient_re ",
1155 "found in the queue!\n";
1156 0 return;
1157 }
1158  
1159 0 $self->flag_msgs;
1160  
1161 0 return;
1162 }
1163  
1164 =head2 stats()
1165  
1166 Display statistics about the queue.
1167  
1168 =cut
1169  
1170 0 ▶sub stats {
Subroutine stats: not called CC=6 SCAR=37.4
Pod documented
1171 0 my $self = shift;
1172  
1173 0 my $total = 0;
1174 0 my $l = 0;
1175 0 my $r = 0;
1176 0 my $b = 0;
1177 0 my $t = 0;
1178  
1179 0 foreach my $msg ( keys %{ $self->msglist } ) {
1180 0 $total++;
1181 0 ▶ $self->msglist->{$msg}{local} && $l++;
Branch: 1 branch
BranchTrueFalseTotal
$self->msglist->{$msg}{"local"} and ++$l 0 0 0
1182 0 ▶ $self->msglist->{$msg}{remote} && $r++;
Branch: 1 branch
BranchTrueFalseTotal
$self->msglist->{$msg}{"remote"} and ++$r 0 0 0
1183 0 ▶ $self->msglist->{$msg}{bounce} && $b++;
Branch: 1 branch
BranchTrueFalseTotal
$self->msglist->{$msg}{"bounce"} and ++$b 0 0 0
1184 0 ▶ $self->msglist->{$msg}{todo} && $t++;
Branch: 1 branch
BranchTrueFalseTotal
$self->msglist->{$msg}{"todo"} and ++$t 0 0 0
1185 }
1186  
1187 0 my $colours = $self->colours;
1188 0 my ( $cstat, $cend ) = @{$colours}{qw[stat end]};
1189  
1190 0 print <<"END_OF_STATS";
1191 ${cstat}Total messages${cend}: $total
1192 ${cstat}Messages with local recipients${cend}: $l
1193 ${cstat}Messages with remote recipients${cend}: $r
1194 ${cstat}Messages with bounces${cend}: $b
1195 ${cstat}Messages in preprocess${cend}: $t
1196 END_OF_STATS
1197 0 return;
1198 }
1199  
1200 =head2 qmail_pid()
1201  
1202 Get the pid of the qmail daemon
1203  
1204 =cut
1205  
1206 0 ▶sub qmail_pid {
Subroutine qmail_pid: not called CC=3 SCAR=24.8
Pod documented
1207 0 my $self = shift;
1208 0 my $pidcmd = $self->commands->{pid};
1209 0 my $qmpid = `$pidcmd`;
1210 0 ▶ return 0 unless $qmpid;
Branch: 1 branch
BranchTrueFalseTotal
unless $qmpid 0 0 0
1211 0 chomp($qmpid);
1212 0 $qmpid =~ s/\s+//g;
1213 0 ▶ return 0 if $qmpid =~ /\D/;
Branch: 1 branch
BranchTrueFalseTotal
if $qmpid =~ /\D/ 0 0 0
1214 0 return $qmpid;
1215 }
1216  
1217 =head2 usage()
1218  
1219 Display usage information.
1220  
1221 =cut
1222  
1223 1 ▶sub usage {
Subroutine usage: called CC=1 SCAR=0.0
Pod documented
1224 1 print <<"END_OF_HELP";
1225 $me v$VERSION
1226 Copyright (c) 2016 Dave Cross <dave\@perlhacks.com>
1227 Based on original version by Michele Beltrame <mb\@italpro.net>
1228  
1229 Available parameters:
1230 -a : try to send queued messages now (qmail must be running)
1231 -l : list message queues
1232 -L : list local message queue
1233 -R : list remote message queue
1234 -s : show some statistics
1235 -mN : display message number N
1236 -dN : delete message number N
1237 -fsender : delete message from sender
1238 -F're' : delete message from senders matching regular expression re
1239 -Stext : delete all messages that have/contain text as Subject
1240 -h're' : delete all messages with headers matching regular expression
1241 re (case insensitive)
1242 -b're' : delete all messages with body matching regular expression
1243 re (case insensitive)
1244 -H're' : delete all messages with headers matching regular expression
1245 re (case sensitive)
1246 -B're' : delete all messages with body matching regular expression
1247 re (case sensitive)
1248 -t're' : flag messages with recipients in regular expression 're' for
1249 earlier retry (note: this lengthens the time message can
1250 stay in queue)
1251 -D : delete all messages in the queue (local and remote)
1252 -V : print program version
1253 -? : Display this help
1254  
1255 Additional (optional) parameters:
1256 -c : display colored output
1257 -N : list message numbers only
1258 (to be used either with -l, -L or -R)
1259  
1260 You can view/delete multiple message i.e. -d123 -m456 -d567
1261  
1262 END_OF_HELP
1263 }
1264  
1265 1 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
1266 1 __PACKAGE__->meta->make_immutable;
1267  
1268 =head2 version()
1269  
1270 Display the version.
1271  
1272 =cut
1273  
1274 0 ▶sub version {
Subroutine version: not called CC=1 SCAR=6.9
Pod documented
1275 0 print "$me v$VERSION\n";
1276 0 return;
1277 }
1278  
1279 =head2 AUTHOR
1280  
1281 Copyright (c) 2016 Dave Cross E<lt>dave@perlhacks.comE<gt>
1282  
1283 Based on original version by Michele Beltrame E<lt>mb@italpro.netE<gt>
1284  
1285 =head2 LICENCE
1286  
1287 This program is distributed under the GNU GPL.
1288 For more information have a look at http://www.gnu.org
1289  
1290 =cut
1291  
1292 1 1;
↑ Summary