package myplugin; sub init { my $dbh=shift; my @args=@_; # user-supplied arguments # optionally do initialization stuff using $dbh and @args bless {} # create the perl object and returns a reference to it } sub finish { # do optional cleaning 1; } sub process { my ($self, $context) = @_; # $self=class pointer # $context=pointer to a hash set up by the caller and that contains those keys: # stage: string whose value is "preprocess", "mimeprocess", "postprocess", "outgoing" or "maintenance" # dbh: the DBI connexion object pointing to the mail database # filename: full path of the mailfile (undef if $context->{stage} is "outgoing" or "maintenance") # mail_id: an integer containing the unique id of the mail (undef if the stage is "preprocess" or "maintenance") # mimeobj: the MIME object containing the mail (undef if the stage is "preprocess" or "maintenance") # The context is also used to communicate results to the caller and to the other plugins # along the chain. The keys that are going to be interpreted are: # tags= perl array of tag names that should be assigned to the message. # action: undef if no particular action (insert the incoming message as new) # "discard" to discard an incoming message, "trash" to trash it # Process the mail... 1; } 1; # the package should evaluate to 1The plugin's name must not contain any non-ascii nor punctuation or space characters. Digits are allowed except for the first character of the name.
plugins_directory = /path/to/plugins
That should appear in the [common]
section of the configuration
incoming_preprocess_plugins = plugin1(arg1,arg2,...) \
plugin2(arg1,arg2,arg3...) \
plugin3 \
...
Must be in a [mailbox] section (the plugin will be called only for
mails to that mailbox)
incoming_postprocess_plugins: same syntax than incoming_preprocess_plugins
incoming_mimeprocess_plugins: same syntax than incoming_preprocess_plugins
outgoing_plugins: same syntax than incoming_preprocess_plugins
maintenance_plugins: the declaration begins with a time frequency specification, which is either:
They are not tied to a mailbox, and thus should appear in the [common] section.
Invocation of maintenance plugins are serialized: two plugins never run at the same time. Also, mail import and export is stopped when a plugin runs.
[common] plugins_directory = /usr/local/manitou/plugins maintenance_plugins = 5h vacuum \ 23:30 reporting [mailbox@domain.tld] # plugins for that mailbox incoming_preprocess_plugins = spamc("tag for spam") incoming_postprocess_plugins = guesslang("en","fr") \ anotherplugin(arg1,arg2,...) outgoing_plugins = gpgsign [mailbox2@domain.tld] incoming_preprocess_plugins = spamc("another tag for spam")
Note that a declaration containing multiple plugins must be splitted across multiple lines, each line except the last one being ended by a backslash .
When manitou-mdx is launched, it searches the configuration file for all
plugins and includes each corresponding perl module file once, using perl's
require command.
It means that in the example configuration shown, it would load these files
from /usr/local/manitou/plugins:
guesslang.pm, anotherplugin.pm, spamc.pm, gpgsign.pm (note that spamc will be instantiated twice).
For each reference to a plugin, a new plugin perl class is instantiated,
and its init()
function called with the arguments from the config file along
with a database handle.
For the example configuration, the following instantiations would occur:
$pl1 = guesslang::init($dbh, "en","fr"); $pl2 = anotherplugin::init($dbh, arg1,arg2,...); $pl3 = spamc::init($dbh, "tag for spam"); $pl4 = gpgsign::init($dbh); $pl5 = spamc::init($dbh, "another tag for spam");
In the example above, since spamc is used by two different mailboxes,
two separate spamc objects are instantiated and
spamc::init
is called on each of them.
Variables used inside the spamc module
may or may not be shared between different instances of a module: it is
the responsibility of the plugin's writer to make the right choice between
private variables inside the object ($self->var
) or variables shared
at the package level (my $var
).
The user-supplied arguments for the init
function are passed verbatim from the
configuration file, and thus are to be considered as perl text.
(technically, the call to the plugin's init
function is
embedded inside a perl eval
call). Thus those user supplied
arguments should be expressed as they would be inside a perl program,
and every special character should be quoted according to perl syntax
rules. Examples:
# @ sign quoted as per perl strings requirements incoming_preprocess_plugins=spamc("tag\@cf") # Simple quotes can be also used to avoid perl variables interpolation # inside strings incoming_preprocess_plugins=spamc('tag@cf$') # On the other hand, we may want to use perl's interpreter to deference # variables: here we're passing the value of the MAIL_ARCH_DIR environment # variable. incoming_postprocess_plugins=archivemsg($ENV{MAIL_ARCH_DIR})
Each time a new message file appears in the mailfiles_directory of a mailbox, manitou-mdx carries out these actions:
process
functions are called with the outgoing mail
built as a perl MIME object in memory, and the unique mail identifier in the
database (mail_id).
When importing a mailbox with manitou-mdx (using the --mboxfile option), incoming_mimeprocess_plugins are called if: