def finish(self): import poplib from email import Parser for i in xrange(self.msgcount): try: data = self.server.retr(i+1)[1] except poplib.error_proto, e: raise MessagePOP3Error(str(e)) data = '\r\n'.join(data) p = Parser.FeedParser() p.feed(data) msg = p.close() if self.ruleset: labels = self.ruleset.apply_msg(msg) else: labels = [] yield (data, labels, get_message_date(msg))
def read_messages(self): from email import Parser for fname in os.listdir(self.dirname): if fname.startswith('.'): continue fname = os.path.join(self.dirname, fname) fp = file(fname, 'rb') p = Parser.FeedParser() for line in fp: p.feed(line) if not line.strip(): break msg = p.close() if self.ruleset: labels = self.ruleset.apply_msg(msg) else: labels = [] self.msgs.append((fname, labels, get_message_date(msg))) return
def finish(self): from mailbox import PortableUnixMailbox from email import Parser try: fp = file(self.fname, 'rb') except IOError: return for data in PortableUnixMailbox(fp, lambda msgfp: msgfp.read()): p = Parser.FeedParser() p.feed(data) msg = p.close() if self.ruleset: labels = self.ruleset.apply_msg(msg) else: labels = [] yield (data, labels, get_message_date(msg)) fp.close() return
def func2(msg, labels): t = time.time()-get_message_date(msg) return t0 <= t and t <= t1