NAME

MATT:Qmail - Common Qmail functions


SYNOPSIS

MATT::Qmail is frequently used functions I've written for perl use with Qmail.


DESCRIPTION

This module has all sorts of goodies, the most useful of which are the Build????Run modules which build your qmail control files for you.

SetSuperviseDir

        my $dir = SetSuperviseDir($conf, "smtp", $debug);

This sub just sets the supervise directory used by the various qmail services (qmail-smtpd, qmail-send, qmail-pop3d, qmail-submit). It sets the values according to your preferences in toaster-watcher.conf. If any settings are missing from the config, it chooses reasonable defaults.

This is used primarily to allow you to set your mail system up in ways that are a different than mine, like a LWQ install.

InstallNetQmail

Builds net-qmail with patches (based on your settings in toaster-watcher.conf), installs the SSL certs, adjusts the permissions of several files that need it.

        use Mail::Toaster::Setup;
        InstallNetQmail($conf, $package);

$conf is a hash of values from toaster-watcher.conf used to determine how to configured your qmail.

$package is the name of the program. It defaults to ``qmail-1.03''

Patch info is here: http://www.tnpi.biz/internet/mail/toaster/patches/

InstallQmail

Builds qmail and installs qmail with patches (based on your settings in toaster-watcher.conf), installs the SSL certs, adjusts the permissions of several files that need it.

        use Mail::Toaster::Setup;
        InstallQmail($conf, $package);

$conf is a hash of values from toaster-watcher.conf used to determine how to configured your qmail.

$package is the name of the program. It defaults to ``qmail-1.03''

Patch info is here: http://www.tnpi.biz/internet/mail/toaster/patches/

GetListOfRWLs

        use MATT::Qmail
        my $list = GetListOfRWLs($conf, $debug);

Here we collect a list of the RWLs from the configuration file that get's passed to us. We return an arrayref with a list of the enabled ones.

TestEachRBL

        use MATT::Qmail
        my $list = TestEachRBL($arrayref, $debug);

We get a list of RBL's in an arrayref and we run some tests on them to determine if they are working correctly. We return a list of the correctly functioning RBLs.

GetListOfRBLs

        use MATT::Qmail
        my $list = GetListOfRBLs($arrayref, $debug);

We get passwd a configuration file (toaster-watcher.conf) and from it we extract all the RBL's the user has selected and return them as an array ref.

BuildSendRun

        use MATT::Qmail;
        if ( BuildSendRun($conf, $file, $debug) ) { print "success"};

BuildSendRun generates a supervise run file for qmail-send. $file is the location of the file it's going to generate. $conf is a list of configuration variables pulled from a config file (see ParseConfigfile). I typically use it like this:

        my $file = "/tmp/toaster-watcher-send-runfile";
        if ( BuildSendRun($conf, $file ) )
        {
                InstallQmailServiceRun($file, "$supervise/send/run");
        };

If it succeeds in building the file, it will install it. You can optionally restart qmail after installing a new run file.

BuildPOP3Run

        use MATT::Qmail;
        if ( BuildPOP3Run($conf, $file, $debug) ) { print "success"};

Generate a supervise run file for qmail-pop3d. $file is the location of the file it's going to generate. $conf is a list of configuration variables pulled from a config file (see ParseConfigfile). I typically use it like this:

        my $file = "/tmp/toaster-watcher-pop3-runfile";
        if ( BuildPOP3Run($conf, $file ) )
        {
                InstallQmailServiceRun($file, "$supervise/pop3/run");
        };

If it succeeds in building the file, it will install it. You can optionally restart the service after installing a new run file.

TestSmtpdConfigValues

SetServiceDir

This is necessary because things such as service directories are now in /var by default but older versions of my toaster installed them in /. This will detect and adjust for that.

BuildSmtpRun

        use MATT::Qmail;
        if ( BuildSmtpRun($conf, $file, $debug) ) { print "success" };

Generate a supervise run file for qmail-smtpd. $file is the location of the file it's going to generate. $conf is a list of configuration variables pulled from a config file (see ParseConfigfile). I typically use it like this:

        my $file = "/tmp/toaster-watcher-smtpd-runfile";
        if ( BuildSmtpRun($conf, $file ) )
        {
                InstallQmailServiceRun($file, "$supervise/smtp/run");
        };

If it succeeds in building the file, it will install it. You can optionally restart the service after installing a new run file.

BuildSubmitRun

        use MATT::Qmail;
        if ( BuildSubmitRun($conf, $file, $debug) ) { print "success"};

Generate a supervise run file for qmail-smtpd running on submit. $file is the location of the file it's going to generate. $conf is a list of configuration variables pulled from a config file (see ParseConfigfile). I typically use it like this:

        my $file = "/tmp/toaster-watcher-smtpd-runfile";
        if ( BuildSubmitRun($conf, $file ) )
        {
                InstallQmailServiceRun($file, "$supervise/submit/run");
        };

If it succeeds in building the file, it will install it. You can optionally restart the service after installing a new run file.

InstallQmailServiceRun

        use MATT::Qmail;
        my $file = "/tmp/toaster-watcher-smtpd-runfile";
        if ( BuildSmtpRun($conf, $file ) )
        {
                InstallQmailServiceRun($file, "$supervise/smtp/run");
        };

The code says it as well as I can.

RestartQmailSmtpd

        RestartQmailSmtpd($dir, $debug)

Use RestartQmailSmtpd to restart the qmail-smtpd process. It will send qmail-smtpd the TERM signal causing it to exit. It will restart immediately (supervise).

StopQmailSend

        StopQmailSend

Use StopQmailSend to quit the qmail-send process. It will send qmail-send the TERM signal and then wait until it's shut down before returning. If qmail-send fails to shut down within 100 seconds, then we force kill it, causing it to abort any outbound SMTP sessions that are active. This is safe, as qmail will attempt to deliver them again, and again until it succeeds.

StartQmailSend

        StartQmailSend - Start up the qmail-send process.

After starting up qmail-send, we verify that it's running before returning.

ProcessQmailQueue


ProcessQmailQueue - Tell qmail to process the queue immediately

CheckRcpthosts

        use MATT::Qmail;
        CheckRcpthosts($qmaildir);

Checks the rcpthosts file and compare it to users/assign. Any zones that are in users/assign but not in control/rcpthosts or control/morercpthosts will be presented as a list and you'll be expected to add them to morercpthosts.

ConfigQmail

        use MATT::Qmail;
        ConfigQmail($qmaildir, $host, $postmaster, $conf);

Qmail is fantastic because it's so easy to configure. Just edit files and put the right values in them. However, many find that a problem because it's not so easy to always know the sytax for what goes in every file, and exactly where that file might be. This sub takes your values from toaster-watcher.conf and puts them where they need to be. It modifies the following files:

 /var/qmail/control/concurrencyremote
 /var/qmail/control/me
 /var/qmail/control/tarpitcount
 /var/qmail/control/tarpitdelay
 /var/qmail/control/sql
 /var/qmail/alias/.qmail-postmaster
 /var/qmail/alias/.qmail-root
 /var/qmail/alias/.qmail-mailer-daemon

ConfigureQmailControl

        use MATT::Qmail;
        ConfigureQmailControl($conf);

Installs the qmail control script as well as the startup (services.sh) script.

InstallQmailSuperviseRunFiles

        use MATT::Qmail;
        InstallQmailSuperviseRunFiles($conf, $debug);

$conf is a hashref of values pulled from toaster-watcher.conf.

Generates the qmail/supervise/*/run files based on your settings.

InstallQmailSuperviseLogRunFiles

        use MATT::Qmail;
        InstallQmailSuperviseLogRunFiles($conf, $debug);

$conf is a hash of values. See ParseConfigFile or toaster-watcher.conf for config values.

Installs the files the control your supervised processes logging. Typically this consists of qmail-smtpd, qmail-send, and qmail-pop3d. The generated files are:


 qmail_supervise/pop3/log/run
 qmail_supervise/smtp/log/run
 qmail_supervise/send/log/run
 qmail_supervise/submit/log/run

GetDomainsFromAssign

Fetch a list of domains from the qmaildir/users/assign file.

        use MATT::Qmail;
        GetDomainsFromAssign($assign, $debug, $match, $value);
 $assign is the path to the assign file.
 $debug is optional
 $match is an optional field to match (dom, uid, dir)
 $value is the pattern to  match


AUTHOR

        Matt Simerson <matt@cadillac.net>


BUGS

        None known. Report any to author.


TODO


SEE ALSO

http://www.tnpi.biz/computing/ http://www.tnpi.biz/internet/mail/toaster/

Mail::Toaster::CGI, Mail::Toaster::DNS, Mail::Toaster::Logs, Mail::Toaster::Qmail, Mail::Toaster::Setup


COPYRIGHT

Copyright (c) 2004, The Network People, Inc. 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.