add filter option to mboxes

This commit is contained in:
Matthew Saunders Brown 2021-11-20 15:20:24 -08:00
parent 074264942a
commit c55e2644a8
4 changed files with 19 additions and 2 deletions

View File

@ -13,13 +13,14 @@ help()
echo "$thisfilename" echo "$thisfilename"
echo "Add email account to vmail system" echo "Add email account to vmail system"
echo "" echo ""
echo "usage: $thisfilename -e <email> -p <password> [-q <quota>] [-s <0|1>] [-h]" echo "usage: $thisfilename -e <email> -p <password> [-q <quota>] [-s <0|1>] [-j <0|1|2>] [-h]"
echo "" echo ""
echo " -h Print this help." echo " -h Print this help."
echo " -e <email> Email address to add." echo " -e <email> Email address to add."
echo " -p <password> Unencrypted Password for new email address." echo " -p <password> Unencrypted Password for new email address."
echo " -q <quota> Set mailbox quota in GB, otherwise default for this domain is used. NULL means no limit." echo " -q <quota> Set mailbox quota in GB, otherwise default for this domain is used. NULL means no limit."
echo " -s <0|1> Status. 1 for enabled, 0 for disabled. Default is in db structure and is normally set to 1." echo " -s <0|1> Status. 1 for enabled, 0 for disabled. Default is in db structure and is normally set to 1."
echo " -j <0|1|2> Filter Junk/Spam messages. 0 = not filtering. 1 = filter Junk only. 2 = filter Junk & Spam. Default is 2."
} }
vmail:getoptions "$@" vmail:getoptions "$@"
@ -53,6 +54,9 @@ if [ "$rowcount" -eq '0' ] ; then
if [[ -n $status ]] ; then if [[ -n $status ]] ; then
dbcmd="$dbcmd, status=\"$status\"" dbcmd="$dbcmd, status=\"$status\""
fi fi
if [[ -n $filter ]] ; then
dbcmd="$dbcmd, filter=\"$filter\""
fi
if [ -z "$quota" ] ; then if [ -z "$quota" ] ; then
# get mbox_quota_default from domains table # 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';"` quota=`mysql --defaults-extra-file=$MYSQL_CONNECTION_INFO_FILE -s -r -N -e "SELECT mbox_quota_default from vm_domains WHERE domain='$domain';"`

View File

@ -20,6 +20,7 @@ help()
echo " -p <password> Set new password." 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 " -q <quota> Set mailbox quota in GB, otherwise default for this domain is used. NULL means no limit."
echo " -s <0|1> 1 for enabled, 0 for disabled. Default is in db structure and is normally set to 1." echo " -s <0|1> 1 for enabled, 0 for disabled. Default is in db structure and is normally set to 1."
echo " -j <0|1|2> Filter Junk/Spam message. 0 = not filtering. 1 = filter Junk only. 2 = filter Junk & Spam. Default is 2."
exit exit
} }
@ -71,6 +72,14 @@ if [ ! -z "$status" ]; then
dbset="$dbset status=\"$status\"" dbset="$dbset status=\"$status\""
fi 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 if [ -n "$dbset" ]; then
# build query # build query

View File

@ -85,7 +85,7 @@ function vmail::yesno() {
function vmail:getoptions () { function vmail:getoptions () {
local OPTIND local OPTIND
while getopts "ha:b:d:e:f:gcp:q:s:tk:f:gl:m:vx" opt ; do while getopts "ha:b:d:e:f:gj:cp:q:s:tk:gl:m:vx" opt ; do
case "${opt}" in case "${opt}" in
h ) # display help and exit h ) # display help and exit
help help
@ -159,6 +159,9 @@ function vmail:getoptions () {
g ) # glob (wildcard) search g ) # glob (wildcard) search
glob=${OPTARG,,} glob=${OPTARG,,}
;; ;;
j ) # Filter Junk
filter=${OPTARG}
;;
k ) # keep k ) # keep
keep=${OPTARG} keep=${OPTARG}
if [[ $keep != "0" ]] && [[ $keep != "1" ]]; then if [[ $keep != "0" ]] && [[ $keep != "1" ]]; then

View File

@ -179,6 +179,7 @@ CREATE TABLE IF NOT EXISTS `vm_mboxes` (
`passwd` char(128) NOT NULL, `passwd` char(128) NOT NULL,
`status` tinyint(1) NOT NULL DEFAULT 1, `status` tinyint(1) NOT NULL DEFAULT 1,
`quota` int(10) UNSIGNED DEFAULT NULL, `quota` int(10) UNSIGNED DEFAULT NULL,
`filter` tinyint(1) NOT NULL DEFAULT 2,
PRIMARY KEY (`id`), PRIMARY KEY (`id`),
KEY `email` (`domain_id`,`mbox`) USING BTREE KEY `email` (`domain_id`,`mbox`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;