Mercurial > libervia-backend
changeset 439:866dbb0d7d87
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
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 03 Dec 2011 15:50:09 +0100 (2011-12-03) |
parents | 62145e50eae5 |
children | 48277946348b |
files | src/memory/persistent.py src/plugins/plugin_misc_imap.py src/plugins/plugin_misc_maildir.py |
diffstat | 3 files changed, 22 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/src/memory/persistent.py Sat Dec 03 15:45:48 2011 +0100 +++ b/src/memory/persistent.py Sat Dec 03 15:50:09 2011 +0100 @@ -79,7 +79,7 @@ return self._cache.__hash__() def __nonzero__(self): - return self._cache.__nonzero__() + return self._cache.__len__() def __unicode__(self): return self._cache.__unicode__()
--- a/src/plugins/plugin_misc_imap.py Sat Dec 03 15:45:48 2011 +0100 +++ b/src/plugins/plugin_misc_imap.py Sat Dec 03 15:50:09 2011 +0100 @@ -50,6 +50,7 @@ } class IMAP_server(): + #TODO: connect profile on mailbox request, once password is accepted params = """ <params>
--- a/src/plugins/plugin_misc_maildir.py Sat Dec 03 15:45:48 2011 +0100 +++ b/src/plugins/plugin_misc_maildir.py Sat Dec 03 15:50:09 2011 +0100 @@ -34,6 +34,7 @@ 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 @@ 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 @@ 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