#!/bin/sh
#
# addpopbox copyright (C) 1996 by Bert Gijsbers (bert@mc.bio.uva.nl)
# GNU General Public License version 2 applies.
#
# modified by Mark Nottingham 17/5/97
#
# This script installs one or more new pop-only mailboxes.
# Suppose this script is started with one argument "joe"
# then a directory ~pop/joe/Maildir/ is made first,
# next a file ~pop/.qmail-joe is made with contents
# ~pop/joe/Maildir/, next a file ~alias/.qmail-joe is made
# with contents "&pop-joe".  Last the apop program is
# started to prompt for Joe's APOP passphrase.
# Note that the arguments to this script shouldn't contain
# any uppercase letters or dots due to qmail looking only for
# lowercase .qmail files while replacing any dots with colons
# in filenames.
#

ALIASUSER="alias"
ALIASHOME="/var/qmail/alias"
POPUSER="pop"
POPHOME="/var/mailhome/pop"

if [ ! -d "$POPHOME" ]; then
    mkdir "$POPHOME" || exit 1
    chmod 500 "$POPHOME" || exit 1
    chown "$POPUSER" "$POPHOME" || exit 1
    apop -i || exit 1
fi
while [ "$1" != "" ]; do
    POPBOX="$1"
    shift
    mkdir "$POPHOME/$POPBOX"
    chmod 755 "$POPHOME/$POPBOX" || exit 1
    /var/qmail/bin/maildirmake "$POPHOME/$POPBOX/Maildir"
    chown -R "$POPUSER" "$POPHOME/$POPBOX" || exit 1
    echo "$POPHOME/$POPBOX/Maildir/" > "$POPHOME/.qmail-$POPBOX" || exit 1
    chmod 644 "$POPHOME/.qmail-$POPBOX" || exit 1
    chown "$POPUSER" "$POPHOME/.qmail-$POPBOX" || exit 1
    echo "&pop-$POPBOX" > "$ALIASHOME/.qmail-$POPBOX" || exit 1
    chmod 644 "$ALIASHOME/.qmail-$POPBOX" || exit 1
    chown "$ALIASUSER" "$ALIASHOME/.qmail-$POPBOX" || exit 1
    /var/qmail/bin/apop -m "$POPBOX" || echo "Run apop to input password for $POPBOX."
done

exit 0
