line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: Siesta.pm 1435 2003-10-17 13:35:50Z richardc $ |
2
|
|
|
|
|
|
|
package Siesta; |
3
|
18
|
|
|
18
|
|
103
|
use strict; |
|
18
|
|
|
|
|
35
|
|
|
18
|
|
|
|
|
687
|
|
4
|
18
|
|
|
18
|
|
101
|
use vars qw/$VERSION $tt/; |
|
18
|
|
|
|
|
32
|
|
|
18
|
|
|
|
|
1057
|
|
5
|
|
|
|
|
|
|
$VERSION = '0.66'; |
6
|
|
|
|
|
|
|
|
7
|
18
|
|
|
18
|
|
11210
|
use Siesta::List; |
|
18
|
|
|
|
|
64
|
|
|
18
|
|
|
|
|
216
|
|
8
|
18
|
|
|
18
|
|
787
|
use Siesta::Message; |
|
18
|
|
|
|
|
39
|
|
|
18
|
|
|
|
|
155
|
|
9
|
|
|
|
|
|
|
|
10
|
18
|
|
|
18
|
|
17686
|
use IO::File; |
|
18
|
|
|
|
|
192158
|
|
|
18
|
|
|
|
|
2487
|
|
11
|
18
|
|
|
18
|
|
18227
|
use File::Find::Rule qw/find/; |
|
18
|
|
|
|
|
160039
|
|
|
18
|
|
|
|
|
172
|
|
12
|
18
|
|
|
18
|
|
1048
|
use File::Basename qw/fileparse/; |
|
18
|
|
|
|
|
42
|
|
|
18
|
|
|
|
|
1662
|
|
13
|
18
|
|
|
18
|
|
107
|
use UNIVERSAL::require; |
|
18
|
|
|
|
|
41
|
|
|
18
|
|
|
|
|
172
|
|
14
|
18
|
|
|
18
|
|
17787
|
use Template; |
|
18
|
|
|
|
|
443319
|
|
|
18
|
|
|
|
|
204
|
|
15
|
|
|
|
|
|
|
|
16
|
18
|
|
|
18
|
|
648
|
use Carp qw(croak); |
|
18
|
|
|
|
|
39
|
|
|
18
|
|
|
|
|
14366
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 NAME |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
Siesta - the Siesta mailing list manager. |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 METHODS |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head2 ->new |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=cut |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub new { |
29
|
1
|
|
|
1
|
1
|
13
|
my $referent = shift; |
30
|
1
|
|
|
|
|
5
|
my %args = @_; |
31
|
1
|
|
33
|
|
|
7
|
my $class = ref $referent || $referent; |
32
|
|
|
|
|
|
|
|
33
|
1
|
|
|
|
|
3
|
my $storage = delete $args{storage}; |
34
|
|
|
|
|
|
|
|
35
|
1
|
|
|
|
|
4
|
my $self = bless {}, $class; |
36
|
1
|
|
|
|
|
6
|
$self->log("instantiated a Siesta", 7); |
37
|
1
|
|
|
|
|
4
|
$self; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head2 ->process( mail => $message, action => $action, list => $list ) |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
process a mail |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
action may be C, C, or C |
45
|
|
|
|
|
|
|
defaults to C |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
mail must be either an anonymous array or a filehandle to read the |
48
|
|
|
|
|
|
|
message body from |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
list must be the identifier of a mailing list |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=cut |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub process { |
56
|
1
|
|
|
1
|
1
|
10519
|
my $self = shift; |
57
|
1
|
|
|
|
|
7
|
my %args = @_; |
58
|
1
|
|
50
|
|
|
8
|
my $action = $args{action} || 'post'; |
59
|
1
|
|
|
|
|
13
|
my $mail = Siesta::Message->new( $args{mail} ); |
60
|
1
|
|
|
|
|
14
|
my $list = Siesta::List->load( $args{list} ); |
61
|
|
|
|
|
|
|
|
62
|
1
|
|
|
|
|
9
|
$self->log("processing $action", 1); |
63
|
1
|
|
|
|
|
8
|
$mail->plugins( [ $list->plugins( $action ) ] ); |
64
|
1
|
|
|
|
|
4337
|
$mail->process; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
my $sender; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head2 ->sender |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Return the current sender. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
The default is Siesta::Send::Sendmail. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
See B for other details. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=cut |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub sender { |
80
|
14
|
50
|
|
14
|
1
|
216
|
$sender || Siesta->set_sender('Sendmail'); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head2 ->set_sender ($class, @options) |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Set the current sender to the given class. |
86
|
|
|
|
|
|
|
This will pass on any options you give it automatically. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=cut |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub set_sender { |
91
|
18
|
|
|
18
|
1
|
44
|
my $self = shift; |
92
|
18
|
|
|
|
|
42
|
my $class = shift; |
93
|
18
|
50
|
|
|
|
91
|
return unless $class; |
94
|
|
|
|
|
|
|
|
95
|
18
|
|
|
|
|
54
|
$class = "Siesta::Send::$class"; |
96
|
18
|
50
|
|
|
|
155
|
$class->require |
97
|
|
|
|
|
|
|
or die "Couldn't require '$class': $UNIVERSAL::require::ERROR"; |
98
|
18
|
|
|
|
|
317
|
$sender = $class->new(@_); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head2 ->log ($message, $level) |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Log message as long as level is below the value set in |
104
|
|
|
|
|
|
|
I<$Siesta::Config::LOG_LEVEL>; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
The lower the log level, the more important the error. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
The default is 3. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=cut |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
my $logger; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub log { |
115
|
33
|
|
|
33
|
1
|
37334
|
my $self = shift; |
116
|
33
|
50
|
|
|
|
141
|
my $message = shift |
117
|
|
|
|
|
|
|
or croak "need a message to log"; |
118
|
|
|
|
|
|
|
|
119
|
33
|
|
66
|
|
|
158
|
my $level = shift || $Siesta::Config::LOG_LEVEL; |
120
|
|
|
|
|
|
|
|
121
|
33
|
100
|
|
|
|
103
|
unless ($logger) { |
122
|
6
|
50
|
|
|
|
78
|
$logger = IO::File->new(">>$Siesta::Config::LOG_PATH") |
123
|
|
|
|
|
|
|
or die "Couldn't open file $Siesta::Config::LOG_PATH for appending\n"; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
33
|
|
|
|
|
2992
|
my $date = localtime; |
127
|
33
|
100
|
|
|
|
350
|
print $logger "$date $message $level\n" |
128
|
|
|
|
|
|
|
if $level >= $Siesta::Config::LOG_LEVEL; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head2 ->available_plugins |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Return the name of every plugin on the system. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=cut |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub available_plugins { |
139
|
1
|
|
|
1
|
1
|
4819596
|
my $self = shift; |
140
|
1
|
|
|
|
|
3
|
my @dirs; |
141
|
|
|
|
|
|
|
|
142
|
1
|
|
|
|
|
4
|
foreach my $dir ( map { "$_/Siesta/Plugin" } @INC ) { |
|
11
|
|
|
|
|
28
|
|
143
|
11
|
100
|
66
|
|
|
455
|
push @dirs, $dir if ( -e $dir && -d $dir ); |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
1
|
|
|
|
|
9
|
my @files = find( name => "*.pm", in => \@dirs ); |
147
|
1
|
|
|
|
|
2379
|
my @plugins; |
148
|
|
|
|
|
|
|
|
149
|
1
|
|
|
|
|
4
|
foreach my $file (@files) { |
150
|
30
|
|
|
|
|
559
|
my ($name) = fileparse($file, qr{\.pm}); |
151
|
30
|
|
|
|
|
83
|
push @plugins, $name; |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
1
|
|
|
|
|
5
|
my %plugins = map { $_ => 1 } @plugins; |
|
30
|
|
|
|
|
48
|
|
155
|
|
|
|
|
|
|
|
156
|
1
|
|
|
|
|
24
|
return sort keys %plugins; |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head2 ->bake ( $template, $options ) |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
$options, if present, is a hash reference |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
Returns the results of baking B<$template> with the variables |
164
|
|
|
|
|
|
|
from B<$options> mixed in. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=cut |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
sub bake { |
169
|
14
|
|
|
14
|
1
|
705
|
my $self = shift; |
170
|
14
|
|
|
|
|
34
|
my $template = shift; |
171
|
|
|
|
|
|
|
|
172
|
14
|
|
|
|
|
73
|
my %opts = @_; |
173
|
|
|
|
|
|
|
|
174
|
14
|
|
66
|
|
|
238
|
$tt ||= Template->new({ INCLUDE_PATH => $Siesta::Config::MESSAGES }); |
175
|
|
|
|
|
|
|
|
176
|
14
|
|
|
|
|
171075
|
my $body; |
177
|
14
|
50
|
|
|
|
130
|
$tt->process($template, \%opts, \$body) |
178
|
|
|
|
|
|
|
or die "Couldn't process message template |
179
|
|
|
|
|
|
|
'${Siesta::Config::ROOT}/messages/$template' |
180
|
|
|
|
|
|
|
because : ",$tt->error(); |
181
|
|
|
|
|
|
|
|
182
|
14
|
|
|
|
|
40929
|
return $body; |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head1 COPYING |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
Licensed under the same terms as Perl itself. |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=head1 SEE ALSO |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
L, L, L, L |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=cut |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
1; |
196
|
|
|
|
|
|
|
|