---
name: "Mail::SpamAssassin::BayesStore"
section: "3pm"
platform: "linux"
package: "spamassassin"
version: "4.0.2-3"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/Mail::SpamAssassin::BayesStore"
---

# Mail::SpamAssassin::BayesStore(3pm)

Storage Module for default Bayes classifier

## NAME

Mail::SpamAssassin::BayesStore - Storage Module for default Bayes classifier

## DESCRIPTION

This is the public API for the Bayesian store methods.  Any implementation of the storage module for the default Bayes classifier must implement these methods.

## METHODS

- new

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

  Description: This method creates a new instance of the Mail::SpamAssassin::BayesStore object.  You must pass in an instance of the Mail::SpamAssassin::Plugin::Bayes object, which is stashed for use throughout the module.

- DB\_VERSION

  public instance (Integer) DB\_VERSION ()

  Description: This method returns the currently supported database version for the implementation.

- read\_db\_configs

  public instance () read\_db\_configs ()

  Description: This method reads any needed config variables from the configuration object and then calls the Mail::SpamAssassin::Plugin::Bayes read\_db\_configs method.

- prefork\_init

  public instance (Boolean) prefork\_init ()

  Description: This optional method is called in the parent process shortly before forking off child processes.

- spamd\_child\_init

  public instance (Boolean) spamd\_child\_init ()

  Description: This optional method is called in a child process shortly after being spawned.

- tie\_db\_readonly

  public instance (Boolean) tie\_db\_readonly ()

  Description: This method opens up the database in readonly mode.

- tie\_db\_writable

  public instance (Boolean) tie\_db\_writable ()

  Description: This method opens up the database in writable mode.

  Any callers of this methods should ensure that they call **untie\_db()** afterwards.

- untie\_db

  public instance () untie\_db ()

  Description: This method unties the database.

- 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.

- token\_expiration

  public instance (Integer, Integer,\
                    Integer, Integer) token\_expiration(\\% `$opts`,\
                                                       Integer `$newest_atime`,\
                                                       Integer `$newdelta`)

  Description: This method performs the database specific expiration of tokens based on the passed in `$newest_atime` and `$newdelta`.

- expire\_old\_tokens

  public instance (Boolean) expire\_old\_tokens (\\% hashref)

  Description: This method expires old tokens from the database.

- expire\_old\_tokens\_trapped

  public instance (Boolean) expire\_old\_tokens\_trapped (\\% `$opts`)

  Description: This methods does the actual token expiration.

  XXX More docs here about the methodology and what not

- sync\_due

  public instance (Boolean) sync\_due ()

  Description: This methods determines if a sync is due.

- expiry\_due

  public instance (Boolean) expiry\_due ()

  Description: This methods determines if an expire is due.

- seen\_get

  public instance (Char) 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

  public instance (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

  public instance (Boolean) seen\_delete (String `$msgid`)

  Description: This method removes `$msgid` from storage.

- get\_storage\_variables

  public instance (@) get\_storage\_variables ()

  Description: This method retrieves the various administrative variables used by the Bayes storage implementation.

  The values returned in the array are in the following order:

  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

- dump\_db\_toks

  public instance () dump\_db\_toks (String `$template`, String `$regex`, @ `@vars`)

  Description: This method loops over all tokens, computing the probability for the token and then printing it out according to the passed in template.

- set\_last\_expire

  public instance (Boolean) \_set\_last\_expire (Integer `$time`)

  Description: This method sets the last expire time.

- get\_running\_expire\_tok

  public instance (Time) get\_running\_expire\_tok ()

  Description: This method determines if an expire is currently running and returns the time the expire started.

- set\_running\_expire\_tok

  public instance (Time) set\_running\_expire\_tok ()

  Description: This method sets the running expire time to the current time.

- remove\_running\_expire\_tok

  public instance (Boolean) remove\_running\_expire\_tok ()

  Description: This method removes a currently set running expire time.

- tok\_get

  public instance (Integer, Integer, Time) tok\_get (String `$token`)

  Description: This method retrieves the specified token (`$token`) from storage and returns it's spam count, ham count and last access time.

- tok\_get\_all

  public instance (\\@) tok\_get\_all (@ `@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

  public instance (Boolean) tok\_count\_change (Integer `$spam_count`,\
                                               Integer `$ham_count`,\
                                               String `$token`,\
                                               Time `$atime`)

  Description: This method takes a `$spam_count` and `$ham_count` and adds it to `$token` along with updating `$token`s atime with `$atime`.

- multi\_tok\_count\_change

  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 tokens atime with `$atime`.

- nspam\_nham\_get

  public instance (Integer, Integer) nspam\_nham\_get ()

  Description: This method retrieves the total number of spam and the total number of ham currently under storage.

- 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.

- tok\_touch

  public instance (Boolean) tok\_touch (String `$token`,\
                                        Time `$atime`)

  Description: This method updates the given tokens (`$token`) access time.

- tok\_touch\_all

  public instance (Boolean) tok\_touch\_all (\\@ `$tokens`,\
                                            Time `$atime`)

  Description: This method does a mass update of the given list of tokens `$tokens`, if the existing token atime is \< `$atime`.

- cleanup

  public instance (Boolean) cleanup ()

  Description: This method performs any cleanup necessary before moving onto the next operation.

- get\_magic\_re

  public instance get\_magic\_re (String)

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

- sync

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

  Description: This method performs a sync of the database.

- perform\_upgrade

  public instance (Boolean) perform\_upgrade (\\% `$opts`)

  Description: This method is a utility method that performs any necessary upgrades between versions.  It should know how to handle previous versions and what needs to happen to upgrade them.

  A true return value indicates success.

- 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.

- backup\_database

  public instance (Boolean) backup\_database ()

  Description: This method will dump the users database in a machine readable format.

- 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.

- db\_readable

  public instance (Boolean) db\_readable ()

  Description: This method returns whether or not the Bayes DB is available in a readable state.

- db\_writable

  public instance (Boolean) db\_writable ()

  Description: This method returns whether or not the Bayes DB is available in a writable state.
