#!/usr/bin/env python import os, mailbox, email, email.Header, time import cgi import cgitb; cgitb.enable() mailroot = "/home/gauret/Mail" headers = ["From", "To", "Date", "Subject"] def listdir(folder=""): if folder: print '
' mailfolder = mailroot+"/"+folder if os.path.abspath(mailfolder).count(mailroot) == 0: print "%s n'est pas un dossier valide, mechant crackeur !" % os.path.abspath(mailfolder) return print "%s | " % header print '
---|
%s | ' % (os.environ["SCRIPT_NAME"], folder, mailid, h) print '
[Retour] ~ ' % os.environ["SCRIPT_NAME"] print '[Retour au dossier]
' % (os.environ["SCRIPT_NAME"], folder) md_file = mailroot+"/"+folder md = mailbox.Maildir(md_file, email.message_from_file) for id in range(1, int(mailid)): md.next() mail = md.next() for header in headers: h = getHeader(header, mail) print '%s: %s
' % (header, h) for part in mail.walk(): if part.is_multipart(): continue filename = part.get_filename() if filename: print 'type: %s
' % part.get_content_type() print '' % (os.environ["SCRIPT_NAME"], folder, mailid, filename, filename) continue print 'type: %s
' % part.get_content_type() print "%s" % part.get_payload(decode=True) def viewfile(folder, mailid, file): md_file = mailroot+"/"+folder md = mailbox.Maildir(md_file, email.message_from_file) for id in range(1, int(mailid)): md.next() mail = md.next() for part in mail.walk(): if part.is_multipart(): continue filename = part.get_filename() if not filename: continue if filename != file: continue print 'Content-type: %s' % part.get_content_type() print 'Content-Disposition: attachment; filename="%s"' % filename print print part.get_payload(decode=True) def getHeader(header, mail): h_tuple = email.Header.decode_header(mail.get(header))[0] h = h_tuple[0].replace("<", "<").replace(">", ">") if header == "Date": h = time.strftime("%d/%m/%y %X", email.Utils.parsedate(h)) return h def headings(): print """Content-type: text/html; charset="iso-8859-1"