Q I run a mail server. Can you tell me how I can monitor mailboxes for corruption?
A Have a look for this error in the mail log /var/log/maillog): 'File isn't in mbox format - Couldn't open INBOX' If you find it, the mailbox is definitely corrupted. To avoid checking mailboxes manually, here's a script you can use:
#!/usr/bin/env python import os, sys, re mailpath = '/var/mail' mailboxes = os.listdir(mailpath) re_valid = re.compile('From\s+[^\s]', re.I) mailboxes.sort() for m in mailboxes: fn = mailpath + os.sep + m if not os.path.isdir(fn): f = open(fn, 'r') l = f.readline() if l: if re_valid.match(l): continue print "Invalid: %s" % m
Name the script verifymailboxes.bin and run it with python veryfimailboxes.bin