#!/usr/bin/python # ex: ts=4 tw=0 sw=4 expandtab # # a cgi harness for the mailformat mail pretty printer script # these paths are relative to where the cgi is MAILDIR = 'mail' CSSFILE = '../mailformat.css' from cgi import FieldStorage from re import match from mailformat import mailformatter from os.path import basename, join, dirname class cgihandler: def __init__(self): self.mf = None def display(self): if self.mf: self.mf.setcss(CSSFILE) self.mf.parse() print "Content-type: %s\n" % self.mf.get_ct() print self.mf.dump() else: print "Content-type: text/plain\n" print "Denied." print self.mf def handle_submit(self): fields = FieldStorage() if fields.has_key('name') and match("^%s/[.\w-]+$" % MAILDIR, fields['name'].value): self.mf = mailformatter(fields['name'].value) if __name__ == "__main__": c = cgihandler() c.handle_submit() c.display()