Over the past few months I began to notice a steady erosion in available disk space on a server running the Parallels’ Plesk control panel. After some sleuthing I tracked it down to the management of mailboxes in combination with the “Mail Forward” and “Mail Group” functions on domains the “Mailbox quota” set to unlimited.
There are two basic issues:
- Users setup 'redirects' or 'mail group' functions and leave the account mailbox enabled, then never check the mailbox and delete the messages. (e.g. sales@somedomain.com forwards to bill@somedomain.com and jim@gmail.com, but nobody logs on to sales@ and deletes the message)
- Disabling the mailbox does not delete the existing files in the mailbox. All those mail files will just hang around forever, orphaned from the control panel.
Slogging around in the qmail directories looking for files is no fun. Here’s how I rid myself of these pesky disk-eaters. I took a two pronged approach:
- Query the Plesk database to identify mail accounts with mailboxes that redirect.
- Query the filesystem to find Mailbox directories that are large.
Query the Plesk Database
You’ll need shell access to your server. Login to your server, pop into mysql and use the Plesk database (PSA) using the following command:
Use the following query to select mailboxes that redirect:
Now you’ve got some ammunition. Exit out of mysql.
Finding Big Mailboxes
A ‘mailbox’ in qmail is simply a directory. Each undelivered message is a file in that directory. On my installation of Plesk qmail is installed in ‘/var/qmail/’ The mailbox for ‘jimbo@somedomain.com’ takes the form: ‘/var/qmail/somedomain.com/jimbo/Maildir/new’.
The command below uses ‘du’ to grab the size of all the directories in mailnames, grep filters out all but the ‘Maildir/new’ directory leaving us with a list of all our mailboxes and their size. Running them through sort in the manner shown orders them biggest to smallest. Just the way we want ‘em.
Log in as root and run the following:
Sample Output:
Delete those Suckers
Armed with all the mailboxes that forward and a list of the big offenders you wouldn’t think this would need much explanation, but after several weeks or months of collecting files you may find you have to many files in the directory to delete with a simple
Apparently there are limits to the number of files you can delete at one time with a wildcard. If you run into difficulties with rm give this a shot:
CD to the directory and run
Note that the name of your server is a string common to all files, replace MYSERVER below with the common string:
In your gusto to clean things out remember that there are legitimate reasons to keep a mailbox turned on for forwarded accounts, (The boss may want to be able to review mail sent to sales@ to make sure that leads are being followed up on, etc.) and some users may just get incredible amounts of mail. With that in mind this should help you keep a lid on things. Once you’ve got things cleaned out you may be able to use quotas to help the problem from repeating.