plugin maildir: maildir now use PersistentBinaryDictionary to store profile specific data

/!\ profile needs to be connected for maildir/imap/smtp plugins to work, this has to be fixed
This commit is contained in:
Goffi 2011-12-03 15:50:09 +01:00
commit 04e8ab3291
2 changed files with 22 additions and 17 deletions

View file

@ -50,6 +50,7 @@ PLUGIN_INFO = {
}
class IMAP_server():
#TODO: connect profile on mailbox request, once password is accepted
params = """
<params>

View file

@ -34,6 +34,7 @@ from cStringIO import StringIO
from twisted.internet import reactor
import pdb
from sat.exceptions import *
from sat.memory.persistent import PersistentBinaryDict
from zope.interface import implements
@ -62,20 +63,30 @@ class MaildirBox():
self.host = host
self.__observed={}
self.data={} #list of profile spectific data. key = profile, value = PersistentBinaryDict where key=mailbox name,
# and value is a dictionnary with the following value
# - cur_idx: value of the current unique integer increment (UID)
# - message_id (as returned by MaildirMailbox): a tuple of (UID, [flag1, flag2, ...])
pList=host.memory.getProfilesList #shorter :)
self.__mailboxes=dict(zip(pList(),len(pList())*[{}]))
self.data=host.memory.getPrivate("MAILDIR_data") or dict(zip(pList(),len(pList())*[{"INBOX":{"cur_idx":0}}])) #Create empty box for each profile
#a value in the dictionnary for a mailbox is a dictionnary with the following value
# - cur_idx: value of the current unique integer increment (UID)
# - message_id (as returned by MaildirMailbox): a tuple of (UID, [flag1, flag2, ...])
self.__mailboxes={} #key: profile, value: {boxname: MailboxUser instance}
#the triggers
host.trigger.add("MessageReceived", self.messageReceivedTrigger)
host.trigger.add("ProfileCreation", self.newProfileTrigger)
def __del__(self):
debug('Destroying MaildirBox')
self.host.memory.setPrivate('MAILDIR_data',self.data)
def profileConnected(self, profile):
"""Called on profile connection, create profile data"""
self.data[profile] = PersistentBinaryDict("plugin_maildir", profile)
self.__mailboxes[profile]={}
def dataLoaded(ignore):
if not self.data[profile]:
#the mailbox is new, we initiate the data
self.data[profile]["INBOX"] = {"cur_idx":0}
self.data[profile].load().addCallback(dataLoaded)
def profileDisconnected(self, profile):
"""Called on profile disconnection, free profile's resources"""
del self.__mailboxes[profile]
del self.data[profile]
def messageReceivedTrigger(self, message, profile):
"""This trigger catch normal message and put the in the Maildir box.
@ -90,13 +101,6 @@ class MaildirBox():
self.accessMessageBox("INBOX", profile_key=profile).addMessage(message)
return False
def newProfileTrigger(self, profile):
"""This trigger create necessary to manage mailbox for every new profile created"""
self.__mailboxes[profile] = {}
self.data[profile]={"INBOX":{"cur_idx":0}}
self.host.memory.setPrivate('MAILDIR_data',self.data)
return True
def accessMessageBox(self, boxname, observer=None, profile_key='@DEFAULT@'):
"""Create and return a MailboxUser instance
@param boxname: name of the box