line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mail::Qmail::Queue::Message; |
2
|
|
|
|
|
|
|
our $VERSION='0.02'; |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# Copyright 2006 Scott Gifford |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# This library is free software; you can redistribute it and/or |
7
|
|
|
|
|
|
|
# modify it under the same terms as Perl itself. |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Mail::Qmail::Queue::Message - Send and/or receive a complete qmail-queue message. |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 SYNOPSIS |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use Mail::Qmail::Queue::Send; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# Read the message |
18
|
|
|
|
|
|
|
my $msg = Mail::Qmail::Queue::Message->receive() |
19
|
|
|
|
|
|
|
or die "Invalid message\n"; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# Change the from |
22
|
|
|
|
|
|
|
my $fr = $msg->from_ref(); |
23
|
|
|
|
|
|
|
$$fr =~ s/\$/-\@[]/; # Enable VERPs |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# Change the to |
26
|
|
|
|
|
|
|
my $to = $msg->to_ref(); |
27
|
|
|
|
|
|
|
push(@$to,'GIFF@cpan.org'); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# Change the body |
30
|
|
|
|
|
|
|
my $br = $msg->body_ref(); |
31
|
|
|
|
|
|
|
$$br =~ s/perl/Pathologically Eclectic Rubbish Lister/ig; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# Now send |
34
|
|
|
|
|
|
|
$msg->send() == 0 |
35
|
|
|
|
|
|
|
or die "Couldn't send message: Exit status $?\n"; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=cut |
38
|
|
|
|
|
|
|
|
39
|
3
|
|
|
3
|
|
51858
|
use Mail::Qmail::Queue::Error qw(:errcodes :fail); |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
795
|
|
40
|
3
|
|
|
3
|
|
1659
|
use Mail::Qmail::Queue::Receive::Body; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
75
|
|
41
|
3
|
|
|
3
|
|
1355
|
use Mail::Qmail::Queue::Receive::Envelope; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
192
|
|
42
|
3
|
|
|
3
|
|
1469
|
use Mail::Qmail::Queue::Send; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
1582
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 DESCRIPTION |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
This module handles mail messages sent and/or received by a program |
47
|
|
|
|
|
|
|
implementing the L interface. |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
You can create a message by providing the body and envelope to the |
50
|
|
|
|
|
|
|
constructor L, or from the file |
51
|
|
|
|
|
|
|
descriptors provided by the qmail-queue interface with the constructor |
52
|
|
|
|
|
|
|
L. |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
You can then modify the message and its envelope, if desired, by |
55
|
|
|
|
|
|
|
getting references to the various parts and modifying their referents. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Finally, you can send the message with the L method. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head2 CONSTRUCTORS |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=over 4 |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=item new ( $body, $from, @to ) |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Create a new mail message with the provided body, from, and to. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=cut |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub new |
70
|
|
|
|
|
|
|
{ |
71
|
2
|
|
|
2
|
1
|
4
|
my $class = shift; |
72
|
2
|
|
|
|
|
6
|
my $self = bless {}, $class; |
73
|
2
|
|
|
|
|
14
|
($self->{_body},$self->{_from},@{$self->{_to}})=@_; |
|
2
|
|
|
|
|
8
|
|
74
|
2
|
|
|
|
|
30
|
$self; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=item receive ( %options ) |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Receive a message with the L protocol. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
This will read the entire message into memory; for very large messages |
82
|
|
|
|
|
|
|
and/or a lot of recipients, see L, |
83
|
|
|
|
|
|
|
L, and |
84
|
|
|
|
|
|
|
L. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Available options are: |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=over 4 |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=item EnvelopeFileHandle |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Read the envelope from the provided FileHandle, instead of the default. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=item BodyFileHandle |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Read the body from the provided FileHandle, instead of the default. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=back |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=back |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=cut |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub receive |
105
|
|
|
|
|
|
|
{ |
106
|
2
|
|
|
2
|
1
|
900
|
my $class = shift; |
107
|
2
|
|
|
|
|
8
|
my(%o) = @_; |
108
|
2
|
|
|
|
|
4
|
my(@qq_env_args,@qq_body_args); |
109
|
2
|
50
|
|
|
|
10
|
if ($o{EnvelopeFileHandle}) |
110
|
|
|
|
|
|
|
{ |
111
|
2
|
|
|
|
|
8
|
push(@qq_env_args,FileHandle => $o{EnvelopeFileHandle}); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
2
|
50
|
|
|
|
6
|
if ($o{BodyFileHandle}) |
115
|
|
|
|
|
|
|
{ |
116
|
2
|
|
|
|
|
6
|
push(@qq_body_args,FileHandle => $o{BodyFileHandle}); |
117
|
|
|
|
|
|
|
} |
118
|
2
|
50
|
|
|
|
18
|
my $qq_env = Mail::Qmail::Queue::Receive::Envelope->new(@qq_env_args) |
119
|
|
|
|
|
|
|
or die "Couldn't get envelope reader: $!\n"; |
120
|
2
|
50
|
|
|
|
20
|
my $qq_body = Mail::Qmail::Queue::Receive::Body->new(@qq_body_args) |
121
|
|
|
|
|
|
|
or die "Couldn't get body reader: $!\n"; |
122
|
2
|
|
|
|
|
8
|
$class->new($qq_body->body,$qq_env->from,$qq_env->to); |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head2 METHODS |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=over 4 |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=item send ( %options ) |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Send the message using the L protocol. |
132
|
|
|
|
|
|
|
The exit status from the C program will be returned, so 0 |
133
|
|
|
|
|
|
|
indicates success. Valid options are the options for |
134
|
|
|
|
|
|
|
Lnew|Mail::Qmail::Queue::Send/new>. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=cut |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub send |
139
|
|
|
|
|
|
|
{ |
140
|
2
|
|
|
2
|
1
|
1138
|
my $self = shift; |
141
|
2
|
50
|
|
|
|
24
|
my $qq_send = Mail::Qmail::Queue::Send->new(@_) |
142
|
|
|
|
|
|
|
or return undef; |
143
|
1
|
|
|
|
|
38
|
return $qq_send->send($self->body,$self->from,$self->to); |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=item from ( ) |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Get the from part of the envelope. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=cut |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub from |
153
|
|
|
|
|
|
|
{ |
154
|
5
|
|
|
5
|
1
|
19
|
my $self = shift; |
155
|
5
|
|
|
|
|
28
|
return $self->{_from}; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=item from_ref ( ) |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
Get a reference to the from part of the envelope. By operating on |
161
|
|
|
|
|
|
|
this reference, you can change the value stored in this object. |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=cut |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
sub from_ref |
166
|
|
|
|
|
|
|
{ |
167
|
2
|
|
|
2
|
1
|
12
|
my $self = shift; |
168
|
2
|
|
|
|
|
14
|
return \$self->{_from} |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=item to ( ) |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Get all to parts of the envelope. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=cut |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
sub to |
178
|
|
|
|
|
|
|
{ |
179
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
180
|
1
|
|
|
|
|
2
|
return @{$self->{_to}}; |
|
1
|
|
|
|
|
40
|
|
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=item to_ref ( ) |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
Get a reference to the list of envelope to items. By modifying this |
186
|
|
|
|
|
|
|
list or its contents, you can change the values within this object. |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=cut |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
sub to_ref |
191
|
|
|
|
|
|
|
{ |
192
|
6
|
|
|
6
|
1
|
16
|
my $self = shift; |
193
|
6
|
|
|
|
|
36
|
return $self->{_to}; |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=item body ( ) |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
Get the body of the message. |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=cut |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
sub body |
203
|
|
|
|
|
|
|
{ |
204
|
5
|
|
|
5
|
1
|
29
|
my $self = shift; |
205
|
5
|
|
|
|
|
37
|
return $self->{_body}; |
206
|
|
|
|
|
|
|
} |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=item body_ref ( ) |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
Get a reference to the body of the message. By modifying this |
211
|
|
|
|
|
|
|
reference, you can change the value of the body within this object. |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=cut |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
sub body_ref |
216
|
|
|
|
|
|
|
{ |
217
|
2
|
|
|
2
|
1
|
1172
|
my $self = shift; |
218
|
2
|
|
|
|
|
10
|
return \$self->{_body}; |
219
|
|
|
|
|
|
|
} |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=back |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=head1 SEE ALSO |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
L, L, |
227
|
|
|
|
|
|
|
L, L. |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=head1 COPYRIGHT |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
Copyright 2006 Scott Gifford. |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or |
234
|
|
|
|
|
|
|
modify it under the same terms as Perl itself. |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=cut |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
1; |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
1; |
242
|
|
|
|
|
|
|
|