#!/usr/bin/env python2

import pymongo

class MailDB():
    def __init__(self, host="localhost", port=27017, database="maildb"):
        client=pymongo.MongoClient( host, port )
        self.db=client[database]
    def getPbox( self, email ):
        return self.db[email]
    def getMails( self, pbox, query={} ):
        if query :
            return [ entry for entry in pbox.find( query ) ]
        return [ entry for entry in pbox.find() ]
    def addMails( self, pbox, msg ):
        pbox.insert( msg )

# TEST
if __name__ == "__main__" :
    print "I am a library, do not run me directly unless you do test."
    
    #t=MailDB()
    #pb=t.getPbox('test')
    #t.addMails( pb, { "msg":"first" } )
    #print t.getMails( pb )
    
    
