Dealing with the 'Default Address' Issue OLD
From brokenpoet.org wiki
Contents |
Default Addresses
Unfortunately, when a new WHM install is performed, it sets the Catch-All setting for all new cPanel users to the cPanel username.
This means that all mail destined for an address that doesn't exist ends up being deposited in /home/username/mail/new/ and /home/username/mail/cur/
This can cause numerous problems from quota overruns to cpbackup failing (due to the large number of files) - so it can cause minor to major issues.
While the default for NEW accounts can be changed to ":fail:" through WHM -> Tweak Settings, this does not affect the existing accounts.
Checking Default Address file count and size
I have written a script for this which will show you the count of files and the size of the directories for all users. At some point I want to rewrite in perl and have it sort and add the option to remove and change to :fail: per user. However, for now it is a multi-part process . . .
In order to get the script and run it (to see if this is an issue):
wget http://scripts.brokenpoet.org/chkdefaultaddresssize.sh sh chkdefaultaddresssize.sh
Now on to the fixing
Changing all accounts to :fail:
:fail: is by far the best choice for the server and links to this affect are:
Blackhole or Fail -- Which One is Better For Your Mail Server
and
Now, to change all existing accounts to :fail: you should:
cd /etc/valiases for file in $(grep -lr -e '*:' .); do sed 's/\*\:.*/\*\:\ \:fail\:\ No\ Such\ User\ Here/g' $file > $file.tmp; cat $file.tmp > $file;rm -f $file.tmp;done
Removing all mail from Default Accounts
Again, simple commandline fu:
for i in $(cat /etc/domainusers |cut -d':' -f1); do echo "Removing CUR mail for $i . . . ";\ find /home/$i/mail/cur/ -type f|xargs rm -rf; echo "Removing NEW mail for $i . . . ";\ find /home/$i/mail/new/ -type f|xargs rm -rf;done
That will take a WHILE sometimes (which is why I created the output) . . .
I had to write a variation of this to remove all mail except for certain users. Simply put in the usernames where it says user#.
for i in $(cat /etc/domainusers |cut -d':' -f1|awk '!/user1|user2/' );\ do echo "Removing CUR mail for $i";\ find /home/$i/mail/cur/ -type f|xargs rm -rf;\ echo "Removing NEW mail for $i";\ find /home/$i/mail/new/ -type f|xargs rm -rf;done
The "|" means OR - you can exclude more users by simply adding another |username to the section awk '!/user1|user2/'
ie: awk '!/user1|user2|user3|user4/'
NEW SCRIPT
There is a new version viewable here
It is faster and has more functionality.
You can simply download this as a script. Be sure to edit the script if you do not want to remove ALL default mail.
wget http://scripts.brokenpoet.org/removedefaultmail.sh
That's about it
