#!/bin/bash # Used to create maildirs via PostfixAdmin. Also creates a SquirrelMail profile # and a Spam folder. This is stuffed into create-mailbox.php. # This assumes you configured PostfixAdmin to create maildirs in this format: /var/vmail/example.com/user/ # $1 is the domain # $2 is the user name # $3 is the quota # $4 $5 $6 $7 contain the pieces and parts of the full name set -e # set this variable to match your system mail_home="/var/vmail" if [ ! -e $mail_home ] ; then echo "mail_home '$mail_home' does not exist; bailing out." exit 1 fi # If this is the first mailbox created in a given domain, we will have to create the domain directory if [ ! -d $mail_home/$1 ] ; then mkdir $mail_home/$1 chown -R vmail:vmail $mail_home/$1 chmod -R 700 $mail_home/$1 # echo "$mail_home/$1 CREATED," fi # Just a note to tell us we are creating a mailbox where a maildir already exists on disk. # This could be bad if the mail actually belongs to a previously deleted mailbox. # This also edits the quota if it has changed - or deletes it if quota is turned off if [ -d $mail_home/$1/$2 ] ; then # echo "NOTE: $mail_home/$1/$2 EXISTS" cd "$mail_home/$1" if [[ $3 > 0 ]]; then maildirmake.maildrop -q "$3S" $2 chown -R vmail:vmail $mail_home/$1/$2/maildirsize chmod 0640 $mail_home/$1/$2/maildirsize else rm $mail_home/$1/$2/maildirsize fi fi if [ -d $mail_home/$1 ] ; then cd "$mail_home/$1" maildirmake.maildrop $2 # if the maildir already exists, the program exits at this point # echo "$mail_home/$1/$2 CREATED" maildirmake.maildrop -q "$3S" $2 # echo "$3S $2 QUOTA CREATED," maildirmake.maildrop -f Spam $mail_home/$1/$2 # echo "Spam folder created," touch "$mail_home/$1/$2/subscriptions" if ! grep -q Spam "$mail_home/$1/$2/subscriptions"; then echo "Spam" >> "$mail_home/$1/$2/subscriptions" fi # echo "subscribed Spam folder to $2" chown -R vmail:vmail $mail_home/$1/$2 chmod -R 700 $mail_home/$1/$2 fi # If using SquirrelMail, create a profile if one does not exist if [ -d /var/lib/squirrelmail/data ] ; then touch "/var/lib/squirrelmail/data/$2@$1.pref" if ! grep -q full_name "/var/lib/squirrelmail/data/$2@$1.pref"; then echo "full_name=$4 $5 $6 $7" >> "/var/lib/squirrelmail/data/$2@$1.pref" fi if ! grep -q email_address "/var/lib/squirrelmail/data/$2@$1.pref"; then echo "email_address=$2@$1" >> "/var/lib/squirrelmail/data/$2@$1.pref" fi chown www-data:www-data "/var/lib/squirrelmail/data/$2@$1.pref" chmod 600 "/var/lib/squirrelmail/data/$2@$1.pref" fi