[Mimedefang] TIP: 2 ways NOT to get MD to report autolearning info and 1 way that works.

Bill Cole mdlist-20140424 at billmail.scconsult.com
Tue Jun 23 11:27:51 EDT 2015

I'm dropping this here in the hope that some future MD user who wants Sa 
learning stats will be saved hours of fumbling and mystification.

Long story short: If you want to understand how to do something with MD, 
don't be afraid to read the code. Diane writes well-formatted 
well-commented Perl that is very easy to follow. I resisted that for a 
week of banging my head against an ugly and growing uglier 
mimedefang-filter (you'd be ugly too, if you'd had a decade of random 
amateur surgery!) and I *THINK* I have worked out how to extract & log 
the SpamAssassin autolearning details for each message...

General Tips:

1. DO NOT call spam_assassin_check() until you're well and truly 
finished with $SASpamTester.
2. DO NOT try to run the 'learner' methods on $SASpamTester

Those are ways to get a lot of complaints in your logs about trying to 
get SA metadata after metadata->finish() has been called. You will also 
be able to get *something* as learner parameters but it will be like any 
reanimation of the dead: you won't get back anything you really want.

The code I have evolved to using (inside the filter_end() implementation 
in mimedefang-filter) which seems to be working and is no longer giving 
me only "no" and "unavailable" as learning status and is giving 
non-insane values for the various sub-scores is this:

# Get SA autolearn status/subscores
# NOTE: MUST be done before spam_assassin_check finishes the object
my $SAStatus = spam_assassin_status();
my $ALStatus = $SAStatus->get_autolearn_status();
my $ALPoints = $SAStatus->get_autolearn_points();
my $ALHead = $SAStatus->get_head_only_points();
my $ALBody = $SAStatus->get_body_only_points();
my $ALLearned = $SAStatus->get_learned_points();
md_syslog('info', "SA-LEARN: stat=$ALStatus pts=$ALPoints h=$ALHead 
b=$ALBody l=$ALLearned");

Anyone may use that at will and at their own risk.  The result is log 
lines like these for each message:

Jun 23 02:44:35 toaster mimedefang.pl[94919]: 3mFyl504sDz1Yj70H: 
SA-LEARN: stat=spam autolearn_force=no pts=27.95 h=20.047 b=7.903 l=4.2
Jun 23 02:45:07 toaster mimedefang.pl[94919]: 3mFylg3lLlz1Yj71N: 
SA-LEARN: stat=ham autolearn_force=no pts=-0.91 h=1.001 b=-0.001 l=-2.1
Jun 23 02:57:32 toaster mimedefang.pl[94919]: 3mFz220VrSz1Yj71q: 
SA-LEARN: stat=no autolearn_force=no pts=0.691 h=-0.198 b=-0.001 l=-2.1
Jun 23 03:02:46 toaster mimedefang.pl[94919]: 3mFz826FlNz1Yj72M: 
SA-LEARN: stat=ham autolearn_force=no pts=-0.91 h=1.001 b=-0.001 l=-2.1
Jun 23 03:12:26 toaster mimedefang.pl[94919]: 3mFzMF10Q9z1Yj730: 
SA-LEARN: stat=ham autolearn_force=no pts=-0.756 h=1.255 b=-0.001 l=-2.1
Jun 23 03:19:42 toaster mimedefang.pl[94919]: 3mFzWZ1yklz1Yj753: 
SA-LEARN: stat=no autolearn_force=no pts=22.831 h=22.147 b=0.684 l=4.2
Jun 23 03:19:46 toaster mimedefang.pl[94919]: 3mFzWf6FkNz1Yj75F: 
SA-LEARN: stat=ham autolearn_force=no pts=-0.91 h=1.001 b=-0.001 l=-2.1

More information about the MIMEDefang mailing list