# get domain_id (and thus check if domain already exists)
domain_id=`mysql --defaults-extra-file=$MYSQL_CONNECTION_INFO_FILE -s -r -N -e "SELECT id from vm_domains WHERE domain='$domain';"`
if[ -z $domain_id];then
echo"ERROR: Domain $domain does not exist."
exit
fi
# make sure mbox doesn't already exist
rowcount=`mysql --defaults-extra-file=$MYSQL_CONNECTION_INFO_FILE -s -r -N -e "SELECT COUNT(*) FROM vm_mboxes WHERE domain_id='$domain_id' AND mbox='$mbox';"`
dbcmd="mysql --defaults-extra-file=$MYSQL_CONNECTION_INFO_FILE -e 'INSERT INTO vm_mboxes SET domain_id=\"$domain_id\", mbox=\"$mbox\", passwd=\"$passwd\""
if[ -n "$status"];then
if["$status"==0]||["$status"==1];then
dbcmd="$dbcmd, status=\"$status\""
else
echo"ERROR: status (-s) must be 1 or 0"
exit
fi
fi
if[ -z "$quota"];then
# get mbox_quota_default from domains table
quota=`mysql --defaults-extra-file=$MYSQL_CONNECTION_INFO_FILE -s -r -N -e "SELECT mbox_quota_default from vm_domains WHERE domain='$domain';"`
fi
if[["$quota"=="NULL"]];then
dbcmd="$dbcmd, quota=NULL"
elif[["$quota"=~ ^[0-9]+$ ]];then
dbcmd="$dbcmd, quota=\"$quota\""
else
echo"ERROR: quota (-q) must numeric or NULL"
exit1
fi
dbcmd="$dbcmd;'"
elif["$rowcount" -eq '1'];then
echo"ERROR: $email already exists in vmail database."
exit
else
echo"ERROR: System error querying vmail database."