18 Aug 2012 17:17
Find "overquota" mailboxes
tobi <tobster <at> brain-force.ch>
2012-08-18 15:17:06 GMT
2012-08-18 15:17:06 GMT
Hello list I need your experience here to see if "my" solution is good or bad(Continue reading)Background: We have a postfix setup which can only check users quota after postfix accepted the message. As you can imagine we produce a lot of backscatter. Until now the procedure was to manually check mailq and delete mails from "well-known" users which never clean up their mailboxes (do not blame me about that, I just started to work there 4 weeks ago
) So I thought that must be solved somehow easier and more automatically. My basic idea is to regularly scan the mailq for mails defered by "overquota". From these mails in queue I fetch the recipients and add them to a recipient-restriction file for postfix. So postfix can reject such mails before the queue. <<snip>> #!/bin/bash LIMIT=10 TFILE=$(mktemp) mailq | tail -n +2| awk 'BEGIN {RS = ""} /over quota/ {print $NF}' | grep -v maildrop: | sort -n | uniq -c | sort -nr | awk '{if($1> '"$LIMIT"') print $2}' > $TFILE while read line ; do echo "$line 550 Account $line is overquota and cannot receive mails" >> /root/overquota done <$TFILE cp -f /root/overquota /etc/postfix/ postmap /etc/postfix/overquota
Background:
We have a postfix setup which can only check users quota after postfix
accepted the message. As you can imagine we produce a lot of
backscatter. Until now the procedure was to manually check mailq and
delete mails from "well-known" users which never clean up their
mailboxes (do not blame me about that, I just started to work there 4
weeks ago
)
So I thought that must be solved somehow easier and more automatically.
My basic idea is to regularly scan the mailq for mails defered by
"overquota". From these mails in queue I fetch the recipients and add
them to a recipient-restriction file for postfix. So postfix can reject
such mails before the queue.
<<snip>>
#!/bin/bash
LIMIT=10
TFILE=$(mktemp)
mailq | tail -n +2| awk 'BEGIN {RS = ""} /over quota/ {print $NF}' |
grep -v maildrop: | sort -n | uniq -c | sort -nr | awk '{if($1>
'"$LIMIT"') print $2}' > $TFILE
while read line ; do
echo "$line 550 Account $line is overquota and cannot receive mails" >>
/root/overquota
done <$TFILE
cp -f /root/overquota /etc/postfix/
postmap /etc/postfix/overquota
RSS Feed