Пример #1
0
 def __init__(self, config, base="./", lang=None):
     """
     Constructor method
     
     @param config: configuration
     @param lang: language
     """
     
     self.config = config
     self.base = base
     self.lang = lang
     self.subscribers = Subscribers(config)
     self.index = Index(self.config)
     
     self.uri = self.config.get('base') + 'forum'
Пример #2
0
class MailingList:
    """
    Mailing List abstraction
    """
    
    def __init__(self, config, base="./", lang=None):
        """
        Constructor method
        
        @param config: configuration
        @param lang: language
        """
        
        self.config = config
        self.base = base
        self.lang = lang
        self.subscribers = Subscribers(config)
        self.index = Index(self.config)
        
        self.uri = self.config.get('base') + 'forum'
        
    def __createDir(self):
        """
        Create the necessary directory
        """
        
        if not (os.path.exists(self.config.get('dir'))):
            os.mkdir(self.config.get('dir'))
        
    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()

        self.messages = messages