Clearing MAILER-DAEMONS from Mail Queue

This little gem will certainly help get rid of pending bounce messages resulting from spam hitting your mail server:

mailq | tail -n +2 | grep -v ‘^ *(’ | awk ‘BEGIN { RS = “” }{ if ($7 == “MAILER-DAEMON” ) print $1 }’ | tr -d ‘*!’ | postsuper -d -

You cant really get simpler than this…

Repairing OSX 10.4 Mail Server Mailboxes

This script could easily be adapted to work for any postfix server, but at this moment, I dont really have the time to do it. If someone can, then please let me know at andy at andydixon.com

You run this script in this way:

repair (username) – eg: repair ajd
(where ajd is a user on the mail server)

The script is thus:


#!/bin/bash

imapUser="cyrusimap"
reconstructUser="cyrusimap"
username="$1"

userDirDest=`sudo -u ${imapUser} /usr/bin/cyrus/bin/mbpath user/$username`

echo -e "Reconstructing folder structure.."
sudo -u ${reconstructUser} /usr/bin/cyrus/bin/reconstruct -r -f user/$username

echo -e "Fixing folder permissions and ownership.."
find $userDirDest -type d -print0 | xargs -0 -n 1 chmod 0700
find $userDirDest -type d -print0 | xargs -0 -n 1 /usr/sbin/chown ${imapUser}:mail

echo -e "Fixing file permissions and ownership.."
find $userDirDest -type f -print0 | xargs -0 -n 1 chmod 0600
find $userDirDest -type f -print0 | xargs -0 -n 1 /usr/sbin/chown ${imapUser}:mail

echo "Repair Completed"