functions used in: toaster-watcher.pl
toaster_setup.pl
qqtool.pl
To expose much of what can be done with these, run toaster_setup.pl -s help and you'll get a list of the available targets.
The functions in Mail::Toaster.pm are used by toaster-watcher.pl (which is run every 5 minutes via cron), as well as in toaster_setup.pl and other functions, particularly those in Qmail.pm and mailadmin.
use Mail::Toaster;
my $toaster = Mail::Toaster->new;
my $conf = $utility->parse_config( file=>"toaster-watcher.conf");
# verify that processes are all running and complain if not
$toaster->toaster_check(conf=>$conf);
# get a list of all maildirs on the system
my @all_maildirs = $toaster->get_maildir_paths( conf=>$conf);
# clean up old messages over X days old
$toaster->clean_mailboxes( conf=>$conf);
# clean up messages in Trash folders that exceed X days
foreach my $maildir ( @all_maildirs ) {
$toaster->maildir_clean_trash(
conf => $conf,
path => $maildir,
);
};
These functions can all be called indivually, see the working
examples in the aforementioned scripts or the t/Toaster.t file.
Mail::Toaster, Everything you need to build a industrial strength mail system.
A collection of perl scripts and modules that are quite useful for building and maintaining a mail system. It was first authored for FreeBSD and has since been extended to Mac OS X, and Linux. It has become quite useful on other platforms and may grow to support other MTA's (think postfix) in the future.
A separate section listing the public components of the module's interface.
These normally consist of either subroutines that may be exported, or methods
that may be called on objects belonging to the classes that the module provides.
Name the section accordingly.
In an object-oriented module, this section should begin with a sentence of the
form "An object of this class represents...", to give the reader a high-level
context to help them understand the methods that are subsequently described.
############################################
# Usage : $toaster->toaster_check(conf=>$conf);
# Purpose : Runs a series of tests to inform admins of server problems
# Returns : prints out a series of test failures
# Parameters : conf - a hashref of values from toaster-watcher.conf
# Throws : no exceptions
# See Also : toaster-watcher.pl
# Comments :
Performs the following tests:
• check for processes that should be running.
• make sure watcher.log is less than 1MB
• make sure ~alias/.qmail-* exist and are not empty
• verify multilog log directories are working
When this is run by toaster-watcher.pl via cron, the mail server admin will get notified via email any time one of the tests fails. Otherwise, there is no output generated.
############################################
# Usage : $toaster->learn_mailboxes( conf=>$conf );
# Purpose : train SpamAssassin bayesian filters with your ham & spam
# Returns : 0 - failure, 1 - success
# Parameters : conf
# See Also : n/a
# Comments :
Powers an easy to use mechanism for training SpamAssassin on what you think is ham versus spam. It does this by trawling through a mail system, finding mail messages that have arrived since the last time it ran. It passes these messages through sa-learn with the appropriate flags (sa-learn --ham|--spam) to train its bayesian filters.
############# clean_mailboxes ##############
# Usage : $toaster->clean_mailboxes( conf=>$conf );
# Purpose : cleaning out old mail messages from user mailboxes
# Returns : 0 - failure, 1 - success
# Parameters : conf
# See Also : n/a
# Comments :
This sub trawls through the mail system pruning all messages that exceed the threshholds defined in toaster-watcher.conf.
Peter Brezny suggests adding another option which is good. Set a window during which the cleaning script can run so that it is not running during the highest load times.
######### email_send_attach ###############
# Usage : internal only
# Purpose : send an email with a .com attachment
# Parameters : an email address
# See Also : email_send
Sends a sample test email to the provided address with a .com file extension. If attachment scanning is enabled, this should trigger the content scanner (simscan/qmailscanner/etc) to reject the message.
############################################
# Usage : $toaster->get_maildir_paths( conf => $conf )
# Purpose : build a list of email dirs to perform actions upon
# Returns : an array listing every maildir on a Mail::Toaster
# Parameters : conf
# Throws : exception on failure, or 0 if fatal=>0
This sub creates a list of all the domains on a Mail::Toaster, and then creates a list of every email box (maildir) on every domain, thus generating a list of every mailbox on the system.
############################################
# Usage : $toaster->maildir_learn_spam(
# conf => $conf,
# path => '/home/domains/example.com/user',
# );
# Purpose : find spam messages newer than the last spam learning run
# Returns : 0 - failure, 1 - success
# Results : matching spam messages are appended to a tmpfile to be
# fed to sa-learn via the caller.
# Parameters : conf
# : path - path to a maildir
# Throws : no exceptions
# See Also : learn_mailboxes
# Comments : this is for a single mailbox
############ maildir_clean_new #############
# Usage : $toaster->maildir_clean_new(
# conf => $conf,
# path => '/home/domains/example.com/user',
# );
# Purpose : expire unread messages older than X days
# Returns : 0 - failure, 1 - success
# Parameters : conf
# path - path to a maildir
# Throws : no exceptions
This should be set to a large value, such as 180 or 365. Odds are, if a user hasn't read their messages in that amount of time, they never will so we should clean them out.
############################################
# Usage : $toaster->maildir_learn_ham(
# conf => $conf,
# path => '/home/domains/example.com/user',
# );
# Purpose : find ham messages newer than the last learning run
# Returns : 0 - failure, 1 - success
# Results : matching ham messages are appended to a tmpfile to be
# fed to sa-learn via the caller.
# Parameters : conf
# path - path to a maildir
# Throws : no exceptions
# See Also : learn_mailboxes
# Comments : this is for a single mailbox
Sets up the supervised mail services for Mail::Toaster
$toaster->service_symlinks(conf=>$conf, );
This populates the supervised service directory (default: /var/service) with symlinks to the supervise control directories (typically /var/qmail/supervise/). Creates and sets permissions on the following directories and files:
Checks a supervised directory to see if it is set up properly for supervise to start it. It performs a bunch of tests including:
• directory exists
• dir/run file exists and is executable
• dir/down file is not present
• dir/log exists
• dir/log/run exists and is executable
• dir/log/down does not exist
arguments required:
conf
prot - a protocol to check (smtp, pop3, send, submit)
Since the functions in the module are primarily called by toaster-watcher.pl, they are designed to do their work with a minimum amount of feedback, complaining only when a problem is encountered. Whether or not they produce status messages and verbose errors is governed by the "debug" argument which is passed to each sub/function.
Status messages and verbose logging is enabled by default. toaster-watcher.pl and most of the automated tests (see t/toaster-watcher.t and t/Toaster.t) explicitely turns this off by setting debug=>0.
The primary means of configuration for Mail::Toaster is via toaster-watcher.conf. It is typically installed in /usr/local/etc, but may also be found in /opt/local/etc, or simply /etc. Documentation for the man settings in toaster-watcher.conf can be found in the man page (perldoc toaster-watcher.conf).
Add support for Darwin (MacOS X) - done
Add support for Linux - done
Update openssl & courier ssl .cnf files - done
Install an optional stub DNS resolver (dnscache)
Copyright (c) 2004-2008, The Network People, Inc. <matt@tnpi.net>. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of the The Network People, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.