112 lines
3.0 KiB
Bash
Executable File
112 lines
3.0 KiB
Bash
Executable File
#!/bin/bash
|
|
#
|
|
# vmail-stack
|
|
# https://git.stack-source.com/msb/vmail-stack
|
|
# Copyright (c) 2022 Matthew Saunders Brown <matthewsaundersbrown@gmail.com>
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
# load include file
|
|
source $(dirname $0)/vmail.sh
|
|
|
|
help()
|
|
{
|
|
thisfilename=$(basename -- "$0")
|
|
echo "$thisfilename"
|
|
echo "Modify an existing email."
|
|
echo ""
|
|
echo "usage: $thisfilename -e <email> [OPTIONS]"
|
|
echo ""
|
|
echo " -h Print this help."
|
|
echo " -e <email> Email account to modify."
|
|
echo " -p <password> Set new password."
|
|
echo " -q <quota> Set mailbox quota in GB, otherwise default for this domain is used. NULL means no limit."
|
|
echo " -r <ratelimit> Hourly rate limit for sending, multiplied by 10 for the daily limit."
|
|
echo " -s <0|1|2> Status. 0 = disabled, 1 = enabled, 2 = enabled with admin privileges. Default is 1."
|
|
echo " -j <0|1|2> Filter Junk/Spam message. 0 = no filtering. 1 = filter Junk only. 2 = filter Junk & Spam. Default is 2."
|
|
exit
|
|
}
|
|
|
|
vmail:getoptions "$@"
|
|
|
|
# check for email
|
|
if [[ -z $email ]]; then
|
|
echo "email is required"
|
|
exit
|
|
fi
|
|
|
|
# get mbox id (and thus check if email account already exists)
|
|
mbox_id=`mysql --defaults-extra-file=$MYSQL_CONNECTION_INFO_FILE -s -r -N -e "SELECT id from vm_mboxes WHERE mbox='$mbox' AND domain='$domain';"`
|
|
|
|
if [[ -z $mbox_id ]] ; then
|
|
echo "ERROR: Email address $email does not exist."
|
|
exit
|
|
fi
|
|
|
|
# set update portion of command to empty string
|
|
dbset=""
|
|
|
|
# check for quota update
|
|
if [[ -n $quota ]]; then
|
|
# make quota uppercase in case it is set to NULL
|
|
quota=`echo $quota | tr [:lower:] [:upper:]`
|
|
if [[ "$quota" =~ ^[0-9]+$ ]] || [[ "$quota" == "NULL" ]]; then
|
|
dbset="quota=$quota"
|
|
else
|
|
echo "ERROR: quota (-q) must numeric or NULL"
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
# check for ratelimit update
|
|
if [[ -n $ratelimit ]]; then
|
|
# make ratelimit uppercase in case it is set to NULL
|
|
ratelimit=`echo $ratelimit | tr [:lower:] [:upper:]`
|
|
if [[ "$ratelimit" =~ ^[0-9]+$ ]] || [[ "$ratelimit" == "NULL" ]]; then
|
|
if [[ ! -z $dbset ]]; then
|
|
dbset="$dbset,"
|
|
fi
|
|
dbset="$dbset ratelimit=$ratelimit"
|
|
else
|
|
echo "ERROR: ratelimit (-r) must numeric or NULL"
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
# check for password update
|
|
if [[ ! -z $password ]]; then
|
|
passwd=`/usr/bin/openssl passwd -6 "$password"`
|
|
passwd="{SHA512-CRYPT}$passwd"
|
|
if [[ ! -z $dbset ]]; then
|
|
dbset="$dbset,"
|
|
fi
|
|
dbset=" $dbset passwd=\"$passwd\""
|
|
fi
|
|
|
|
# check for status update
|
|
if [[ ! -z $status ]]; then
|
|
if [[ ! -z $dbset ]]; then
|
|
dbset="$dbset,"
|
|
fi
|
|
dbset="$dbset status=\"$status\""
|
|
fi
|
|
|
|
# check for junk filter update
|
|
if [[ ! -z $filter ]]; then
|
|
if [[ ! -z $dbset ]]; then
|
|
dbset="$dbset,"
|
|
fi
|
|
dbset="$dbset filter=\"$filter\""
|
|
fi
|
|
|
|
if [[ -n $dbset ]]; then
|
|
|
|
# build query
|
|
dbcmd="mysql --defaults-extra-file=$MYSQL_CONNECTION_INFO_FILE -e 'UPDATE vm_mboxes SET $dbset WHERE id=\"$mbox_id\";'"
|
|
eval $dbcmd
|
|
|
|
else
|
|
|
|
echo "ERROR: No values passed for update."
|
|
|
|
fi
|