def __parse(self): """ Parse mailingg list and load all indexes into memory """ previous = None mbox = Mbox(self.config.get('mbox')) messages = 0 message = mbox.nextMessage() while(message != None): try: #fisrt load message msg = Message(message, self.config) #index it self.index.add(msg) self.subscribers.add(msg) subscriber = self.subscribers.get(msg.getFromMail()) msg.setSender(subscriber) #parent message (refactor) inReplyTo = msg.getInReplyTo() if (inReplyTo != None): parent = self.index.get(inReplyTo) if (parent != None): msg.setParent(parent) #link child with parent parent.addChild(msg) #and parent with child #and previous and next by date if (previous != None): previous.setNextByDate(msg) msg.setPreviousByDate(previous) previous = msg except KeyError, details: print 'Error parsing a mail form mailbox: ' + str(details) messages += 1 #and continue with next message message = mbox.nextMessage()
def publish(self): """ Publish the messages """ self.__createDir() #first lap self.__parse() #and second lap mbox = Mbox(self.config.get('mbox')) messages = 0 message = mbox.nextMessage() while(message != None): try: messages += 1 try: id = message['Message-Id'] except: id = random.randint(1000000000, 9999999999) + "@localhost" #FIXME print messages + "is not a valid RFC2822 message, it hasn't message-id field" msg = self.index.getMessage(messages) msg.setBody(message.fp.read()) msg.toRDF() msg.toXHTML() #self.index.delete(id) except Exception, detail: print 'Error processing message ' + str(messages) + ': ' + str(detail) #import traceback #traceback.print_exc(file=sys.stdout) message = mbox.nextMessage()