]> git.donarmstrong.com Git - debbugs.git/commitdiff
add learn subcommand and examples
authorDon Armstrong <don@donarmstrong.com>
Wed, 21 Feb 2018 20:58:57 +0000 (12:58 -0800)
committerDon Armstrong <don@donarmstrong.com>
Wed, 21 Feb 2018 20:58:57 +0000 (12:58 -0800)
bin/debbugs-spam

index b172e97e36508ebd70b35e3b28fa2ae826ff314c..ba026da4547af6a1ac3b79d07df1e9af9c5b940f 100755 (executable)
@@ -78,11 +78,25 @@ id
 Mark messages as ham if there is a regex match to subject or message
 id
 
+=item B<learn>
+
+Learn from messages which are ham/spam
+
 =back
 
 
 =head1 EXAMPLES
 
+Start spamd:
+
+  /usr/sbin/spamd --socketpath=/home/debbugs/spamd_socket \
+      --nouser-config --cf='include /home/debbugs/.spamassassin/user_prefs' \
+      --cf='allow_user_rules 1' --allow-tell;
+
+Then score bugs:
+
+  debbugs-spam --spamc-opts '-U' --spamc-opts '/home/debbugs/spamd_socket' \
+      score 859123;
 
 =cut
 
@@ -130,6 +144,8 @@ my %subcommands =
                     },
      'mark-ham' => {function => \&mark_ham,
                    },
+     'learn' => {fuction => \&learn,
+                },
      'help' => {function => sub {pod2usage({verbose => 2});}}
     );
 
@@ -207,6 +223,40 @@ sub mark_it {
     }
 }
 
+sub learn {
+    my ($options,$opts,$config,$argv) = @_;
+    for my $bug_num (@{$argv}) {
+        my $spam = Debbugs::Log::Spam->new(bug_num => $bug_num) or
+            die "Unable to open bug log spam for $bug_num";
+        foreachmsg(sub {
+                       my ($bn,$rec,$mid) = @_;
+                       my $score;
+                       if ($spam->is_spam($mid)) {
+                           $score //=
+                               spam_score($rec,$options->{spamc},
+                                          [@{$options->{spamc_opts}},
+                                           '-L','spam'
+                                          ]
+                                         );
+                           print STDERR "learning spam" if $DEBUG;
+                       } elsif ($spam->is_ham($mid)) {
+                           $score //=
+                               spam_score($rec,$options->{spamc},
+                                          [@{$options->{spamc_opts}},
+                                           '-L','ham'
+                                          ]
+                                         );
+                           print STDERR "learning ham" if $DEBUG;
+                       } else {
+                           print STDERR "not learning" if $DEBUG;
+                       }
+                       print STDERR " from $mid" if $DEBUG;
+                   },
+                   $bug_num
+                  );
+    }
+}
+
 
 sub score_bug {
     my ($options,$opts,$config,$argv) = @_;