From a456a545b0e5fef3f555c25a63a23f3cf66882c2 Mon Sep 17 00:00:00 2001
From: Squidly <squidly+alternc@nnx.com>
Date: Thu, 31 Jul 2014 15:32:47 +0200
Subject: [PATCH] Updating options for update_quota_mail.sh script

---
 src/update_quota_mail.sh | 85 ++++++++++++++++++++--------------------
 1 file changed, 42 insertions(+), 43 deletions(-)

diff --git a/src/update_quota_mail.sh b/src/update_quota_mail.sh
index f82d1819..2a6d5997 100755
--- a/src/update_quota_mail.sh
+++ b/src/update_quota_mail.sh
@@ -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
 
-