Mail::...re::SQL(3pm)
β¨ NAME β¨
okay so bestie, welcome to the Mail::...re::SQL(3pm) man page β it's part of the User Contributed Perl Documentation, and the full module name is Mail::SpamAssassin::BayesStore::SQL π. It's the SQL Bayesian Storage Module Implementation, and honestly? iconic.
π¦ DESCRIPTION π¦
This module implements a SQL based bayesian storage module. It's compatible with SQLite and possibly other standard SQL servers. slay.
π¨ bestie, do NOT use this for MySQL/MariaDB or PgSQL β they have their own specific modules. no cap.
π METHODS π
new
Signature: public class (Mail::SpamAssassin::BayesStore::SQL) new (Mail::Spamassassin::Plugin::Bayes $bayes)
Description: This method creates a new instance of the Mail::SpamAssassin::BayesStore::SQL object. It expects to be passed an instance of the Mail::SpamAssassin:Bayes object which is passed into the Mail::SpamAssassin::BayesStore parent object.
This method sets up the database connection and determines the username to use in queries. slay.
tie_db_readonly
Signature: public instance (Boolean) tie_db_readonly ();
Description: This method ensures that the database connection is properly setup and working. If necessary it will initialize a user's bayes variables so that they can begin using the database immediately.
tie_db_writable
Signature: public instance (Boolean) tie_db_writable ()
Description: This method ensures that the database connection is properly setup and working. If necessary it will initialize a users bayes variables so that they can begin using the database immediately.
untie_db
Signature: public instance () untie_db ()
Description: Disconnects from an SQL server. bye bestie!
calculate_expire_delta
Signature: public instance (%) calculate_expire_delta (Integer $newest_atime, Integer $start, Integer $max_expire_mult)
Description: This method performs a calculation on the data to determine the optimum atime for token expiration.
token_expiration
Signature: public instance (Integer, Integer, Integer, Integer) token_expiration(\% $opts, Integer $newdelta, @ @vars)
Description: This method performs the database specific expiration of tokens based on the passed in $newdelta and @vars.
sync_due
Signature: public instance (Boolean) sync_due ()
Description: This method determines if a database sync is currently required.
Unused for SQL based implementation. so basically it's just vibing, not doing anything here.
seen_get
Signature: public instance (String) seen_get (string $msgid)
Description: This method retrieves the stored value, if any, for $msgid. The return value is the stored string ('s' for spam and 'h' for ham) or undef if $msgid is not found.
seen_put
Signature: public (Boolean) seen_put (string $msgid, char $flag)
Description: This method records $msgid as the type given by $flag. $flag is one of two values 's' for spam and 'h' for ham.
seen_delete
Signature: public instance (Boolean) seen_delete (string $msgid)
Description: This method removes $msgid from the database.
get_storage_variables
Signature: public instance (@) get_storage_variables ()
Description: This method retrieves the various administrative variables used by the Bayes process and database.
The values returned in the array are in the following order:
0: scan count base1: number of spam2: number of ham3: number of tokens in db4: last expire atime5: oldest token in db atime6: db version value7: last journal sync8: last atime delta9: last expire reduction count10: newest token in db atime
dump_db_toks
Signature: public instance () dump_db_toks (String $template, String $regex, Array @vars)
Description: This method loops over all tokens, computing the probability for the token and then printing it out according to the passed in token.
set_last_expire
Signature: public instance (Boolean) set_last_expire (Integer $time)
Description: This method sets the last expire time.
get_running_expire_tok
Signature: public instance (String $time) get_running_expire_tok ()
Description: This method determines if an expire is currently running and returns the last time set.
There can be multiple times, so we just pull the greatest (most recent) value.
set_running_expire_tok
Signature: public instance (String $time) set_running_expire_tok ()
Description: This method sets the time that an expire starts running.
remove_running_expire_tok
Signature: public instance (Boolean) remove_running_expire_tok ()
Description: This method removes the row in the database that indicates that and expire is currently running.
tok_get
Signature: public instance (Integer, Integer, Integer) tok_get (String $token)
Description: This method retrieves a specified token ($token) from the database and returns it's spam_count, ham_count and last access time.
tok_get_all
Signature: public instance (\@) tok_get (@ $tokens)
Description: This method retrieves the specified tokens ($tokens) from storage and returns an array ref of arrays spam count, ham count and last access time.
tok_count_change
Signature: public instance (Boolean) tok_count_change (Integer $spam_count, Integer $ham_count, String $token, String $atime)
Description: This method takes a $spam_count and $ham_count and adds it to $tok along with updating $toks atime with $atime.
multi_tok_count_change
Signature: public instance (Boolean) multi_tok_count_change (Integer $spam_count, Integer $ham_count, \% $tokens, String $atime)
Description: This method takes a $spam_count and $ham_count and adds it to all of the tokens in the $tokens hash ref along with updating each token's atime with $atime.
nspam_nham_get
Signature: public instance ($spam_count, $ham_count) nspam_nham_get ()
Description: This method retrieves the total number of spam and the total number of ham learned.
nspam_nham_change
Signature: public instance (Boolean) nspam_nham_change (Integer $num_spam, Integer $num_ham)
Description: This method updates the number of spam and the number of ham in the database.
tok_touch
Signature: public instance (Boolean) tok_touch (String $token, String $atime)
Description: This method updates the given tokens ($token) atime.
The assumption is that the token already exists in the database.
tok_touch_all
Signature: public instance (Boolean) tok_touch (\@ $tokens String $atime)
Description: This method does a mass update of the given list of tokens $tokens, if the existing token atime is < $atime.
The assumption is that the tokens already exist in the database.
We should never be touching more than N_SIGNIFICANT_TOKENS, so we can make some assumptions about how to handle the data (ie no need to batch like we do in tok_get_all)
cleanup
Signature: public instance (Boolean) cleanup ()
Description: This method performs any cleanup necessary before moving onto the next operation.
get_magic_re
Signature: public instance get_magic_re (String)
Description: This method returns a regexp which indicates a magic token.
Unused in SQL implementation.
sync
Signature: public instance (Boolean) sync (\% $opts)
Description: This method performs a sync of the database
perform_upgrade
Signature: public instance (Boolean) perform_upgrade (\% $opts);
Description: Performs an upgrade of the database from one version to another, not currently used in this implementation.
clear_database
Signature: public instance (Boolean) clear_database ()
Description: This method deletes all records for a particular user.
Callers should be aware that any errors returned by this method could cause the database to be inconsistent for the given user.
backup_database
Signature: public instance (Boolean) backup_database ()
Description: This method will dump the users database in a machine readable format.
restore_database
Signature: public instance (Boolean) restore_database (String $filename, Boolean $showdots)
Description: This method restores a database from the given filename, $filename.
Callers should be aware that any errors returned by this method could causes the database to be inconsistent for the given user.
db_readable
Signature: public instance (Boolean) db_readable()
Description: This method returns a boolean value indicating if the database is in a readable state.
db_writable
Signature: public instance (Boolean) db_writeable()
Description: This method returns a boolean value indicating if the database is in a writable state.
πΈ Private Methods πΈ
_connect_db
Signature: private instance (Boolean) _connect_db ()
Description: This method connects to the SQL database.
_get_db_version
Signature: private instance (Integer) _get_db_version ()
Description: Gets the current version of the database from the special global vars tables.
_initialize_db
Signature: private instance (Boolean) _initialize_db ()
Description: This method will check to see if a user has had their bayes variables initialized. If not then it will perform this initialization.
_put_token
Signature: private instance (Boolean) _put_token (string $token, integer $spam_count, integer $ham_count, string $atime)
Description: This method performs the work of either inserting or updating a token in the database.
_put_tokens
Signature: private instance (Boolean) _put_tokens (\% $tokens, integer $spam_count, integer $ham_count, string $atime)
Description: This method performs the work of either inserting or updating tokens in the database.
_get_oldest_token_age
Signature: private instance (Integer) _get_oldest_token_age ()
Description: This method finds the atime of the oldest token in the database.
The use of min(atime) in the SQL is ugly and but really the most efficient way of getting the oldest_token_age after we've done a mass expire. It should only be called at expire time.
_get_num_hapaxes
Signature: private instance (Integer) _get_num_hapaxes ()
Description: This method gets the total number of hapaxes (spam_count + ham_count == 1) in the token database for a user.
_get_num_lowfreq
Signature: private instance (Integer) _get_num_lowfreq ()
Description: This method gets the total number of lowfreq tokens (spam_count < 8 and ham_count < 8) in the token database for a user
_token_select_string
Signature: private instance (String) _token_select_string
Description: This method returns the string to be used in SELECT statements to represent the token column.
The default is to use the SUBSTR function to pad the token out to 5 characters.
and that's the whole vibe π this page was brought to you by perl v5.40.1, dated 2026-07-23, for Mail::...re::SQL(3pm). periodt β¨
π¦ where this page comes from
- ubuntu stonking: spamassassin 4.0.2+svn1935691-1build1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms