def scan_file(file): fp = open(file, 'r') mbox = UnixMailbox(fp) #msg = email.message_from_file(fp) #print_header(msg) #msg = email.message_from_file(fp) #print_header(msg) #print "ok" #return i = 0 for mail in mbox: i = i + 1 fromh = mail.getheader("from") date = mail.getdate("date") mydate = '%4d/%2d/%2d' % (date[2], date[1], date[0]) print i, mydate, fromh
#!/usr/bin/env python2.4 from mailbox import UnixMailbox from PyLucene import StandardAnalyzer, FSDirectory, IndexWriter from email import EmailDoc store = FSDirectory.getDirectory('chipy-index', True) writer = IndexWriter(store, StandardAnalyzer(), True) mailbox = UnixMailbox(open('chipy.mbox')) while True: msg = mailbox.next() if msg == None: break writer.addDocument(EmailDoc(msg)) writer.close()
def openmailbox(self): fd = self.vfs.open(self.getselector(), "rt") return UnixMailbox(fd)
def prepare(self): self.rfile = self.vfs.open(self.getselector(), "rt") self.mbox = UnixMailbox(self.rfile) FolderHandler.prepare(self)