HOME_USERS=/home/users
MAIL_SPOOL=/var/spool/mail
function move_mailboxlist
{
if [ ! -d "$HOME_USERS/$1" ];
then
echo "Error: $HOME_USERS/$1 does not exist"
return 0
fi
cd "$HOME_USERS/$1"
mkdir mail
chown "$1" mail
if [ ! -f ".mailboxlist" ];
then
echo "Warning: .mailboxlist does not exist for $1"
return 0
fi
cat .mailboxlist | tr '\n' '\0' | xargs -0 mv -t ./mail/
mkdir Maildir
chown "$1" Maildir
cp -a .mailboxlist Maildir/subscriptions
}
function move_inbox
{
if [ ! -f "${MAIL_SPOOL}/$1" ];
then
echo "Error: ${MAIL_SPOOL}/$1 does not exist"
return 0
fi
cp "${MAIL_SPOOL}/$1" "${HOME_USERS}/$1/mail/inbox"
chown "$1" "${HOME_USERS}/$1/mail/inbox"
}
if [ $# -eq 0 ];
then
echo "First, did you edit the directory names in the script?"
echo "Then, if you want to do a dry run, prefix mv and cp with echo."
echo "Then, invoke $0 by passing one or more user names."
exit
fi
for user in $@
do
echo "*** Processing user $user"
move_mailboxlist $user
move_inbox $user
done