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