From 06bc5abf349508c906a2a4de8eaaa213e0ba0d28 Mon Sep 17 00:00:00 2001 From: Steven Mondji-Lerider Date: Wed, 23 Jan 2013 13:47:52 +0000 Subject: [PATCH] Adding a script to resync maildirs quotas used by dovecot with AlternC 3 --- .gitattributes | 1 + install/upgrades/1.1.sh | 4 ++++ src/Makefile | 2 +- src/update_quota_mail.sh | 31 +++++++++++++++++++++++++++++++ 4 files changed, 37 insertions(+), 1 deletion(-) create mode 100755 src/update_quota_mail.sh diff --git a/.gitattributes b/.gitattributes index 9c83faac..e22388e8 100644 --- a/.gitattributes +++ b/.gitattributes @@ -610,6 +610,7 @@ src/spoolsize.php -text src/sqlbackup.sh -text src/update_domains.sh -text src/update_mails.sh -text +src/update_quota_mail.sh -text /svnup.sh -text tests/make_mail_dataset.sh -text tests/mechdump.pm -text diff --git a/install/upgrades/1.1.sh b/install/upgrades/1.1.sh index be028cc9..8a654405 100644 --- a/install/upgrades/1.1.sh +++ b/install/upgrades/1.1.sh @@ -62,6 +62,10 @@ invoke-rc.d dovecot stop || true # We call the migration script (provided by wiki.dovecot.com) perl "/usr/lib/alternc/courier-dovecot-migrate.pl" --to-dovecot --convert --recursive "$MAIL_DIR" + +#We have to resync maildirs quotas with dovecot informations. +/usr/lib/alternc/update_quota_mail.sh + # Starting dovecot service invoke-rc.d dovecot start || true ## End of migration part diff --git a/src/Makefile b/src/Makefile index cd2c6fa3..ef29814d 100644 --- a/src/Makefile +++ b/src/Makefile @@ -19,7 +19,7 @@ # ---------------------------------------------------------------------- # Purpose of file: Makefile des binaires de /usr/lib/alternc # ---------------------------------------------------------------------- -SCRIPTS=sqlbackup.sh quota_init quota_delete update_domains.sh slave_dns sendmail spoolsize.php fixperms.sh alternc-dboptimize export_account.php cron_users_doit.sh cron_users.sh compress_logs.sh delete_logs.sh quota-warning.sh update_mails.sh alternc_add_policy_dovecot rebuild_all_webconf.sh courier-dovecot-migrate.pl popimap-log-login.sh mem_add mem_del quota_edit quota_get du.pl +SCRIPTS=sqlbackup.sh quota_init quota_delete update_domains.sh slave_dns sendmail spoolsize.php fixperms.sh alternc-dboptimize export_account.php cron_users_doit.sh cron_users.sh compress_logs.sh delete_logs.sh quota-warning.sh update_mails.sh alternc_add_policy_dovecot rebuild_all_webconf.sh courier-dovecot-migrate.pl popimap-log-login.sh mem_add mem_del quota_edit quota_get du.pl update_quota_mail.sh LIBS=functions.sh functions_hosting.sh functions_dns.sh BIN=$(DESTDIR)/usr/lib/alternc/ diff --git a/src/update_quota_mail.sh b/src/update_quota_mail.sh new file mode 100755 index 00000000..2bc0f412 --- /dev/null +++ b/src/update_quota_mail.sh @@ -0,0 +1,31 @@ +#! /bin/bash + +. /usr/lib/alternc/functions.sh + +#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"` + + +#Then we loop through every maildir to get the maildir size +for i in $ALTERNC_LOC/mail/*/* ; do + + user=`ls -l $i| tail -n 1|cut -d' ' -f 3` + size=`du -s $i|awk '{print $1}'` + q=`mysql_query "SELECT * FROM mailbox where path = '$i' "` + + #when counting mails we eclude dovecot specific files + mail_count=`find $i -type f |grep -v dovecot* |wc -l` + echo "folder : "$i + echo "mail count : "$mail_count + echo "dir size : "$size + echo "" + + if [ -z "$q" ]; then + echo "no mail folder found for user $user " + else + #update the mailbox table accordingly + q=`mysql_query "UPDATE mailbox SET bytes=$size WHERE path='$i' "` + q=`mysql_query "UPDATE mailbox SET messages=$mail_count WHERE path='$i' "` + fi +done +