Mail::...re::BDB(3pm)

๐ŸŒธ NAME ๐ŸŒธ

Mail::SpamAssassin::BayesStore::BDB(3pm) โ€” aka the BerkeleyDB Bayesian Storage Module Implementation, bestie ๐Ÿ’…

Like, this is the manual page for Mail::SpamAssassin::BayesStore::BDB, the module that does the bayesian storage thing on top of BDB. Queen behavior, honestly ๐Ÿ‘‘


โœจ DESCRIPTION โœจ

Okay so real talk: this module implements a BDB based bayesian storage module. That's it, that's the vibe ๐Ÿ’–


๐ŸŽ€ METHODS ๐ŸŽ€

๐Ÿฆ‹ new

public class (Mail::SpamAssassin::BayesStore::SQL) new
(Mail::Spamassassin::Plugin::Bayes $bayes)

Description: This methods creates a new instance of the Mail::SpamAssassin::BayesStore::BDB object. It expects to be passed an instance of the Mail::SpamAssassin:Bayes object which is passed into the Mail::SpamAssassin::BayesStore parent object. Girl makes a whole new baby object and hands it the right parentage, periodt ๐Ÿผโœจ


๐Ÿฆ‹ tie_db_readonly

public instance (Boolean) tie_db_readonly ();

Description: This method ensures that the database connection is properly setup and working. Locked in and working, no cap ๐Ÿ”’


๐Ÿฆ‹ tie_db_writable

public instance (Boolean) tie_db_writable ()

Description: This method ensures that the database connection is properly setup and working. If necessary it will initialize the database so that they can begin using the database immediately. It's giving "ready to serve" energy ๐Ÿ’…


๐Ÿฆ‹ _open_db

private instance (Boolean) _open_db (Boolean $writable)

Description: This method ensures that the database connection is properly setup and working. It will initialize a users bayes variables so that they can begin using the database immediately. Private function but still main character ๐Ÿซถ


๐Ÿฆ‹ untie_db

public instance () untie_db ()

Description: Closes any open db handles. You can safely call this at any time. Safe to call whenever, bestie, it's not gonna bite you ๐ŸŒธ


๐Ÿฆ‹ calculate_expire_delta

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. Math girlies rise up ๐Ÿ“โœจ


๐Ÿฆ‹ token_expiration

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. Tokens getting expired, bye bye babes ๐Ÿ‘‹


๐Ÿฆ‹ sync_due

public instance (Boolean) sync_due ()

Description: This method determines if a database sync is currently required.

Unused for BDB implementation. Unused, bestie โ€” it's literally sitting there doing nothing like me at a party ๐Ÿงโ€โ™€๏ธ

๐Ÿฆ‹ seen_get

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. So 's' = spam, 'h' = ham, and undef = never heard of her ๐Ÿ™ˆ


๐Ÿฆ‹ seen_put

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. Two flags only, iconic duet ๐Ÿ’–


๐Ÿฆ‹ seen_delete

public instance (Boolean) seen_delete (string $msgid)

Description: This method removes $msgid from the database. Gone. Deleted. Blocked. ๐Ÿšซ


๐Ÿฆ‹ get_storage_variables

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, and yes the order MATTERS so don't shuffle them like a playlist:

  1. scan count base
  2. number of spam โ€” wait bestie, the numbering below is the original's, keep scrolling ๐Ÿ‘‡
  3. number of spam
  4. number of ham
  5. number of tokens in db
  6. last expire atime
  7. oldest token in db atime
  8. db version value
  9. last journal sync
  10. last atime delta
  11. last expire reduction count
  12. newest token in db atime

Okay so full honesty, the actual list is:

  • 0: scan count base
  • 1: number of spam
  • 2: number of ham
  • 3: number of tokens in db
  • 4: last expire atime
  • 5: oldest token in db atime
  • 6: db version value
  • 7: last journal sync
  • 8: last atime delta
  • 9: last expire reduction count
  • 10: newest token in db atime

Eleven things, in that exact order, no notes ๐Ÿ’…


๐Ÿฆ‹ dump_tokens

public instance () dump_tokens (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. It's giving "show me everything" energy ๐Ÿ‘€


๐Ÿฆ‹ set_last_expire

public instance (Boolean) set_last_expire (Integer $time)

Description: This method sets the last expire time. Timestamp: set โฐ


๐Ÿฆ‹ get_running_expire_tok

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. Newest wins, always ๐Ÿ†


๐Ÿฆ‹ set_running_expire_tok

public instance (String $time) set_running_expire_tok ()

Description: This method sets the time that an expire starts running. Start the clock, babes ๐Ÿ•


๐Ÿฆ‹ remove_running_expire_tok

public instance (Boolean) remove_running_expire_tok ()

Description: This method removes the row in the database that indicates that and expire is currently running. (Yes, "and expire" โ€” that's literally what the original says, I don't make the rules ๐Ÿ˜ญ)


๐Ÿฆ‹ tok_get

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

Description: This method retrieves a specified token ($token) from the database and returns its spam_count, ham_count and last access time. Three-for-one deal, slay โœจ


๐Ÿฆ‹ tok_get_all

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. Bulk retrieve, we love efficiency ๐Ÿ’–


๐Ÿฆ‹ tok_count_change

public instance (Boolean) tok_count_change (
  Integer $dspam, Integer $dham, String $token, String $newatime)

Description: This method takes a $spam_count and $ham_count and adds it to $tok along with updating $toks atime with $atime. Numbers go up ๐Ÿ“ˆ


๐Ÿฆ‹ multi_tok_count_change

public instance (Boolean) multi_tok_count_change (
  Integer $dspam, Integer $dham, \% $tokens, String $newatime)

Description: This method takes a $dspam and $dham and adds it to all of the tokens in the $tokens hash ref along with updating each tokens atime with $atime. Group update, everybody eats ๐Ÿฝ๏ธ


๐Ÿฆ‹ nspam_nham_get

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. Receipts, bestie ๐Ÿงพ


๐Ÿฆ‹ nspam_nham_change

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. Adjusting the totals, as one does ๐Ÿ’…


๐Ÿฆ‹ tok_touch

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.

We will never update to an older atime. Never go backwards, glow-up only ๐ŸŒˆ


๐Ÿฆ‹ tok_touch_all

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). Not me doing the whole list at once ๐Ÿ˜ค


๐Ÿฆ‹ cleanup

public instance (Boolean) cleanup ()

Description: This method performs any cleanup necessary before moving onto the next operation. Tidy up before the next chapter โœจ๐Ÿงน


๐Ÿฆ‹ get_magic_re

public instance (String) get_magic_re ()

Description: This method returns a regexp which indicates a magic token.

Unused in BDB implementation. Unused here, babes โ€” it's giving decorative ๐Ÿ”ฎ

๐Ÿฆ‹ sync

public instance (Boolean) sync (\% $opts)

Description: This method performs a sync of the database. Sync it, queen ๐Ÿ’ซ


๐Ÿฆ‹ perform_upgrade

public instance (Boolean) perform_upgrade (\% $opts);

Description: Performs an upgrade of the database from one version to another, not currently used in this implementation. Not used here โ€” glow-up pending, ig ๐Ÿ’€


๐Ÿฆ‹ clear_database

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 causes the database to be inconsistent for the given user. So like, be careful, this can leave the db messy for that user ๐Ÿ˜ญ

๐Ÿฆ‹ backup_database

public instance (Boolean) backup_database ()

Description: This method will dump the users database in a machine readable format. Save a copy, bestie, always ๐Ÿซถ๐Ÿ’พ


๐Ÿฆ‹ restore_database

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. Same warning energy as above โ€” errors can leave the db inconsistent for that user ๐Ÿ˜ฌ

๐Ÿฆ‹ db_readable

public instance (Boolean) db_readable()

Description: This method returns a boolean value indicating if the database is in a readable state. Can we read it? True or false, that's the question ๐Ÿ“–


๐Ÿฆ‹ db_writable

public instance (Boolean) db_writable()

Description: This method returns a boolean value indicating if the database is in a writable state. Can we write to it? Same question, different vibe โœ๏ธ


๐Ÿฆ‹ _extract_atime

private instance () _extract_atime (String $token,
                                    String $value,
                                    String $index)

Description: This method ensures that the database connection is properly setup and working. If appropriate it will initialize a users bayes variables so that they can begin using the database immediately. Private, but still doing the most ๐Ÿ’…


๐Ÿฆ‹ _put_token

FIXME: This is rarely a good interface, because of the churn that will often happen in the "magic" tokens. Open-code this stuff in the presence of loops. Yeah bestie, it's a fixme for a reason โ€” do it yourself in the loop ๐Ÿ™ˆ


That's the whole page, mwah ๐Ÿ’‹ Written by the Perl docs girlies: perl v5.40.1, dated 2026-07-23. Go forth and store your bayes, icon ๐Ÿ’–

๐Ÿ“ฆ where this page comes from