#!/usr/bin/perl -w

#----------------------------------------------------------------------
# Copyright (c) 2001 Mitel Networks Corporation 
# 
# Technical support for this program is available from Mitel Networks
# Corporation.  Please visit our web site www.e-smith.com for details.
#----------------------------------------------------------------------
package esmith;

use strict;
use Errno;
use esmith::config;
use esmith::templates;

my %conf;
tie %conf, 'esmith::config';


#------------------------------------------------------------
# This program writes the files to configure qmail, as well as
# the fetchmail and startmail scripts.
#------------------------------------------------------------

foreach my $name( qw(	
		bouncefrom
		bouncehost
	   	concurrencylocal
	   	concurrencyremote
		databytes
		defaultdomain
		defaulthost
		doublebounceto
		envnoathost
		helohost
		locals
		me
		plusdomain
		rcpthosts
		smtproutes
		virtualdomains
		) )
{
    esmith::templates::processTemplate ({ TEMPLATE_PATH => "/var/qmail/control/${name}"});
}
		

#--------------------------------------------------
# Set up aliases.
#--------------------------------------------------

esmith::templates::processTemplate ({
		TEMPLATE_PATH => "/var/qmail/alias/.qmail-localdelivery-default",
		UID => "alias",
		GID => "qmail",
	    }
	);

esmith::templates::processTemplate ({
		TEMPLATE_PATH => "/home/e-smith/.qmail",
		UID => "admin",
		GID => "admin",
		PERMS => 0640,
	    }
	);
unless (-f "/home/e-smith/.qmail-default")
{
    symlink ".qmail", "/home/e-smith/.qmail-default";
}

if ($conf{'EmailUnknownUser'} && ($conf{'EmailUnknownUser'} eq 'admin'))
{
    esmith::templates::processTemplate
	({
		TEMPLATE_PATH => "/var/qmail/alias/.qmail-default",
		UID => "alias",
		GID => "qmail",
	});
}
else
{
    unlink ("/var/qmail/alias/.qmail-default");
}

#------------------------------------------------------------
# Configure Fetchmail.
#------------------------------------------------------------

esmith::templates::processTemplate (
                                {
                                  TEMPLATE_PATH => "/etc/startmail",
                                  PERMS         => 0700,
                                  UID           => "root",
                                  GID           => "daemon",
                                } );

esmith::templates::processTemplate (
                                {
                                  TEMPLATE_PATH => "/etc/fetchmail",
                                  PERMS         => 0700,
                                  UID           => "qmailr",
                                  GID           => "nofiles",
                                } );

exit (0);
