You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by gb...@apache.org on 2023/05/02 08:17:57 UTC

svn commit: r1909554 - /spamassassin/trunk/sa-awl.raw

Author: gbechis
Date: Tue May  2 08:17:57 2023
New Revision: 1909554

URL: http://svn.apache.org/viewvc?rev=1909554&view=rev
Log:
add a --dry-run option to check which entries will be cleaned
before removing records

Modified:
    spamassassin/trunk/sa-awl.raw

Modified: spamassassin/trunk/sa-awl.raw
URL: http://svn.apache.org/viewvc/spamassassin/trunk/sa-awl.raw?rev=1909554&r1=1909553&r2=1909554&view=diff
==============================================================================
--- spamassassin/trunk/sa-awl.raw (original)
+++ spamassassin/trunk/sa-awl.raw Tue May  2 08:17:57 2023
@@ -41,7 +41,7 @@ BEGIN {                          # see c
 
 sub usage {
   die "
-usage: sa-awl [--clean] [--min n] [dbfile]
+usage: sa-awl [--clean] [--dry-run] [--min n] [dbfile]
 ";
 }
 
@@ -51,10 +51,11 @@ use POSIX qw(locale_h setsid sigprocmask
 
 POSIX::setlocale(LC_TIME,'C');
 
-our ( $opt_clean, $opt_min, $opt_help );
+our ( $opt_clean, $opt_dryrun, $opt_min, $opt_help );
 
 GetOptions(
   'clean'		=> \$opt_clean,
+  'dry-run'		=> \$opt_dryrun,
   'min:i'		=> \$opt_min,
   'help'		=> \$opt_help
 ) or usage();
@@ -79,7 +80,7 @@ if ($#ARGV == -1) {
 }
 
 my %h;
-if ($opt_clean) {
+if ($opt_clean and not $opt_dryrun) {
   tie %h, "AnyDBM_File",$db, O_RDWR,0600
       or die "Cannot open r/w file $db: $!\n";
 } else {
@@ -87,11 +88,15 @@ if ($opt_clean) {
       or die "Cannot open file $db: $!\n";
 }
 
-if (!$opt_clean) {  # just pretend to be cleaning
+if (not $opt_clean or $opt_dryrun) {  # just pretend to be cleaning
   while (my($key, $count) = each %h) {
     next if $key =~ /totscore$/;
+    next if (($count >= $opt_min) and ($opt_dryrun and $opt_clean));
     my $totscore = $h{"$key|totscore"};
     next unless defined($totscore);
+    if($opt_dryrun and $opt_clean) {
+      printf("cleaning [dry-run]: ");
+    }
     printf("%8.1f %15s  --  %s\n",
 	   $totscore/$count, sprintf("(%.1f/%d)",$totscore,$count), $key);
   }
@@ -130,7 +135,7 @@ sa-awl - examine and manipulate SpamAssa
 
 =head1 SYNOPSIS
 
-B<sa-awl> [--clean] [--min n] [dbfile]
+B<sa-awl> [--clean] [--dry-run] [--min n] [dbfile]
 
 =head1 DESCRIPTION
 
@@ -148,6 +153,12 @@ The default is C<$HOME/.spamassassin/aut
 Clean out infrequently-used AWL entries.  The C<--min> switch can be
 used to select the threshold at which entries are kept or deleted.
 
+=item --dry-run
+
+When specified with th C<--clean> option it displays the infrequently-used AWL entries
+that will be deleted. The C<--min> switch can be
+used to select the threshold at which entries are kept or deleted.
+
 =item --min n
 
 Select the threshold at which entries are kept or deleted when C<--clean> is