line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# -*- Mode: Perl -*- |
2
|
|
|
|
|
|
|
# Active.pm -- |
3
|
|
|
|
|
|
|
# ITIID : $ITI$ $Header $__Header$ |
4
|
|
|
|
|
|
|
# Author : Ulrich Pfeifer |
5
|
|
|
|
|
|
|
# Created On : Sat Sep 28 14:15:22 1996 |
6
|
|
|
|
|
|
|
# Last Modified By: Ulrich Pfeifer |
7
|
|
|
|
|
|
|
# Last Modified On: Thu Feb 27 16:31:03 1997 |
8
|
|
|
|
|
|
|
# Language : CPerl |
9
|
|
|
|
|
|
|
# Update Count : 86 |
10
|
|
|
|
|
|
|
# Status : Unknown, Use with caution! |
11
|
|
|
|
|
|
|
# |
12
|
|
|
|
|
|
|
# (C) Copyright 1996, Universität Dortmund, all rights reserved. |
13
|
|
|
|
|
|
|
# |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
package NNML::Active; |
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
49
|
|
18
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION @ISA @EXPORT_OK $ACTIVE); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
99
|
|
19
|
|
|
|
|
|
|
require Exporter; |
20
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
21
|
|
|
|
|
|
|
@EXPORT_OK = qw($ACTIVE); |
22
|
|
|
|
|
|
|
|
23
|
1
|
|
|
1
|
|
619
|
use NNML::Config qw($Config); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
154
|
|
24
|
1
|
|
|
1
|
|
589
|
use NNML::Group; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
27
|
|
25
|
1
|
|
|
1
|
|
6
|
use IO::File; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
116
|
|
26
|
1
|
|
|
1
|
|
14
|
use File::Path; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
1901
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
$VERSION = '0.01'; |
29
|
|
|
|
|
|
|
$ACTIVE = bless {}, 'NNML::Active'; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my %GROUP; |
32
|
|
|
|
|
|
|
my $TIME = 0; |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
0
|
0
|
|
sub last_change { $TIME } |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub _read_active { |
37
|
0
|
|
|
0
|
|
|
%GROUP = (); |
38
|
0
|
|
|
|
|
|
$TIME = time; |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
my $fh = new IO::File "<" . $Config->active; |
41
|
0
|
0
|
|
|
|
|
die "Could not read active file" unless defined $fh; |
42
|
0
|
|
|
|
|
|
my $line; |
43
|
0
|
|
|
|
|
|
while (defined ($line = <$fh>)) { |
44
|
0
|
|
|
|
|
|
chomp($line); |
45
|
0
|
|
|
|
|
|
my ($group, $max, $min, $post) = split ' ', $line; |
46
|
0
|
|
|
|
|
|
my $dir = $group; |
47
|
0
|
|
|
|
|
|
$dir =~ s:\.:/:g; |
48
|
0
|
|
|
|
|
|
$dir = $Config->base . '/' . $dir; |
49
|
0
|
0
|
|
|
|
|
if (-e $dir) { |
50
|
0
|
|
|
|
|
|
my $ctime = (stat($dir))[10]; |
51
|
0
|
|
|
|
|
|
$GROUP{$group} = NNML::Group->new(name => $group, |
52
|
|
|
|
|
|
|
dir => $dir, |
53
|
|
|
|
|
|
|
min => $min, |
54
|
|
|
|
|
|
|
max => $max, |
55
|
|
|
|
|
|
|
post => $post, |
56
|
|
|
|
|
|
|
ctime => $ctime, |
57
|
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub _write_active { |
63
|
0
|
|
|
0
|
|
|
my $active = $Config->active; |
64
|
|
|
|
|
|
|
|
65
|
0
|
0
|
|
|
|
|
unless (rename $active, "$active~") { |
66
|
0
|
|
|
|
|
|
print "Could not backup '$active': $!\n"; |
67
|
0
|
|
|
|
|
|
return 0; |
68
|
|
|
|
|
|
|
} |
69
|
0
|
|
|
|
|
|
my $fh = new IO::File ">" . $active; |
70
|
0
|
0
|
|
|
|
|
unless (defined $fh) { |
71
|
0
|
|
|
|
|
|
print "Could not write active file\n"; |
72
|
0
|
|
|
|
|
|
return 0; |
73
|
|
|
|
|
|
|
} |
74
|
0
|
|
|
|
|
|
for (sort keys %GROUP) { |
75
|
0
|
|
|
|
|
|
$fh->printf("%s %d %d %s\n", $_, |
76
|
|
|
|
|
|
|
$GROUP{$_}->max, $GROUP{$_}->min, $GROUP{$_}->post, |
77
|
|
|
|
|
|
|
) |
78
|
|
|
|
|
|
|
} |
79
|
0
|
|
|
|
|
|
$fh->close; |
80
|
0
|
|
|
|
|
|
$TIME = time; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub _update { |
84
|
0
|
|
|
0
|
|
|
my $mtime = (stat($Config->active))[9]; |
85
|
0
|
0
|
|
|
|
|
_read_active if $mtime > $TIME; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub group { |
89
|
0
|
|
|
0
|
0
|
|
my ($self, $group) = @_; |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
_update; |
92
|
0
|
0
|
|
|
|
|
if (exists $GROUP{$group}) { |
93
|
0
|
|
|
|
|
|
return $GROUP{$group}; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub delete_group { |
98
|
0
|
|
|
0
|
0
|
|
my ($self, $group) = @_; |
99
|
0
|
|
|
|
|
|
my $dir; |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
_update; |
102
|
0
|
0
|
|
|
|
|
unless (exists $GROUP{$group}) { |
103
|
0
|
|
|
|
|
|
return; |
104
|
|
|
|
|
|
|
} else { |
105
|
0
|
|
|
|
|
|
$dir = $GROUP{$group}->dir; |
106
|
0
|
|
|
|
|
|
delete $GROUP{$group}; |
107
|
|
|
|
|
|
|
} |
108
|
0
|
|
|
|
|
|
_write_active; |
109
|
0
|
|
|
|
|
|
rmtree($dir,1,1); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
sub groups { |
112
|
0
|
|
|
0
|
0
|
|
_update; |
113
|
0
|
|
|
|
|
|
values %GROUP; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub newgroups { |
117
|
0
|
|
|
0
|
0
|
|
my ($self, $time) = @_; |
118
|
0
|
|
|
|
|
|
my @result; |
119
|
|
|
|
|
|
|
|
120
|
0
|
|
|
|
|
|
_update; |
121
|
0
|
|
|
|
|
|
for (keys %GROUP) { |
122
|
|
|
|
|
|
|
# printf "%s %d %d\n", $_, $GROUP{$_}->ctime, $time; |
123
|
0
|
0
|
|
|
|
|
if ($GROUP{$_}->ctime > $time) { |
124
|
0
|
|
|
|
|
|
unshift @result, $_; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
} |
127
|
0
|
|
|
|
|
|
@result; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub list_match { |
131
|
0
|
|
|
0
|
0
|
|
my ($self, $expr) = @_; |
132
|
|
|
|
|
|
|
|
133
|
0
|
|
|
|
|
|
$expr =~ s/\./\\./g; |
134
|
0
|
|
|
|
|
|
$expr =~ s/\*/.*/g; |
135
|
0
|
|
|
|
|
|
my (@expr) = split /,/, $expr; |
136
|
|
|
|
|
|
|
|
137
|
0
|
|
|
|
|
|
_update; |
138
|
|
|
|
|
|
|
|
139
|
0
|
|
|
|
|
|
my $neg = join '|', grep s/^!//, @expr; |
140
|
0
|
|
|
|
|
|
my $pos = join '|', grep /^[^!]/, @expr; |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
#print "pos = $pos\n"; |
143
|
|
|
|
|
|
|
#print "neg = $neg\n"; |
144
|
|
|
|
|
|
|
|
145
|
0
|
|
|
|
|
|
my @result; |
146
|
0
|
|
|
|
|
|
for (sort keys %GROUP) { |
147
|
0
|
0
|
|
|
|
|
next unless /^$pos$/; |
148
|
0
|
0
|
|
|
|
|
next if /^$neg$/; |
149
|
0
|
|
|
|
|
|
push @result, $GROUP{$_}; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
0
|
|
|
|
|
|
@result; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
sub accept_article { |
156
|
0
|
|
|
0
|
0
|
|
my ($self, $header, $head, $body, $create, |
157
|
|
|
|
|
|
|
$afile, $extra_group, @groups) = @_; |
158
|
0
|
|
|
|
|
|
my $group; |
159
|
0
|
|
|
|
|
|
my $any_group = 0; |
160
|
0
|
|
|
|
|
|
my $overwrite_file = $afile; |
161
|
0
|
|
|
|
|
|
my %seen; |
162
|
|
|
|
|
|
|
|
163
|
0
|
|
|
|
|
|
$self->_update; |
164
|
|
|
|
|
|
|
|
165
|
0
|
0
|
0
|
|
|
|
if ($afile and -e $afile) { # xaccept overwrites |
166
|
0
|
|
|
|
|
|
my $fh = new IO::File "> $afile"; |
167
|
0
|
0
|
|
|
|
|
unless (defined $fh) { |
168
|
0
|
|
|
|
|
|
print "Could not write '$afile': $!\n"; |
169
|
0
|
|
|
|
|
|
return 0; |
170
|
|
|
|
|
|
|
} |
171
|
0
|
|
|
|
|
|
$fh->print($head, "\n", $body); |
172
|
0
|
|
|
|
|
|
$fh->close; |
173
|
|
|
|
|
|
|
} |
174
|
0
|
|
|
|
|
|
for $group (@groups) { |
175
|
0
|
0
|
|
|
|
|
next if $seen{$group}++; # do not insert twice |
176
|
0
|
0
|
|
|
|
|
unless (exists $GROUP{$group}) { |
177
|
0
|
0
|
|
|
|
|
next unless $create; # no permission to create group |
178
|
0
|
|
|
|
|
|
my $dir = $group; |
179
|
0
|
|
|
|
|
|
$dir =~ s:\.:/:g; |
180
|
0
|
|
|
|
|
|
$dir = $Config->base . '/' . $dir; |
181
|
0
|
0
|
|
|
|
|
unless (-d $dir) { |
182
|
0
|
0
|
|
|
|
|
unless (mkpath($dir,1,0700)) { |
183
|
0
|
|
|
|
|
|
print "Could not mkpath($dir).\n"; |
184
|
0
|
|
|
|
|
|
return 0; |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
} |
187
|
0
|
|
|
|
|
|
$GROUP{$group} = NNML::Group->new(name => $group, |
188
|
|
|
|
|
|
|
dir => $dir, |
189
|
|
|
|
|
|
|
min => 1, |
190
|
|
|
|
|
|
|
max => 0, |
191
|
|
|
|
|
|
|
post => 'y', |
192
|
|
|
|
|
|
|
ctime => time, |
193
|
|
|
|
|
|
|
); |
194
|
|
|
|
|
|
|
} |
195
|
0
|
|
|
|
|
|
my $ov = $GROUP{$group}->overview; |
196
|
|
|
|
|
|
|
|
197
|
0
|
|
|
|
|
|
my $oano = $GROUP{$group}->article_by_id($header->{'message-id'}); |
198
|
0
|
|
0
|
|
|
|
my $ano = $oano || $GROUP{$group}->add($header->{'message-id'}); |
199
|
0
|
|
|
|
|
|
my $dir = $GROUP{$group}->dir; |
200
|
0
|
|
|
|
|
|
my $file = "$dir/$ano"; |
201
|
|
|
|
|
|
|
|
202
|
0
|
0
|
0
|
|
|
|
if ($ano and $group eq $extra_group) { # force a copy |
203
|
0
|
|
|
|
|
|
$ano = $GROUP{$group}->add($header->{'message-id'}); |
204
|
0
|
|
|
|
|
|
$file = "$dir/$ano"; |
205
|
0
|
|
|
|
|
|
$oano = undef; |
206
|
|
|
|
|
|
|
} else { |
207
|
0
|
0
|
0
|
|
|
|
if (!$oano and -e $file) { |
208
|
0
|
|
|
|
|
|
print "File '$file' already exists\n"; |
209
|
0
|
|
|
|
|
|
return 0; |
210
|
|
|
|
|
|
|
} |
211
|
|
|
|
|
|
|
} |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
# add overview entry if new article number |
214
|
0
|
0
|
|
|
|
|
unless ($oano) { |
215
|
0
|
|
|
|
|
|
my $fh = new IO::File ">> $ov"; |
216
|
0
|
0
|
|
|
|
|
unless (defined $fh) { |
217
|
0
|
|
|
|
|
|
print "Could not write '$ov': $!\n"; |
218
|
0
|
|
|
|
|
|
return 0; |
219
|
|
|
|
|
|
|
} |
220
|
0
|
|
|
|
|
|
$header->{subject} =~ s/\s/ /; |
221
|
0
|
|
|
|
|
|
$fh->printf("%d\t%s\t%s\t%s\t%s\t%s\t%d\t%s\t%s\t\n", |
222
|
|
|
|
|
|
|
$ano, |
223
|
|
|
|
|
|
|
$header->{subject}, |
224
|
|
|
|
|
|
|
$header->{from}, |
225
|
|
|
|
|
|
|
$header->{date}, |
226
|
|
|
|
|
|
|
$header->{'message-id'}, |
227
|
|
|
|
|
|
|
$header->{references}, |
228
|
|
|
|
|
|
|
length($body), |
229
|
|
|
|
|
|
|
$header->{lines}, |
230
|
|
|
|
|
|
|
$header->{xref}); |
231
|
0
|
|
|
|
|
|
$fh->close; |
232
|
|
|
|
|
|
|
} |
233
|
|
|
|
|
|
|
# add the article ... |
234
|
0
|
0
|
|
|
|
|
if (defined $afile) { # as link |
235
|
0
|
0
|
0
|
|
|
|
unless ($oano or link($afile, $file)) { |
236
|
0
|
|
|
|
|
|
print "Could not link '$file' to '$afile': $!\n"; |
237
|
0
|
|
|
|
|
|
return 0; |
238
|
|
|
|
|
|
|
} |
239
|
|
|
|
|
|
|
} else { # as copy |
240
|
0
|
|
|
|
|
|
$afile = $file; |
241
|
0
|
|
|
|
|
|
my $fh = new IO::File "> $file"; |
242
|
0
|
0
|
|
|
|
|
unless (defined $fh) { |
243
|
0
|
|
|
|
|
|
print "Could not write '$file': $!\n"; |
244
|
0
|
|
|
|
|
|
return 0; |
245
|
|
|
|
|
|
|
} |
246
|
0
|
|
|
|
|
|
$fh->print($head, "\n", $body); |
247
|
0
|
|
|
|
|
|
$fh->close; |
248
|
|
|
|
|
|
|
} |
249
|
0
|
|
|
|
|
|
$any_group++; # we posted to one group atleast |
250
|
|
|
|
|
|
|
} |
251
|
0
|
|
0
|
|
|
|
return $self->_write_active || $any_group; |
252
|
|
|
|
|
|
|
} |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
1; |