#!/usr/bin/env python import os def escape(s): s = s.replace('&', '&') return s.replace('<', '<') def info(fn): subject, sender, date = 'Message ' + fn[:-4], 'Unknown', '-' body, accumulate = [], False f = open(fn) for line in f: line = line.rstrip('\r\n') if accumulate: body.append(escape(line)) elif not line.rstrip(' '): accumulate = True else: if line.startswith('Subject: '): subject = line[9:].replace('[mysterylights] ', '') subject = subject.replace('Re: Re: ', 'Re: ') elif line.startswith('From: '): sender = line[6:] elif line.startswith('Date: '): date = line[11:28].rstrip(':') f.close() return escape(subject), escape(sender), escape(date), body def main(): n = os.environ.get('REQUEST_URI', '').split('/').pop() if n == 'format': import sys print 'Content-Type: text/plain' print f = open('format.cgi') for line in f: sys.stdout.write(line) f.close() return print 'Content-Type: text/html' print print """\ Mysterylights Group Message %s

Mysterylights Group Message %s

""" % (n, n) subject, sender, date, body = info(n + '.txt') print '

' print 'Subject: ' + subject + '
' print 'From: ' + sender + '
' print 'Date: ' + date print '

' print '
'
   for line in body: 
      if len(line) <= 100: 
         print line
      else: print line[:95] + '[...]'
   print '
' print """\
Mailing list run by Sean B. Palmer
These are archived posts of mailing list messages: see the "From" line at the top of the page for the actual author. I take no responsibility for contents of mailing list posters, but feel free to email me if you have any concerns.
""" if __name__ == '__main__': main()