Quarantine/Sendmail.pm untested

filter: Statementstmt 0.0% 0 / 53 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 76 CC 6 SCAR 21.7
CC
6
Cov
0%
sendmail_or_queue
20.0
sendmail_or_postpone
12.0
send_postponed
2.0
CRAP 8.8
1 # Copyright(C) 2006 David Muir Sharnoff <muir@idiom.com>
2 #
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License along
14 # with this program; if not, write to the Free Software Foundation, Inc.,
15 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 #
17 # This software is available without the GPL: please write if you need
18 # a non-GPL license. All submissions of patches must come with a
19 # copyright grant so that David Sharnoff remains able to change the
20 # license at will.
21  
22 package Qpsmtpd::Plugin::Quarantine::Sendmail;
23  
24 use Mail::SendVarious;
25 use Mail::SendVarious qw(@to_rejected $mail_error);
26 use Qpsmtpd::Plugin::Quarantine::Common;
27 use OOPS;
28 use Time::HiRes qw(time);
29 require Exporter;
30 use strict;
31  
32 our @ISA = qw(Exporter);
33 our @EXPORT = qw(sendmail_or_queue sendmail_or_postpone send_postponed);
34  
35 our @postponed;
36  
37 sub sendmail_or_postpone
38 {
39 my (%options) = @_;
40 if (sendmail(%options)) {
41 return 1 unless @to_rejected;
42 $options{to} = [ @to_rejected ];
43 }
44 push(@postponed, \%options);
45 }
46  
47 sub send_postponed
48 {
49 while (@postponed) {
50 sendmail_or_queue(%{shift(@postponed)});
51 }
52 }
53  
54 sub sendmail_or_queue
55 {
56 my (%options) = @_;
57 if (sendmail(%options)) {
58 return 1 unless @to_rejected;
59 $options{to} = [ @to_rejected ];
60 }
61 for my $o (keys %options) {
62 delete $options{$o} if ref($options{$o}) eq 'CODE';
63 }
64 $options{first_attempt} = time;
65 $options{attempt_count} = 1;
66 $options{last_attempt} = time;
67 $options{last_error} = $mail_error;
68 my $options = \%options;
69 bless $options, 'Quarantine::QueuedMail';
70 transaction(sub {
71 my $oops = get_oops();
72 my $qd = $oops->{quarantine};
73 my $mqueue = $qd->{mqueue};
74 $mqueue->{$$.time()} = $options;
75 $oops->commit();
76 });
77 }
78  
79 1;