Re: [exim] Mail delivery to full mailbox

Kezdőlap
Üzenet törlése
Válasz az üzenetre
Szerző: Marcin Owsiany
Dátum:  
Címzett: exim-users
Tárgy: Re: [exim] Mail delivery to full mailbox
On Thu, Jan 06, 2005 at 08:57:12AM +0100, Zbynek Houska wrote:
> Dear users,
>
> I wonder how to set up exim to refuse to deliver to full mailbox?
> Instead of queuing it in spool rather send it to /dev/null or back to
> sender (together with notice). Or better, refuse to accept mail during
> conversation with senders MTA.
>
> Is there any solution?


I use a trick like this (works also on exim3):

in /etc/crontab:

-----8<----------------------------------------------------------------------------------------
@reboot         root    /usr/local/sbin/get-over-quotas > /etc/exim/over-quota.tmp && mv /etc/exim/over-quota.tmp /etc/exim/over-quota
* *     * * *   root    /usr/local/sbin/get-over-quotas > /etc/exim/over-quota.tmp && mv /etc/exim/over-quota.tmp /etc/exim/over-quota
-----8<----------------------------------------------------------------------------------------


/usr/local/sbin/get-over-quotas:

-----8<----------------------------------------------------------------------------------------
#!/bin/bash
# Get usernames who have less than 20 KB free quota
# print username: free space
for space in free com staff;
do
        export ID=$(getent group $space | awk -F: '{print $3}')
        repquota /home/$space | tail -n +6 | \
        perl -n -e 'BEGIN{$gid=$ENV{q/ID/};@a=`awk -F: "\\\$4 == $gid {print \\\$1}" /etc/passwd`}' \
                -e '/^(\S+)/;$a=$1."\n"; print $_ if grep { $_ eq $a } @a' | \
        awk '$5 != 0 && $3 + 20 > $5 { print $1 ": :fail: User over quota - brak miejsca w skrzynce (" $5 - $3 ")"}'
done
exit 0
-----8<----------------------------------------------------------------------------------------


The script could be much simpler when there is only one partition holding mail. The
perl two-liner filters the quota usage for users which do not have mail on that
particular filesystem. Now that I have over-quota users in a file, like this:

-----8<----------------------------------------------------------------------------------------
konri: :fail: User over quota - brak miejsca w skrzynce (0)
pentium: :fail: User over quota - brak miejsca w skrzynce (0)
arturkmicic: :fail: User over quota - brak miejsca w skrzynce (16)
[...]
-----8<----------------------------------------------------------------------------------------

... the rest is simple: in /etc/exim/exim.conf just add a router like this
before your driver=localuser router/director:

-----8<----------------------------------------------------------------------------------------
# this one failes over quota accounts
over_quota:
driver = aliasfile
search_type = lsearch
file = /etc/exim/over-quota
-----8<----------------------------------------------------------------------------------------

The script executes in less than half a second, with almost 500 users on the
system, so I'd say this is a very efficient way. It is not perfect because of
the X KB and one minute fuzz, but either way, together with receiver_verify,
the problem of over-quota double-bounces is history for me now :-)

Marcin
--
Marcin Owsiany
porridge@???