Tuesday 9 February 2010

Mailman-style mailing list archives

I have the posts made to several mailing lists in a variety of non-standard formats. Converting them to a standard mbox file is a matter of parsing and is a different process for each. Once I have each parsed, what I would like to do is generate Mailman-style list archives.

I've downloaded Mailman and tried to get it to take my mbox file, and output the list archives. But the process is to some degree tied to Unix-style platforms, relying on functionality that is not supported on Windows. But to a larger degree, it is tied into the quality of being a proper Mailman hosted mailing list. Even changing the code to address or work around these things is not the cleanest of processes. There must be a better way.

Any suggestions?

Have some hacky code while I am at it:


WORKING_PATH = r"D:\MailingList"
MAILMAN_PATH = os.path.join(WORKING_PATH, "mailman-2.1.13")

class MailList:
def __init__(self, basePath, fileName):
self.basePath = basePath
self.fileName = fileName
self.SetVars()

def SetVars(self):
self._internal_name = "mud-dev"
self._fullpath = "/resource/MUD-Dev/"
self.host_name = "localhost"
self.subject_prefix = "[MUD-Dev] "
self.real_name = "MUD-Dev"

def fullpath(self):
return self._fullpath

def archive_dir(self):
return self.basePath

def internal_name(self):
return self.fileName

def ArchiveFileName(self):
return os.path.join(self.basePath, self.internal_name() + ".mbox")

def GetScriptURL(self, *args, **kwargs):
return args[0]

def GetListEmail(self):
return "no-list-email"

class SuperDuperArchive(HyperArchive):
def GetArchLock(self): return 1

def DropArchLock(self): pass

def fake_symlink(src, dst):
if os.path.exists(src):
open(dst, "w").write(open(src, "r").read())

os.symlink = fake_symlink
os.link = fake_symlink
Mailman.mm_cfg.TEMPLATE_DIR = os.path.join(MAILMAN_PATH, "templates")
Mailman.mm_cfg.LIST_DATA_DIR = WORKING_PATH
Mailman.mm_cfg.PUBLIC_ARCHIVE_FILE_DIR = WORKING_PATH
Mailman.mm_cfg.PRIVATE_ARCHIVE_FILE_DIR = WORKING_PATH

mlist = MailList(os.path.join(filePath, "archives"), "mud-dev")
mlist.preferred_language = 'en'

listPath = os.path.join(Mailman.mm_cfg.LIST_DATA_DIR, mlist.internal_name())
if not os.path.exists(listPath):
os.makedirs(listPath)

class DummyClass:
def internal_name(self):
return "mud-dev"

def archive_dir(self):
return Site.get_archpath(self.internal_name())

def GetScriptURL(self, *args, **kwargs):
return args[0]

def GetListEmail(self):
return "no-list-email"

instance = DummyClass()

Mailman.MailList.MailList.InitVars.im_func(instance, "mud-dev")
for baseclass in Mailman.MailList.MailList.__bases__:
if hasattr(baseclass, 'InitVars'):
baseclass.InitVars.im_func(instance)

MailList.SetVars.im_func(instance)

listConfigPath = os.path.join(listPath, "config.pck")
if not os.path.exists(listConfigPath):
cPickle.dump(instance.__dict__, open(listConfigPath, "wb"))

archive = SuperDuperArchive(mlist)
archive.processListArch()
archive.close()
Next post: Abusing mailman on Windows

No comments:

Post a Comment