#!/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 """\
'
print 'Subject: ' + subject + '
'
print 'From: ' + sender + '
'
print 'Date: ' + date
print '
' for line in body: if len(line) <= 100: print line else: print line[:95] + '[...]' print '' print """\