Train spamassassin with spam/ham from user's imap mailboxes
sa-learn-cyrus [ options ] user-name(s)
user-name(s) One ore more user/mailbox name(s). options: --help Prints a brief help message and exits. -h --man Prints the manual page and exits. --verbose level Be verbose if level > 0 -v level --config file Use a configuration file other than the default -c file one. --sa-debug Run sa-learn in debug mode. -d --simulate Run in simulation mode (show commands only). -s --imap-domains domains Search mailboxes in list of domains. -D domains
sa-learn-cyrus feeds spam and non-spam (ham) messages to Spamassassin's database. Its main purpose is to train \s-1SA\s0's bayes database with spam/ham messages sorted by the mailbox owners into special subfolders.
It is intended to be used on smal mail systems (e.g. home office) with a single server-wide \s-1SA\s0 configuration.
Launching sa-learn-cyrus at regular intervalls (cron job) may improve \s-1SA\s0's hit rate considerably, provided that the users are well instructed what to move to their ham/spam folders and what not.
sa-learn-cyrus scans local mail spools as used by Cyrus IMAPd for special subfolders. These subfolders are supposed to contain mails which have been classfied as spam or ham by the mailbox owners.
Example: The users move spam mails which have not been tagged as spam by SpamAssassin (false positives) to a subfolder \s-1INBOX\s0.Learn.Spam. Other mails, which may be classified by \s-1SA\s0 as spam in the future because of certain characteristics are copied to a subfolder \s-1INBOX\s0.Learn.Ham.
sa-learn-cyrus feeds the content of these spam/ham folders to \s-1SA\s0's Bayes database using the sa-learn tool which is shipped with the Spamassassin package.
Afterwards these mails are deleted (optionally) by means of ipurge which is a helper tool coming along with the Cyrus IMAPd package.
sa-learn-cyrus optionally takes a list of mailbox/user names as agruments:
sa-learn-cyrus fred wilma fritz hjb
If not supplied all mailboxes found will be handled.
All options supplied on the comand line will override corresponding parameters given in the configuration file.
Please note that the basic parameters of sa-learn-cyrus have to be defined in a configuration file. sa-learn-cyrus cannot be controlled solely by means of command.
Use configuration file other then the default one. Always adopt the configuartion file to your needs before using sa-learn-cyrus on a live system. Otherwise you may loose data or corrupt your \s-1SA\s0 data base!
Specify level of verbosity. (Default = 0)
Run sa-learn in debug mode. This may be useful to examine problems with sa-learn.
Run sa-learn-cyrus in simulation mode. This is useful for first tests after initial configuration or if problem are encountered. In simulation mode sa-learn-cyrus doesn't execute any system commands nor does it touch any data. It just displays what it would do.
If your Cyrus installation uses the \*(L"domain support\*(R" you may use this option to tell what domains you want to be searched. --domains example.com,another.org is equivalent to [imap] ... domains = example.com another.org ... in the configuration file.
By default sa-learn-cyrus expects its configuration file as /etc/sapmasassin/sa-learn-cyrus.conf.
One has to change this setting in the code, if another default file is wanted. Another than the default file can always be choosen with the \*(C`--config option\*(C'.
A sample configuration file is shipped with sa-learn-cyrus.
The configuration file has a format as knwon from rsync or samba is very similar to the format of Windows ini files. The file consist of sequence sections. The begin of each section is designated with a section name, a word in square brackets, e.g. \*(C`[global]\*(C'. The section entries consist of parameters, which are key/value pairs each on a single line. Key an value are separated by an equal sign like
key = value
The value is a single word or a list of words each of them representing a number or a string. Words may be surrounded ba any number of spaces for better readability. Empty lines and lines with a leading hash character \*(C`#\*(C' are ingored.
The [global] section contains all global controll parameters.
sa-learn-cyrus creates some temporary files during each run. This is the directory where thes files are created.
To avoid race conditions, sa-learn-cyrus uses a simple file locking mechanism. Each new sa-learn-cyrus process looks for this file before it realy does anything. If this file exists, the process exits with a warning, assuming that another sa-learn-cyrus process is running.
The level of verbosity. Values range from 0 (low) to 3 (high). A reasonable level to start with is 1.
sa-learn-cyrus should be run in simulation mode (\*(C`simulate = yes\*(C') after the first customization of the configuration to avoid loss of data or corruption of \s-1SA\s0's database in case of wrongly configured parameters.
Prepend the ouput (log) with a tag (date, time, pid). Set to \*(C`no\*(C' to avoid additional tagging when piped to syslog. Default is \*(C`yes\*(C'.
Section [mailbox] contains all parameters to select the mailboxes, to specify the special subfolders, and to define the actions to apply.
Only spam/ham mails of these mailboxes are fed to Spamassassin's database. If this List ist empty, all mailboxes will be used. \*(C`include_list\*(C' may be used instead of the list on the command line. Example: include_list = fred wilma fritz hjb
If include_list is empty, a regular expression given here is applied to all mailbox names to select mailboxes. This parameter is ignored if include_list is not empty. Example: Include all mailboxes beginning with 'knf-'. include_regexp = ^knf-
A list of mailboxes wich will be excluded. If include_list is not empty, this parameter is ignored.
Mailbox names which match with this regular expresson are excluded from processing. Example: Ignore all mailboxes ending with '.beie' exclude_regexp = \.beie$
The name of the special subfolder in each mailbox which contains spam. The name should be a complete folder path relative to the root folder \s-1INBOX\s0. The Cyrus nomenclature is applied (same as with cyradm). Example: spam_folder = Learn.Spam This is a subfolder in a folder tree like this: INBOX +--Drafts +--Templates +--Sent +--Learn | +--Ham | +--Spam <-- spam subfolder |
The name of the special subfolder in each mailbox which contains ham. (Same naming scheme as with \*(C`spam_folder\*(C', see above.)
Are the spam messages in the \*(C`spam_folder\*(C' to be removed after feeding them to the \s-1SA\s0 database or not?
Are the ham messages in the \*(C`ham_folder\*(C' to be removed after feeding them to the \s-1SA\s0 database or not?
Spamassassin (\s-1SA\s0) configuration items.
Path to system-wide \s-1SA\s0 preferences. Example: site_config_path = /etc/spamassassin
Bayes storage mechanism (berkely|sql) berkely: Berkely \s-1DB\s0 (default) sql: \s-1SQL\s0 Database
Path of the system-wide \s-1SA\s0 configuartin file. Example: prefs_file = /etc/spamassassin/local.cf
Path to the sa-learn utility. Example: learn_cmd = /usr/bin/sa-learn
Should permissions of \s-1DB\s0 files be fixed? Ignored unless \*(C`bayes_storage = berkely\*(C'
The user id \s-1SA\s0 runs with. Required if \*(C`fix_db_permissions = yes\*(C'. Example: user = mail
The group id \s-1SA\s0 runs with. Required if \*(C`fix_db_permissions = yes\*(C'. Example: group = mail
Skip synchronization after every change of database, but sync once after all messages have been learned. May speed up learning from many folders. Default is \*(C`yes\*(C'.
Use this if you use the \*(C`--virtual-config-dir\*(C' option of \*(C`spamd\*(C' (it needs to match exactly). See the \*(C`spamd\*(C' man page for more information.
Run sa-learn in debug mode or not. \*(C`debug = yes\*(C' may be useful to examine problems.
The section [imap] contains the necessary configuration parameter to locate an manage the (Cyrus) IMAPd spool files.
The root of the base directory of the \s-1IMAP\s0 spool (below that the mailboxes are located).
If base_dir is divided in subdirectories named with the initial letters of mailbox names set \*(C`initial_letter = yes\*(C' (default), otherwise choose no. Examples for joe's mailbox: <base_dir>/j/user/joe/ : initial_letter = yes <base_dir>/user/joe/ : initial_letter = no
If your Cyrus spool uses domain hierarchy supply a list of domains. If domain support is not used leave this entry empty. The \*(C`initial_letter\*(C' option (see above) is applied to domains, too. Example for mailboxes [email protected] and [email protected] : The mail files within the Cyrus spool are located at <base_dir>/domain/b/bar.org/f/fritz <base_dir>/domain/f/foo.com/j/joe List the domains as domains = foo.com bar.org
Choose \*(C`unixhierarchysep = yes\*(C' if Cyrus is configured to accept usernames like 'hans.mueller.somedomain.tld'. Otherwise set \*(C`unixhierarchysep = no\*(C'.
The path to the Cyrus ipurge utility for purging mail messages. Example: purge_cmd = /usr/sbin/ipurge
The user Cyrus-IMAPd runs as. Example: user = cyrus
/etc/spamassassin/sa-learn-cyrus.conf
\*(C`sa-learn(1)\*(C', spamassassin(1), Mail::SpamAssassin(3), Mail::SpamAssassin::Conf(3), imapd(8), spamd(8)
The current version of this script is available at http://www.pollux.franken.de/mail-server-tools/sa-learn-cyrus/ <http://www.pollux.franken.de/mail-server-tools/sa-learn-cyrus/>
sa-learn (part of the SpamAssassin package), ipurge (part of Cyrus IMAPd)
Hans-Juergen Beie <[email protected]>
Copyright 2004-2011 by Hans-Juergen Beie.
This program is free software; you can redistribute it and/or modify it under the terms of the Artistic License 2.0 (http://foundation.perl.org/legal/licenses/artistic-2_0-plain.html <http://foundation.perl.org/legal/licenses/artistic-2_0-plain.html>) or the \s-1GNU\s0 General Public License as published by the Free Software Foundation; either version 2 of the license (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>), or (at your option) any later version.
This program is distributed in the hope that it will be useful, but \s-1WITHOUT\s0 \s-1ANY\s0 \s-1WARRANTY\s0; without even the implied warranty of \s-1MERCHANTABILITY\s0 or \s-1FITNESS\s0 \s-1FOR\s0 A \s-1PARTICULAR\s0 \s-1PURPOSE\s0.
Thanks to Robert Carnecky and Jan Hauke Rahm for testing and suggestions for the implementation of the domain support. David Caldwell contributed the the virtual_config_dir feature. Some other contributers are listed in the \s-1CHANGELOG\s0. Many thanks to them for their help and suggestions.