Polishing mailbox quota updating script
This commit is contained in:
parent
77bda2ca38
commit
7ef2d8bd0d
|
@ -5,7 +5,7 @@
|
||||||
#or you can call it with a directory reffering to a maildir to just sync one mailbox
|
#or you can call it with a directory reffering to a maildir to just sync one mailbox
|
||||||
|
|
||||||
function showhelp() {
|
function showhelp() {
|
||||||
echo "FIXME: some help"
|
echo "$1"
|
||||||
exit
|
exit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,70 +16,54 @@ do
|
||||||
case "$optname" in
|
case "$optname" in
|
||||||
"a")
|
"a")
|
||||||
# All mails
|
# All mails
|
||||||
# FIXME replace it by a select in da DB
|
maildirs=$(mysql_query "select path from mailbox")
|
||||||
maildirs=`find "$ALTERNC_MAIL/" -maxdepth 2 -mindepth 2 -type d`
|
|
||||||
;;
|
;;
|
||||||
"m")
|
"m")
|
||||||
# An email
|
# An email
|
||||||
if [[ "$OPTARG" =~ ^[^\@]*@[^\@]*$ ]] ; then
|
if [[ ! "$OPTARG" =~ ^[^\@]*@[^\@]*$ ]] ; then
|
||||||
if [[ "$(mysql_query "select userdb_home from dovecot_view where user = '$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'")
|
maildirs=$(mysql_query "select userdb_home from dovecot_view where user = '$OPTARG'")
|
||||||
else
|
|
||||||
echo "Bad mail provided"
|
|
||||||
showhelp
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo "Bad mail provided"
|
|
||||||
showhelp
|
|
||||||
fi
|
|
||||||
;;
|
;;
|
||||||
"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-z\-]+(\.[a-z\-]+)+$ ]] ; then
|
||||||
echo "Bad domain provided"
|
showhelp "bad domain provided"
|
||||||
showhelp
|
|
||||||
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
|
||||||
echo "Bad domain provided"
|
showhelp "non existant domain"
|
||||||
showhelp
|
|
||||||
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-z]*$ ]] ; then
|
||||||
if [[ "$(mysql_query "select domaine from domaines where domaine = '$1'")" ]]; 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")
|
maildirs=$(mysql_query "select userdb_home from dovecot_view where userdb_uid = $OPTARG")
|
||||||
else
|
|
||||||
echo "Bad account provided"
|
|
||||||
showhelp
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
echo "Bad account provided"
|
|
||||||
showhelp
|
|
||||||
fi
|
|
||||||
;;
|
;;
|
||||||
"?")
|
"?")
|
||||||
echo "Unknown option $OPTARG - stop processing"
|
showhelp "Unknown option $OPTARG - stop processing"
|
||||||
showhelp
|
|
||||||
exit
|
|
||||||
;;
|
;;
|
||||||
":")
|
":")
|
||||||
echo "No argument value for option $OPTARG - stop processing"
|
showhelp "No argument value for option $OPTARG - stop processing"
|
||||||
showhelp
|
|
||||||
exit
|
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
# Should not occur
|
# Should not occur
|
||||||
echo "Unknown error while processing options"
|
echo
|
||||||
showhelp
|
showhelp "Unknown error while processing options"
|
||||||
exit
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
@ -96,6 +80,11 @@ for i in $maildirs ; do
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ ! -d "$i" ];then
|
||||||
|
echo "The maildir $i does not exists. It's quota won't be resync"
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
# We grep only mails, not the others files
|
# We grep only mails, not the others files
|
||||||
mails=`find $i -type f | egrep "(^$i)*[0-9]+\.M"`
|
mails=`find $i -type f | egrep "(^$i)*[0-9]+\.M"`
|
||||||
|
|
||||||
|
@ -112,3 +101,4 @@ 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
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue