feat: improvements based on feedback and useage

This commit is contained in:
silver 2023-12-16 04:23:21 +00:00
parent 342e67e10c
commit 602f9b572b
2 changed files with 36 additions and 24 deletions

View file

@ -18,6 +18,11 @@ for dir in $FROM/*;
do
username=$(basename "$dir");
if [ -z "$(ls -A $FROM/$username)" ]; then
rm -rf $FROM/$username
continue
fi
# a few usernames are bogus, ignore these
if [[ $username == bogus* ]] || [[ $username == BOGUS* ]];
then
@ -36,26 +41,29 @@ do
if [ ! -d "$TO_USER" ]; then
# if it doesnt exist, create it and do the rest of this script.
mkdir $TO_USER
cp -R $FROM/$username/* $TO_USER/
# set proper permissions
chmod -R 600 $TO_USER/
chmod -R u+X $TO_USER/
# change owner to the mailserver
chown -R virtualMail:virtualMail $TO_USER/
# subscribe the user to the mailbox show it shows up
doveadm mailbox subscribe -u "$username@skynet.ie" $MAILBOX
# this pops a new mail in that mailbox
sendmail "$username+$MAILBOX@skynet.ie" < email.txt
echo "Complete: $username"
else
# if the sub-mailbox already exists dont touch it again.
echo "Already Complete: $username"
fi
# from https://askubuntu.com/a/483192
mv $FROM/$username/{*,.[^.]*,..?*} $TO_USER/
# if empty
if [ -z "$(ls -A $FROM/$username)" ]; then
rm -rf $FROM/$username
fi
# set proper permissions
chmod -R 600 $TO_USER/
chmod -R u+X $TO_USER/
# change owner to the mailserver
chown -R virtualMail:virtualMail $TO_USER/
# subscribe the user to the mailbox show it shows up
doveadm mailbox subscribe -u "$username@skynet.ie" $MAILBOX
# this pops a new mail in that mailbox
sendmail "$username+$MAILBOX@skynet.ie" < email.txt
echo "Complete: $username";
done