def get_mails(self): try: self.__connect() except ImapBoxConnectionError: raise ImapBoxConnectionError() except ImapBoxAuthError: raise ImapBoxAuthError() mails = [] try: if self.use_default_mbox: result, message = self.mbox.select(readonly=1) else: result, message = self.mbox.select(self.mbox_dir, readonly=1) if result != 'OK': raise Exception, message # retrieve only unseen messages typ, data = self.mbox.search(None, 'UNSEEN') for num in data[0].split(): # fetch only needed fields f = self.mbox.fetch(num, '(BODY.PEEK[HEADER.FIELDS (SUBJECT FROM MESSAGE-ID)])') hp = HeaderParser() m = hp.parsestr(f[1][0][1]) sub = utils.mime_decode(m['subject']) fr = utils.mime_decode(m['from']) mails.append([m['Message-ID'], sub, fr]) except Exception, e: print str(e)
def get_mails(self): self.__connect() messages = [] print "Starting reading POP messages" msgs = self.mbox.list()[1] print "POP messages readed: %i" % (len(msgs)) for msg in msgs: msgNum = int(msg.split(" ")[0]) msgSize = int(msg.split(" ")[1]) # retrieve only the header st = "\n".join(self.mbox.top(msgNum, 0)[1]) print st print "----------------------------------------" msg = self.parser.parsestr(st, True) # header only sub = utils.mime_decode(msg.get("Subject")) msgid = msg.get("Message-Id") if not msgid: msgid = hash(msg.get("Received") + sub) fr = utils.mime_decode(msg.get("From")) messages.append( [msgid, sub, fr] ) self.mbox.quit() return messages
def get_mails(self): try: self.__connect() except ImapBoxConnectionError: raise ImapBoxConnectionError() except ImapBoxAuthError: raise ImapBoxAuthError() mails = [] try: if self.use_default_mbox: result, message = self.mbox.select(readonly=1) else: result, message = self.mbox.select(self.mbox_dir, readonly=1) if result != 'OK': raise Exception, message # retrieve only unseen messages typ, data = self.mbox.search(None, 'UNSEEN') for num in data[0].split(): # fetch only needed fields f = self.mbox.fetch( num, '(BODY.PEEK[HEADER.FIELDS (SUBJECT FROM MESSAGE-ID)])') hp = HeaderParser() m = hp.parsestr(f[1][0][1]) sub = utils.mime_decode(m['subject']) fr = utils.mime_decode(m['from']) mails.append([m['Message-ID'], sub, fr]) except Exception, e: print str(e)
def __get_mail_content(self, mbox, msgNum): # retrieve only the header st = "\n".join(mbox.top(msgNum, 0)[1]) #print st #print "----------------------------------------" msg = self.parser.parsestr(st, True) # header only sub = utils.mime_decode(msg.get("Subject")) fr = utils.mime_decode(msg.get("From")) return [msgNum, sub, fr]
def get_mails(self): self.__connect() messages = [] msgs = self.mbox.list()[1] for msg in msgs: try: msgNum = int(msg.split(" ")[0]) msgSize = int(msg.split(" ")[1]) # retrieve only the header st = "\n".join(self.mbox.top(msgNum, 0)[1]) #print st #print "----------------------------------------" msg = self.parser.parsestr(st, True) # header only sub = utils.mime_decode(msg.get("Subject")) msgid = msg.get("Message-Id") if not msgid: msgid = hash(msg.get("Received") + sub) fr = utils.mime_decode(msg.get("From")) messages.append( [msgid, sub, fr] ) except Exception, e: logger.error("Error reading pop3 box: " + str(e))