Updating options for update_quota_mail.sh script

This commit is contained in:
Squidly 2014-07-31 15:32:47 +02:00
parent d37d906ff5
commit a456a545b0
1 changed files with 42 additions and 43 deletions

View File

@ -6,7 +6,7 @@
function showhelp() {
echo "$1"
exit
exit
}
@ -14,57 +14,57 @@ function showhelp() {
while getopts "a:m:d:c:" optname
do
case "$optname" in
"a")
"a")
# All mails
maildirs=$(mysql_query "select path from mailbox")
;;
"m")
# An email
if [[ ! "$OPTARG" =~ ^[^\@]*@[^\@]*$ ]] ; then
showhelp "bad mail address provided"
fi
if [[! "$(mysql_query "select userdb_home from dovecot_view where user = '$OPTARG'")" ]]; then
showhelp "non existant mail address"
fi
maildirs=$(mysql_query "select userdb_home from dovecot_view where user = '$OPTARG'")
;;
"d")
maildirs=$(mysql_query "select path from mailbox")
;;
"m")
# An email
if [[ ! "$OPTARG" =~ ^[^\@]*@[^\@]*$ ]] ; then
showhelp "bad mail address provided"
fi
if [[ ! "$(mysql_query "select userdb_home from dovecot_view where user = '$OPTARG'")" ]]; then
showhelp "non existant mail address"
fi
maildirs=$(mysql_query "select userdb_home from dovecot_view where user = '$OPTARG'")
;;
"d")
# Expecting a domain
# Check if domain is well-formed
if [[ ! "$OPTARG" =~ ^[a-z\-]+(\.[a-z\-]+)+$ ]] ; then
showhelp "bad domain provided"
fi
if [[ ! "$OPTARG" =~ ^[a-z0-9\-]+(\.[a-z\-]+)+$ ]] ; then
showhelp "bad domain provided"
fi
# Attemp to get from database.
if [[ ! "$(mysql_query "select domaine from domaines where domaine = '$OPTARG'")" ]]; then
if [[ ! "$(mysql_query "select domaine from domaines where domaine = '$OPTARG'")" ]]; then
# Seem to be empty
showhelp "non existant domain"
fi
showhelp "non existant domain"
fi
maildirs=$(mysql_query "select userdb_home from dovecot_view where user like '%@$OPTARG'")
;;
"c")
maildirs=$(mysql_query "select userdb_home from dovecot_view where user like '%@$OPTARG'")
;;
"c")
# An account
if [[! "$OPTARG" =~ ^[a-z]*$ ]] ; then
showhelp "bad account provided"
fi
if [[! "$(mysql_query "select domaine from domaines where domaine = '$1'")" ]]; then
showhelp "non existant account"
fi
maildirs=$(mysql_query "select userdb_home from dovecot_view where userdb_uid = $OPTARG")
;;
"?")
showhelp "Unknown option $OPTARG - stop processing"
;;
":")
showhelp "No argument value for option $OPTARG - stop processing"
;;
*)
if [[! "$OPTARG" =~ ^[a-z0-9]*$ ]] ; then
showhelp "bad account provided"
fi
if [[! "$(mysql_query "select domaine from domaines where domaine = '$1'")" ]]; then
showhelp "non existant account"
fi
maildirs=$(mysql_query "select userdb_home from dovecot_view where userdb_uid = $OPTARG")
;;
"?")
showhelp "Unknown option $OPTARG - stop processing"
;;
":")
showhelp "No argument value for option $OPTARG - stop processing"
;;
*)
# Should not occur
echo
showhelp "Unknown error while processing options"
;;
echo
showhelp "Unknown error while processing options"
;;
esac
done
@ -101,4 +101,3 @@ for i in $maildirs ; do
mysql_query "UPDATE mailbox SET messages=$mail_count WHERE path='$i' ; "
done