Quota warnings

Malcolm Locke malc at e2-media.co.nz
Sun Jan 14 15:23:55 EST 2007


On Sat, Jan 13, 2007 at 10:41:05AM +0100, Anders Norrbring wrote:
> Anders Norrbring skrev:
> >Hello!
> >I run a Cyrus IMAP server v2.3.7 and I've set this in imapd.conf:
> >
> >quotawarn: 80
> >enable_quota_warnings: yes
> >
> >This seems to work fine with IMAP clients, but when someone use MS 
> >Outlook or Outlook Express and poll mail with POP3, there's no quota 
> >warning showing up.
> >
> >Is there some way to fix this? Perhaps the server generates a mail in 
> >the inbox for the users, so POP clients also get warned.
> 
> I just realized how stupid this looks without more background..
> The server autocreates folders like INBOX.SPAM and others, and since POP 
> clients deosn't pull other folders than the INBOX, quotas can be 
> exceeded anyway. So a way to alert those clients would be great!

I use the following as a cron job running nightly which will only notify
the user every 5 days.  Run as 'check-cyrus-quotas.sh 80' to notify when
quota is over 80%, default is 90%.  Make sure the dir
/var/state/check-cyrus-quotas exists and is writable by the cron
process.  Edit /etc/mail-quota-warning.txt to fit your setup.

HTH,

Malc

check-cyrus-quotas.sh
------------------------------------------------
#!/bin/bash

DELIVER=/usr/lib/cyrus/deliver
HEADER="   Quota  % Used    Used Username"
TEMPLATE=/etc/mail-quota-warning.txt
# Notify the user every n days that they are over quota
NOTIFY_INTERVAL=5
STAMPDIR=/var/state/check-cyrus-quotas

# Set the default warning threshhold
if [ -n "$1" ] ; then
        THRESHHOLD=$1
else
        THRESHHOLD=90
fi

# Remove any stale stamp files
find $STAMPDIR -type f -mtime +$NOTIFY_INTERVAL | xargs -r rm

mboxlist=`awk -v threshhold=$THRESHHOLD '{if(NR>1 && $2>=threshhold){print}}'`

if [ -z "$mboxlist" ] ; then
        exit
fi

# Create tmp file to hold timestamp
tmpfile=`mktemp /tmp/check-cyrus-quotas-XXXXXX`
touch -d "$NOTIFY_INTERVAL days ago" $tmpfile

echo "Sending quota warning to the following mailboxes which exceed the"
echo "quota threshhold of ${THRESHHOLD}%"
echo
echo "$HEADER"

IFS="
"
for mbox in $mboxlist ; do
        echo -n "$mbox"
        user=`echo "$mbox" | awk '{print $4}'`
        user=${user//user./}
        if [ -f "$TEMPLATE" ] ; then
                # Script creates a stamp file so as not to send a notification
                # every day to an over quota mailbox.
                if [ -f $STAMPDIR/$user ] && [ $STAMPDIR/$user -nt $tmpfile ]
                then
                        echo " [not notified]"
                        continue
                fi
                        sed -e "s/@USAGE@/$HEADER\n$mbox/;s/@USER@/$user/g" $TEMPLATE | $DELIVER -q $user
                touch $STAMPDIR/$user
                echo " [notified]"
        fi
done

rm $tmpfile
------------------------------------------------

/etc/mail-quota-warning.txt
------------------------------------------------
From: Postmaster <postmaster at yourdomain.com>
Subject: Mail quota warning for user @USER@

Hello,

This is an automated message from the email system.  You are receiving
this message because your mailbox is approaching its storage capacity
limit.  Your current usage is:

@USAGE@

Please be aware that if your mailbox storage reaches 100% YOU WILL NO
LONGER BE ABLE TO RECEIVE EMAIL.

Thank you,

Postmaster
------------------------------------------------
-- 
Malcolm Locke - Systems Administrator, http://www.e2-media.co.nz/


More information about the Info-cyrus mailing list