diff --git a/skynet_old_mail-import.sh b/skynet_old_mail-import.sh index 378f585..ed95614 100644 --- a/skynet_old_mail-import.sh +++ b/skynet_old_mail-import.sh @@ -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 \ No newline at end of file diff --git a/skynet_old_mail-send.sh b/skynet_old_mail-send.sh index fa45a52..0f67727 100644 --- a/skynet_old_mail-send.sh +++ b/skynet_old_mail-send.sh @@ -4,8 +4,11 @@ echo "Subject: Testing, please ignore 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 username=$(basename "$dir"); @@ -14,8 +17,9 @@ do continue fi - sendmail "$username@skynet.ie" < email.txt - - echo "Complete: $username" + if [ ! -d "$TO/$username" ]; then + sendmail "$username@skynet.ie" < email.txt + echo "Mail Sent: $username" + fi done