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 do
username=$(basename "$dir"); username=$(basename "$dir");
if [ -z "$(ls -A $FROM/$username)" ]; then
rm -rf $FROM/$username
continue
fi
# a few usernames are bogus, ignore these # a few usernames are bogus, ignore these
if [[ $username == bogus* ]] || [[ $username == BOGUS* ]]; if [[ $username == bogus* ]] || [[ $username == BOGUS* ]];
then then
@ -36,26 +41,29 @@ do
if [ ! -d "$TO_USER" ]; then if [ ! -d "$TO_USER" ]; then
# if it doesnt exist, create it and do the rest of this script. # if it doesnt exist, create it and do the rest of this script.
mkdir $TO_USER mkdir $TO_USER
fi
cp -R $FROM/$username/* $TO_USER/
# from https://askubuntu.com/a/483192
# set proper permissions mv $FROM/$username/{*,.[^.]*,..?*} $TO_USER/
chmod -R 600 $TO_USER/
chmod -R u+X $TO_USER/ # if empty
if [ -z "$(ls -A $FROM/$username)" ]; then
# change owner to the mailserver rm -rf $FROM/$username
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 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 done

View file

@ -4,8 +4,11 @@
echo "Subject: Testing, please ignore echo "Subject: Testing, please ignore
Testing please ignore" > email.txt Testing please ignore" > email.txt
FROM=/skynet_old/mail
TO=/var/vmail/skynet.ie
for dir in /skynet_old/mail/*;
for dir in $FROM/*;
do do
username=$(basename "$dir"); username=$(basename "$dir");
@ -14,8 +17,9 @@ do
continue continue
fi fi
sendmail "$username@skynet.ie" < email.txt if [ ! -d "$TO/$username" ]; then
sendmail "$username@skynet.ie" < email.txt
echo "Complete: $username" echo "Mail Sent: $username"
fi
done done