Mail::...::MySQL(3pm)

πŸ’– Mail::...::MySQL(3pm) πŸ’–

okay bestie, you found the MySQL brain for SpamAssassin's bayes storage, and it's in the User Contributed Perl Documentation collection. pull up a chair, we're getting into it πŸ’…


✨ NAME ✨

Mail::SpamAssassin::BayesStore::MySQL β€” the MySQL-Specific Bayesian Storage Module Implementation. that's the whole thing. she does one job and she eats πŸ“


🌸 DESCRIPTION 🌸

okay so this module is the MySQL-flavored bayesian storage module. it's the girl who speaks MySQL and only MySQL.

⚠️ REAL TALK: she needs you to be running at least version 4.1 of MySQL. if you're on a version of MySQL < 4.1, then several aspects of this module will fail and possibly corrupt your bayes database data. not a vibe. do not do this. 😭

plus β€” and this is the slay part β€” this module will support rollback on error if you're using the InnoDB database table type in MySQL. for more info, please review the instructions in sql/README.bayes. (yes, actually go read it, i'm not kidding πŸ’œ)

this module is also compatible with MariaDB, and DBD::MariaDB can be used instead of the DBD::mysql driver. versatile queen πŸ‘‘


🌈 METHODS 🌈


πŸŽ€ token_expiration

public instance (Integer, Integer,
                 Integer, Integer) token_expiration(\% $opts,
                                                    Integer $newdelta,
                                                    @ @vars)

what she does: this method performs the database specific expiration of tokens, based on the $newdelta and @vars you hand her. bye bye old tokens πŸ‘‹


πŸŽ€ seen_put

public (Boolean) seen_put (string $msgid, char $flag)

what she does: this method records $msgid as the type given by $flag. and $flag is one of exactly two values, no in-between: 's' for spam and 'h' for ham. pick a lane bestie 🚦


πŸŽ€ seen_delete

public instance (Boolean) seen_delete (string $msgid)

what she does: this method removes $msgid from the database. gone, deleted, not coming back πŸ’€


πŸŽ€ set_last_expire

public instance (Boolean) set_last_expire (Integer $time)

what she does: this method sets the last expire time. that's it, that's the tweet ✨


πŸŽ€ set_running_expire_tok

public instance (String $time) set_running_expire_tok ()

what she does: this method sets the time that an expire starts running. stopwatch started, no pressure ⏱️


πŸŽ€ remove_running_expire_tok

public instance (Boolean) remove_running_expire_tok ()

what she does: this method removes the row in the database that indicates that an expire is currently running. (the original says "that and expire is currently running" but we all know what she meant πŸ’…)


πŸŽ€ tok_get

public instance (Integer, Integer, Integer) tok_get (String $token)

what she does: this method retrieves a specified token ($token) from the database, and returns its spam_count, ham_count and last access time. the full trio, no crumbs left behind πŸ”₯


πŸŽ€ tok_get_all

public instance (\@) tok_get (@ $tokens)

what she does: this method retrieves the specified tokens ($tokens) from storage, and returns an array ref of arrays β€” spam count, ham count and last access time. bulk energy, she's efficient πŸ¦‹


πŸŽ€ nspam_nham_change

public instance (Boolean) nspam_nham_change (Integer $num_spam,
                                             Integer $num_ham)

what she does: this method updates the number of spam and the number of ham in the database. keeping score, lowkey obsessed πŸ“Š


πŸŽ€ tok_touch

public instance (Boolean) tok_touch (String $token,
                                     String $atime)

what she does: this method updates the given token's ($token) atime.

the assumption is that the token already exists in the database. don't come at her with tokens that aren't there πŸ™ˆ


πŸŽ€ tok_touch_all

public instance (Boolean) tok_touch (\@ $tokens
                                     String $atime)

what she does: this method does a mass update of the given list of tokens $tokens, if the existing token atime is < $atime. conditional queen πŸ‘‘

the assumption is that the tokens already exist in the database.

also she wants you to know: 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). iykyk πŸ’œ


πŸŽ€ cleanup

public instance (Boolean) cleanup ()

what she does: this method performs any cleanup necessary before moving onto the next operation. tidy girl, clear skin, clear mind 🌸


πŸŽ€ clear_database

public instance (Boolean) clear_database ()

what she does: this method deletes all records for a particular user. nuking it, respectfully πŸ’€

⚠️ callers should be aware that any errors returned by this method could cause the database to be inconsistent for the given user. fr fr, proceed with care.

πŸ”’ Private Methods πŸ”’

these are the backstage girls, the ones doing the actual work while nobody's watching. don't call them directly unless you know what you're doing 🫢


πŸ’œ _connect_db

private instance (Boolean) _connect_db ()

what she does: this method connects to the SQL database. hi bestie, it's me πŸ‘‹


πŸ’œ _initialize_db

private instance (Boolean) _initialize_db ()

what she does: this method will check to see if a user has had their bayes variables initialized. if not, then it will perform this initialization. she checks, then she does. thorough πŸŽ€


πŸ’œ _put_token

private instance (Boolean) _put_token (string $token,
                                       integer $spam_count,
                                       integer $ham_count,
                                       string $atime)

what she does: this method performs the work of either inserting or updating a token in the database. insert-vs-update is giving whatever-the-data-wants energy ✨


πŸ’œ _put_tokens

private instance (Boolean) _put_tokens (\% $tokens,
                                        integer $spam_count,
                                        integer $ham_count,
                                        string $atime)

what she does: this method performs the work of either inserting or updating tokens (plural, we're in bulk mode now) in the database. same job as her sister, bigger guest list πŸ’…


πŸ’œ _token_select_string

private instance (String) _token_select_string

what she does: this method returns the string to be used in SELECT statements to represent the token column.

the default is to use the RPAD function to pad the token out to 5 characters. no cap, exactly five 🌈


<div align="center">🌸 πŸ¦‹ ✨ πŸŽ€ 🌈 ⭐ πŸ’– πŸ‘‘ πŸ“ 🧚 πŸ’œ 🌸</div>

okay that's the whole page bestie, go forth and store your bayes data responsibly πŸ’– this came out of perl v5.40.1, dated 2026-07-23, and it lives under the name Mail::...::MySQL(3pm) β€” mwah, periodt πŸ’…βœ¨

πŸ“¦ where this page comes from