{
    use esmith::config;
    use esmith::db;

    $OUT = '';

    # Generate qmail user assignments for users. These will be handled by
    # ~user/.qmail.

    my %accounts;
    tie %accounts, 'esmith::config', "/home/e-smith/accounts";

    foreach (db_get(\%accounts))
    {
	next unless db_get_type(\%accounts, $_) eq "user";

	my (undef, undef, $uid, $gid, undef, undef, undef, $dir, undef)
	    = getpwnam($_);

	# It is almost impossible to get Text::Template to output nothing
	# on failure. It can be done by removing the newline at the end of
	# this file but that is messy. Therefore, we'll simply return an
	# error message that will make qmail-newu fail. Also send a
	# warning message that will be captured in the logs.

	unless (defined $uid && defined $gid && defined $dir)
	{
	    my $msg =
		"Failed to obtain user details for \'$_\' "
		. "while processing user assignments.";

	    warn "$msg\n";
	    $OUT = $msg;
	    return;
	}

	$user_assign = "${_}:${uid}:${gid}:${dir}";

	# Assign mail for user@
	$OUT .= "=${_}:${user_assign}:::\n";

	# Assign mail for user-ext@
	$OUT .= "+${_}-:${user_assign}:-::\n";
    }

    # Need to remove the final newline character. Blank lines in
    # /var/qmail/users/assign are prohibited.

    chomp($OUT);

    # Failsafe: /var/qmail/users/assign cannot have blank lines.
    # Therefore, if $OUT is empty, simply set up an assign for the
    # alias user.

    unless ($OUT)
    {
	(undef, undef, $uid, $gid, undef, undef, undef, $dir, undef)
		= getpwnam("alias");

	$alias_assign = "alias:${uid}:${gid}:${dir}";
	$OUT = "=alias:${alias_assign}:::";
    }
}
