home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / glimpsehttp / news / sievenews < prev    next >
Encoding:
Text File  |  1995-05-16  |  3.1 KB  |  122 lines

  1. #!/usr/local/bin/perl 
  2. #/****************************************************
  3. #**
  4. #** SOURCE NAME | sievenews, (Sieve News)
  5. #**             | 
  6. #**    SYNOPSIS | sievenews [-n cfgfile]
  7. #**             | 
  8. #** DESCRIPTION | sievenews goes directory ./groups/<newsgroup>/
  9. #**             | and kills all the articles that match the kill-file
  10. #**             | for each newsgroup.
  11. #**             | Use this program if you add something to the kill-file
  12. #**             | and you want to kill the previous articles
  13. #**             | that match the pattern.
  14. #**             | 
  15. #** SEE ALSO    | NOTES section and 'getnews' program
  16. #**             | 
  17. #**     CHANGES | Programmer:         Date:     Reason/Comments
  18. #**        | Pavel Klark         04-08-94  VERSION 1.0 (sievenews)
  19. #**             | 
  20. #**       NOTES | sievenews needs a file named getnews.cfg to read
  21. #**             | its newsgroup and last message number from.
  22. #**             | See 'getnews' NOTES section for details
  23. #**             | 
  24. #**     AUTHOR  | Pavel Clark, paul@cs.arizona.edu
  25. #**             | 
  26. #****************************************************/
  27.  
  28. $gunzip = "/usr/local/bin/gunzip";
  29.  
  30. # Your kill-file top directory, the following is trn's default
  31. $kill_location = $ENV{'HOME'} . "/News";
  32.  
  33. require 'getopts.pl' ;
  34. # -n getnews : Name of getnews file; default getnews.cfg
  35. $opt_n = 'getnews.cfg';
  36. &Getopts ('n:');
  37.  
  38. $VERSION = '1.0';
  39.  
  40. $newsfile = $opt_n;
  41.  
  42. $killcount = 0;
  43. open(TMP,"du -s groups|");
  44. $_ = <TMP>;
  45. ($oldvolume,$dummy) = split;
  46. close(TMP);
  47.  
  48. open(GRP, "<$newsfile") || die "Could not open $newsfile: $!";
  49. group: while(<GRP>)
  50. {
  51.     chop;
  52.     ($grp, $lgot) = split;
  53.     print "Sieving newsgroup $grp:\n";
  54.     #this select will block until the server gives us something.
  55.     #
  56.     # access kill-file (in directory $HOME/News)
  57.     #
  58.     $killfile = $grp;
  59.     $killfile =~ s|\.|/|g;
  60.     $killfile = "$kill_location/$killfile/KILL";
  61.     if (open(KILL, $killfile))
  62.     {
  63.         @karray = ();
  64.         while (<KILL>) {
  65.             ($dummy,$pattern) = split(m|/|);
  66.             push(@karray,$pattern) if $pattern;
  67.         }
  68.     } else {
  69.         print "No kill-file for group $grp\n";
  70.         next group;
  71.     }
  72.     close(KILL);
  73. # We now slurp the article's header into the array article...
  74.     $dir = "./groups/$grp"; #directory for saved files
  75.     opendir(DIR,$dir);
  76.     while ($i = readdir(DIR)) {
  77.         next if $i =~ /^\./;
  78.         $file = "$dir/$i";
  79.         $name = $file;
  80.         $name = "exec $unzip <$1|" if $file =~ /^(.*)\.gz/;
  81.         @article = ();
  82.         open(ARTICLE,$name) ||
  83.             warn "Cannot open article file $file\n";
  84.         while (<ARTICLE>) {
  85.             last if /^$/;
  86.             push(@article,$_);
  87.         }
  88.         close(ARTICLE);
  89.         &testandkill;
  90.     }
  91.     closedir(DIR);
  92. }
  93. close(GRP);
  94.  
  95. open(TMP,"du -s groups|");
  96. $_ = <TMP>;
  97. ($newvolume,$dummy) = split;
  98. close(TMP);
  99.  
  100. printf "Killed %d articles, got %dK space\n",
  101.     $killcount,$oldvolume-$newvolume;
  102.  
  103. # We parse through @article to search for kill-patterns
  104. # kills article and returns undef if matches, otherwise returns 1
  105. sub testandkill
  106. {
  107.     local($pattern,$author,$subject,$ID,$date);
  108.  
  109.     scan: foreach (@article) {
  110.         foreach $pattern (@karray) {
  111.             if (/$pattern/) {
  112.                 print "* Killing article $file:\n\t$_";
  113.                 unlink($file) ||
  114.                     warn "Cannot unlink $file\n";
  115.                 ++$killcount;
  116.                 return undef;
  117.             }
  118.         }
  119.     }
  120.     return 1;
  121. }
  122.