home *** CD-ROM | disk | FTP | other *** search
- #!/usr/local/bin/perl
- #/****************************************************
- #**
- #** SOURCE NAME | sievenews, (Sieve News)
- #** |
- #** SYNOPSIS | sievenews [-n cfgfile]
- #** |
- #** DESCRIPTION | sievenews goes directory ./groups/<newsgroup>/
- #** | and kills all the articles that match the kill-file
- #** | for each newsgroup.
- #** | Use this program if you add something to the kill-file
- #** | and you want to kill the previous articles
- #** | that match the pattern.
- #** |
- #** SEE ALSO | NOTES section and 'getnews' program
- #** |
- #** CHANGES | Programmer: Date: Reason/Comments
- #** | Pavel Klark 04-08-94 VERSION 1.0 (sievenews)
- #** |
- #** NOTES | sievenews needs a file named getnews.cfg to read
- #** | its newsgroup and last message number from.
- #** | See 'getnews' NOTES section for details
- #** |
- #** AUTHOR | Pavel Clark, paul@cs.arizona.edu
- #** |
- #****************************************************/
-
- $gunzip = "/usr/local/bin/gunzip";
-
- # Your kill-file top directory, the following is trn's default
- $kill_location = $ENV{'HOME'} . "/News";
-
- require 'getopts.pl' ;
- # -n getnews : Name of getnews file; default getnews.cfg
- $opt_n = 'getnews.cfg';
- &Getopts ('n:');
-
- $VERSION = '1.0';
-
- $newsfile = $opt_n;
-
- $killcount = 0;
- open(TMP,"du -s groups|");
- $_ = <TMP>;
- ($oldvolume,$dummy) = split;
- close(TMP);
-
- open(GRP, "<$newsfile") || die "Could not open $newsfile: $!";
- group: while(<GRP>)
- {
- chop;
- ($grp, $lgot) = split;
- print "Sieving newsgroup $grp:\n";
- #this select will block until the server gives us something.
- #
- # access kill-file (in directory $HOME/News)
- #
- $killfile = $grp;
- $killfile =~ s|\.|/|g;
- $killfile = "$kill_location/$killfile/KILL";
- if (open(KILL, $killfile))
- {
- @karray = ();
- while (<KILL>) {
- ($dummy,$pattern) = split(m|/|);
- push(@karray,$pattern) if $pattern;
- }
- } else {
- print "No kill-file for group $grp\n";
- next group;
- }
- close(KILL);
- # We now slurp the article's header into the array article...
- $dir = "./groups/$grp"; #directory for saved files
- opendir(DIR,$dir);
- while ($i = readdir(DIR)) {
- next if $i =~ /^\./;
- $file = "$dir/$i";
- $name = $file;
- $name = "exec $unzip <$1|" if $file =~ /^(.*)\.gz/;
- @article = ();
- open(ARTICLE,$name) ||
- warn "Cannot open article file $file\n";
- while (<ARTICLE>) {
- last if /^$/;
- push(@article,$_);
- }
- close(ARTICLE);
- &testandkill;
- }
- closedir(DIR);
- }
- close(GRP);
-
- open(TMP,"du -s groups|");
- $_ = <TMP>;
- ($newvolume,$dummy) = split;
- close(TMP);
-
- printf "Killed %d articles, got %dK space\n",
- $killcount,$oldvolume-$newvolume;
-
- # We parse through @article to search for kill-patterns
- # kills article and returns undef if matches, otherwise returns 1
- sub testandkill
- {
- local($pattern,$author,$subject,$ID,$date);
-
- scan: foreach (@article) {
- foreach $pattern (@karray) {
- if (/$pattern/) {
- print "* Killing article $file:\n\t$_";
- unlink($file) ||
- warn "Cannot unlink $file\n";
- ++$killcount;
- return undef;
- }
- }
- }
- return 1;
- }
-