Created
January 25, 2010 16:40
-
-
Save jiphex/285998 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
# | |
# James Hannah <[email protected]> - 2010-01-25 | |
# | |
# Opens a mailbox (mbox) file and runs through all the messages, | |
# splitting them into the real mailboxes. Should be useful when | |
# for some reason mail gets delivered into a shared mbox instead | |
# of the correct mboxes. | |
import mailbox | |
import os.path | |
boringrcpt = ['root','postmaster','[email protected]', '[email protected]'] | |
print "Loading mbox...", | |
allmail = mailbox.mbox('allmail') | |
allmail.lock() | |
for msg in allmail: | |
origto = msg['X-Original-To'] | |
if origto == "" or origto == None: | |
#print "\t\tEmpty origto" | |
pass | |
elif origto in boringrcpt: | |
#print "\t\tDisregarding message to %s" % origto | |
pass | |
else: | |
mboxname = origto.replace("@", ".").strip() | |
mboxpath = "/var/spool/mail/%s" % mboxname | |
if(os.path.exists(mboxpath)): | |
print "Found workable mailbox %s!" % mboxpath | |
target = mailbox.mbox(mboxpath) | |
target.lock() | |
target.add(msg) | |
print "Added message to %s" % mboxpath | |
target.unlock() | |
target.close() | |
else: | |
print "%s DOES NOT EXIST!" % mboxpath | |
allmail.unlock() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment