NAME

Mail::Toaster:::Qmail - Common Qmail functions

SYNOPSIS

Mail::Toaster::Qmail is a module of Mail::Toaster. It contains features for use with qmail, like starting and stopping the deamons, installing qmail, checking the contents of config files, etc.

See http://www.tnpi.biz/internet/mail/toaster for details.

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.

METHODS

new

To use any of the methods following, you need to create a qmail object:

        use Mail::Toaster::Qmail;
        my $qmail = Mail::Toaster::Qmail->new();

build_pop3_run

        $qmail->build_pop3_run($conf, $file, $debug) ? print "success" : print "failed";

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 $utility->parse_config). I typically use it like this:

  my $file = "/tmp/toaster-watcher-pop3-runfile";
  if ( $qmail->build_pop3_run($conf, $file ) )
  {
    $qmail->install_supervise_run( {file=>$file, service=>"pop3"}, $conf);
  };

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

build_send_run

  $qmail->build_send_run($conf, $file, $debug) ? print "success";

build_send_run 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 toaster-watcher.conf. I typically use it like this:

  my $file = "/tmp/toaster-watcher-send-runfile";
  if ( $qmail->build_send_run($conf, $file ) )
  {
    $qmail->install_supervise_run( {file=>$file, service=>"send"}, $conf);
    $qmail->restart($conf, $debug);
  };

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

build_smtp_run

  if ( $qmail->build_smtp_run($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 ( $qmail->build_smtp_run($conf, $file ) )
  {
    $qmail->install_supervise_run( {file=>$file, service=>"smtp"}, $conf);
  };

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

build_submit_run

  if ( $qmail->build_submit_run($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 ( $qmail->build_submit_run($conf, $file ) )
  {
    $qmail->install_supervise_run( {file=>$file, service=>"submit"}, $conf);
  };

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

check_control

Verify the existence of the qmail control directory (typically /var/qmail/control).

check_rcpthosts

  $qmail->check_rcpthosts($qmaildir);

Checks the control/rcpthosts file and compares it's contents 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.

config

   $qmail->config($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 syntax 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/spfbehavior
   /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

You should not manually edit these files. Instead, make changes in toaster-watcher.conf and allow it to keep the updated.

control_create

  $qmail->control_create($conf);

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

get_domains_from_assign

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

  $qmail->get_domains_from_assign($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

returns an array

get_list_of_rbls

  my $selected = $qmail->get_list_of_rbls($arrayref, $debug);

We get passed a configuration file (toaster-watcher.conf) and from it we extract all the RBL's the user has selected.

returns an array ref.

get_list_of_rwls

  my $selected = $qmail->get_list_of_rwls($conf, $debug);

Here we collect a list of the RWLs from the configuration file that get's passed to us.

returns an arrayref with a list of the enabled list from your config file.

install_qmail

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.

  $qmail->install_qmail($conf, $package, $debug);

$conf is a hash of values from toaster-watcher.conf

$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/

install_qmail_control_files

  $qmail->install_qmail_control_files($conf, $debug);

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

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

install_supervise_run

Installs a new supervise/run file for a supervised service. It first builds a new file, then compares it to the existing one and installs the new file if it's changed. It optionally notifies the admin.

  my $file = "/tmp/toaster-watcher-smtpd-runfile";

  if ( $qmail->build_smtp_run($conf, $file, $debug ) )
  {
    $qmail->install_supervise_run( {file=>$file, service=>"smtp"}, $debug);
  };

Input is a hashref with these values:

  file    - new file that was created (typically /tmp/something) 
  service - one of (smtp, send, pop3, submit)

returns 1 on success, 0 on error

install_qmail_control_log_files

        $qmail->install_qmail_control_log_files($conf, $progs, $debug);

$conf is a hash of values. See $utility->parse_config 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

netqmail

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.

  $qmail->netqmail($conf, $package);

$conf is a hash of values from toaster-watcher.conf

$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/

netqmail_virgin

Builds and installs a pristine net-qmail. This is necessary to resolve a chicken and egg problem. You can't apply the toaster patches (specifically chkuser) against NetQmail until vpopmail is installed, and you can't install vpopmail without qmail being installed. After installing this, and then vpopmail, you can rebuild NetQmail with the toaster patches.

  $qmail->netqmail_virgin($conf, $package);

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

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

queue_process

queue_process - Tell qmail to process the queue immediately

restart

  $qmail->restart()

Use to restart the qmail-send process. It will send qmail-send the TERM signal and then return.

send_start

        $qmail->send_start() - Start up the qmail-send process.

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

send_stop

  $qmail->send_stop()

Use send_stop 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.

service_dir_get

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

  $qmail->service_dir_get($conf, $prot);

$prot is the protocol (smtp, pop3, submit, send).

returned is the directory

supervise_dir_get

  my $dir = $qmail->supervise_dir_get($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.

smtpd_restart

  $qmail->smtpd_restart($conf, "smtp", $debug)

Use smtpd_restart to restart the qmail-smtpd process. It will send qmail-smtpd the TERM signal causing it to exit. It will restart immediately because it's supervised.

test_each_rbl

        my $available = $qmail->test_each_rbl($selected, $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.

returns a list of the correctly functioning RBLs.

_test_smtpd_config_values

Runs the following tests:

  make sure qmail_dir exists
  make sure vpopmail home dir exists
  make sure qmail_supervise is not a directory

_supervise_dir_exist

AUTHOR

Matt Simerson <matt@tnpi.biz>

BUGS

None known. Report any to author.

TODO

SEE ALSO

The following are all man/perldoc pages:

 Mail::Toaster 
 Mail::Toaster::Conf
 toaster.conf
 toaster-watcher.conf

 http://matt.simerson.net/computing/mail/toaster/

COPYRIGHT

Copyright (c) 2004-2005, 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.