The Object Model

The Sophos Anti-Spam API is comprised of four types of objects. Each object type is prefixed with 'PMX'. These object types are:

  • PMX_ENGINE: The anti-spam engine itself. Used to scan email messages for spam.
  • PMX_MESSAGE: The complete email message. This includes all headers (for example: Subject, To, From), body text, and attachments.
  • PMX_HASH: A hash table of key/value pairs that can be loaded from, or saved to, a file on disk. Keys and values are of type string. This interface object is required when specifying trusted relays. See the eg/sample.c file for details of its implementation.
  • PMX_WEIGHTS: This object is provided for backwards compatibility, do not use it. A hash table of key/value pairs. Keys are of type string and values are floating point numbers. This interface object is not required for basic SDK usage.

These objects are implemented in the Perl programming language and are exposed via a C wrapper layer. The Perl interpreter is part of the anti-spam engine distribution and is located in the lib directory.

The C API uses a struct with a virtual function table (vtbl) for each of the object's methods. For example, a method must be accessed though the vtbl as follows:


The PMX_ENGINE is passed individual PMX_MESSAGE objects and computes a number indicating the email message's spam probability. This is done by aggregating values for spam features found in the compiled data.

The engine passes information back to the program that called it using several client-defined callback functions. These callbacks are passed to the engine as function pointers. For example, the engine's scan_message method returns information on found spam features and the aggregated spam probability via callback. For the required structure of a specific callback function, see "Callbacks" in the Anti-Spam Engine Reference section.

A PMX_MESSAGE object that has been created by one instance of PMX_ENGINE can also be used by other PMX_ENGINE instances.