line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mail::QmailQueue; |
2
|
|
|
|
|
|
|
# $Id: QmailQueue.pm,v 1.2 2002/04/05 13:07:58 ikechin Exp $ |
3
|
1
|
|
|
1
|
|
560
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
4
|
1
|
|
|
1
|
|
4
|
use vars qw($VERSION); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
46
|
|
5
|
1
|
|
|
1
|
|
833
|
use IO::Pipe; |
|
1
|
|
|
|
|
9888
|
|
|
1
|
|
|
|
|
44
|
|
6
|
1
|
|
|
1
|
|
13
|
use IO::Handle; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
34
|
|
7
|
1
|
|
|
1
|
|
7
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
673
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
$VERSION = '0.03'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
13
|
0
|
|
0
|
|
|
|
my $bin = shift || "/var/qmail/bin/qmail-queue"; |
14
|
0
|
|
|
|
|
|
my $self = { |
15
|
|
|
|
|
|
|
bin => $bin |
16
|
|
|
|
|
|
|
}; |
17
|
0
|
|
|
|
|
|
bless $self,$class; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub mail { |
21
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
22
|
0
|
0
|
|
|
|
|
if ($_[0]) { |
23
|
0
|
|
|
|
|
|
$self->{mail} = shift; |
24
|
|
|
|
|
|
|
} |
25
|
0
|
|
|
|
|
|
$self->{mail}; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
*sender = \&mail; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub recipient { |
31
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
32
|
0
|
0
|
|
|
|
|
if (@_) { |
33
|
0
|
0
|
|
|
|
|
if ($self->{recipient}) { |
34
|
0
|
|
|
|
|
|
push(@{$self->{recipient}},@_); |
|
0
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
} else { |
36
|
0
|
|
|
|
|
|
$self->{recipient} = [ @_ ]; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
0
|
|
|
|
|
|
$self->{recipient}; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
*to = \&recipient; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub data { |
45
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
46
|
0
|
0
|
|
|
|
|
if ($_[0]) { |
47
|
0
|
|
|
|
|
|
my $data = $_[0]; |
48
|
0
|
0
|
|
|
|
|
if (ref($data) eq 'ARRAY') { |
49
|
0
|
|
|
|
|
|
for my $d(@{$data}) { |
|
0
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
$d =~ s/\r\n/\n/g; |
51
|
0
|
|
|
|
|
|
$self->{data} .= $d; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
else { |
55
|
0
|
|
|
|
|
|
$data =~ s/\r\n/\n/g; |
56
|
0
|
|
|
|
|
|
$self->{data} .= $data; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
0
|
|
|
|
|
|
$self->{data}; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub datasend { |
63
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
64
|
0
|
|
|
|
|
|
$self->data(shift); |
65
|
0
|
|
|
|
|
|
$self->send; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub send { |
69
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
70
|
0
|
|
|
|
|
|
my $data = IO::Pipe->new; |
71
|
0
|
|
|
|
|
|
my $addr = IO::Pipe->new; |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
foreach my $key (qw(recipient mail data)) { |
74
|
0
|
0
|
|
|
|
|
if (!$self->{$key}) { |
75
|
0
|
|
|
|
|
|
carp "please specify $key"; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} |
78
|
0
|
0
|
|
|
|
|
$self->{data} .= "\n" unless $self->{data} =~ m/\n$/s; |
79
|
0
|
0
|
|
|
|
|
if (my $pid = fork) { |
|
|
0
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
$data->writer; |
81
|
0
|
|
|
|
|
|
$addr->writer; |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
$data->print($self->data); |
84
|
0
|
|
|
|
|
|
$data->close; |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
$addr->print("F" . $self->mail . "\0"); |
87
|
0
|
|
|
|
|
|
foreach my $rcpt (@{$self->recipient}) { |
|
0
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
$addr->print("T" . $rcpt . "\0"); |
89
|
|
|
|
|
|
|
} |
90
|
0
|
|
|
|
|
|
$addr->print("\0"); |
91
|
0
|
|
|
|
|
|
$addr->close; |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
delete $self->{mail}; |
94
|
0
|
|
|
|
|
|
delete $self->{recipient}; |
95
|
0
|
|
|
|
|
|
delete $self->{data}; |
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
wait; |
98
|
|
|
|
|
|
|
} elsif (defined $pid) { |
99
|
0
|
|
|
|
|
|
my $fd0 = IO::Handle->new->fdopen(0,"w"); |
100
|
0
|
|
|
|
|
|
my $fd1 = IO::Handle->new->fdopen(1,"w"); |
101
|
0
|
|
|
|
|
|
$data->reader(); |
102
|
0
|
|
|
|
|
|
$addr->reader(); |
103
|
0
|
|
|
|
|
|
$fd0->fdopen(fileno($data),"r"); |
104
|
0
|
|
|
|
|
|
$fd1->fdopen(fileno($addr),"r"); |
105
|
0
|
0
|
|
|
|
|
exec($self->{bin}) || carp $!; |
106
|
0
|
|
|
|
|
|
exit; |
107
|
|
|
|
|
|
|
} else { |
108
|
0
|
|
|
|
|
|
carp "Cannot fork!!"; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub quit { |
114
|
|
|
|
|
|
|
# do nothing |
115
|
0
|
|
|
0
|
0
|
|
1; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
1; |
119
|
|
|
|
|
|
|
__END__ |