You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@spamassassin.apache.org by Wade Rossmann <ro...@realestatewebmasters.com> on 2014/02/20 21:07:24 UTC
SQL preferences when invoked via perl
I'm using SpamAssassin via MimeDefang and trying to load user
preferences in from a mySQL database. I've tried adding the
user_scores_sql_* config items in the config file, but these seem to be
ignored by everything except spamd -q. I've more or less given up on
making that work [but if someone can clue me in that would be great] so
I've written my own bit of code into mimedefang-filter to pull the
preferences out of the database and then appending them with
post_config_text.
However, it appears that none of these preferences are being applied
other than required_hits. For example, the preferences pulled for a test
user are:
required_hits 7
report_safe 0
rewrite_header Subject [SPAM]
score BANG_OPRAH 3.0
required_hits 8
required_hits 9
Where required_hits is set to 5 in the config file, 7 is in the global
settings in DB, 8 in domain in DB, and 9 in the user's settings in DB. A
test message <https://gist.github.com/Sammitch/9084301> I've devised
triggers the message to be tagged, and the report shows a required score
of 9, but the subject is not modified, and the BANG_OPRAH rule is not
listed as matching.
Can someone enlighten me on the proper way to specify per-user settings
pulled from a database when SpamAssassin is invoked via perl?
--
Wade Rossmann
Systems Administrator
rossmann.wade@realestatewebmasters.com
Re: SQL preferences when invoked via perl
Posted by "Kevin A. McGrail" <KM...@PCCC.com>.
On 2/20/2014 3:07 PM, Wade Rossmann wrote:
> I'm using SpamAssassin via MimeDefang and trying to load user
> preferences in from a mySQL database. I've tried adding the
> user_scores_sql_* config items in the config file, but these seem to
> be ignored by everything except spamd -q. I've more or less given up
> on making that work [but if someone can clue me in that would be
> great] so I've written my own bit of code into mimedefang-filter to
> pull the preferences out of the database and then appending them with
> post_config_text.
>
> However, it appears that none of these preferences are being applied
> other than required_hits. For example, the preferences pulled for a
> test user are:
>
> required_hits 7
> report_safe 0
> rewrite_header Subject [SPAM]
> score BANG_OPRAH 3.0
> required_hits 8
> required_hits 9
>
> Where required_hits is set to 5 in the config file, 7 is in the global
> settings in DB, 8 in domain in DB, and 9 in the user's settings in DB.
> A test message <https://gist.github.com/Sammitch/9084301> I've devised
> triggers the message to be tagged, and the report shows a required
> score of 9, but the subject is not modified, and the BANG_OPRAH rule
> is not listed as matching.
>
> Can someone enlighten me on the proper way to specify per-user
> settings pulled from a database when SpamAssassin is invoked via perl?
Likely a better question for the MD list but here's some answers:
A - The API is different than using Spamc or SpamAssassin.
For example, required_hits will be used. And you can set a config file
with BANG_OPRAH 3.0.
But these settings ONLY affect SA's implementation of the API:
report_safe 0
rewrite_header Subject [SPAM]
Think of the API as returning a 0/1 for yes or no this is spam.
Then in MD, you've got to implement report_safe and rewrite_header for
the subject if that's what you want. Many people on MD list can help
with that as I think it's been documented over the years.
B - Two ways to implement SA with MD:
One: I spawn out and call spamc from MD. I already run a bunch of spamd
servers so this makes most sense to me:
http://www.pccc.com/downloads/MIMEDefang/contrib/spamc/SpamassassinSpamcSpamd%20-%20Kwiki.pdf
Two:
load_scoreonly_sql() and signal_user_changed() are likely what you need
such as these pseudo cut and paste of a live filter:
my $sa_object;
if ($Features{"SpamAssassin"}) {
#$SALocalTestsOnly = 1; # I do NOT want network tests
$SALocalTestsOnly = 0; # I DO want network tests
#Switched to $sa_object as returned by SA per DFS
$sa_object = spam_assassin_init() if defined(spam_assassin_init());
# If you want to use auto-whitelisting:
if (defined($sa_object)) {
use Mail::SpamAssassin::SQLBasedAddrList;
my $awl = Mail::SpamAssassin::SQLBasedAddrList->new();
$sa_object->set_persistent_address_list_factory($awl) if
defined($awl);
}
}
Then in filter_end you need logic to figure out your username:
#IF WE HAVE A USER, A SPAMASSASSIN OBJECT, AND THEY AREN'T AN
AUTHORIZED USER, SET THE USER PREFERENCES
if ($username ne '' && $Features{"SpamAssassin"} &&
$authorized_sender < 1) {
$sa_object->load_scoreonly_sql($username) || md_syslog('warning',
"load_scoreonly_sql failed for $recip");
$sa_object->signal_user_changed({ username => $username},
user_dir => undef);
md_syslog('warning', "Enabling SPAM Filter from MD for $username
- $recip_list");
}
then call ($hits, $req, $names, $report) = spam_assassin_check();
regards,
KAM