2013-01-23 19:26:42 +00:00
|
|
|
#!/bin/bash
|
2013-01-23 13:47:52 +00:00
|
|
|
. /usr/lib/alternc/functions.sh
|
|
|
|
|
2013-01-23 19:26:42 +00:00
|
|
|
#You can call this script either without arguments, inwich case each maildir quotas will be recalculated
|
|
|
|
#or you can call it with a directory reffering to a maildir to just sync one mailbox
|
|
|
|
|
|
|
|
#basic checks
|
|
|
|
if [ $# -gt 1 ]; then
|
|
|
|
echo "usage : update_quota_mail.sh (Maildir)."
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $# -eq 1 ];then
|
|
|
|
if [ ! -d "$1" ];then
|
|
|
|
echo "$1 is not a directory, aborting."
|
|
|
|
exit
|
|
|
|
else
|
|
|
|
d="$1"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
#Fist we set the quotas no 0 (infinite for each already existing account
|
|
|
|
t=`mysql_query "UPDATE mailbox SET quota='0' WHERE quota IS NULL"`
|
2013-01-24 10:11:30 +00:00
|
|
|
d=`find "$ALTERNC_LOC/mail/" -maxdepth 2 -mindepth 2 -type d`
|
2013-01-23 19:26:42 +00:00
|
|
|
fi
|
|
|
|
|
2013-01-23 13:47:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
#Then we loop through every maildir to get the maildir size
|
2013-01-23 19:26:42 +00:00
|
|
|
for i in $d ; do
|
|
|
|
|
|
|
|
if [ -d "$i" ];then
|
|
|
|
user=`ls -l $i| tail -n 1|cut -d' ' -f 3`
|
2013-01-24 10:11:30 +00:00
|
|
|
size=0
|
|
|
|
# We grep only mails, not the others files
|
|
|
|
mails=`find $i -type f | egrep "(^$i)*[0-9]+\.M"`
|
|
|
|
for j in $mails
|
|
|
|
do
|
|
|
|
size=$(( $size + `du -b $j|awk '{print $1}'`))
|
|
|
|
done
|
|
|
|
mail_count=`echo $mails|wc -w`
|
2013-01-23 19:26:42 +00:00
|
|
|
echo "folder : "$i
|
|
|
|
echo "mail count : "$mail_count
|
|
|
|
echo "dir size : "$size
|
|
|
|
echo ""
|
2013-01-23 13:47:52 +00:00
|
|
|
#update the mailbox table accordingly
|
2013-01-23 19:26:42 +00:00
|
|
|
mysql_query "UPDATE mailbox SET bytes=$size WHERE path='$i' "
|
|
|
|
mysql_query "UPDATE mailbox SET messages=$mail_count WHERE path='$i' "
|
|
|
|
else
|
|
|
|
echo "The maildir $i does not exists. It's quota won't be resync"
|
|
|
|
fi
|
2013-01-23 13:47:52 +00:00
|
|
|
done
|
|
|
|
|