Mercurial > libervia-backend
changeset 259:11f71187d5e4
core, plugin Maildir: added "ProfileCreation" Trigger
This trigger is user by maildir to create account data for the new profile
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 18 Jan 2011 01:07:12 +0100 |
parents | aac82dee6091 |
children | c8406fe5e81e |
files | src/plugins/plugin_misc_maildir.py src/tools/memory.py |
diffstat | 2 files changed, 25 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/src/plugins/plugin_misc_maildir.py Tue Jan 18 01:04:20 2011 +0100 +++ b/src/plugins/plugin_misc_maildir.py Tue Jan 18 01:07:12 2011 +0100 @@ -69,13 +69,34 @@ # - cur_idx: value of the current unique integer increment (UID) # - message_id (as returned by MaildirMailbox): a tuple of (UID, [flag1, flag2, ...]) - #the trigger - host.trigger.add("MessageReceived", self.MessageReceivedTrigger) + #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 messageReceivedTrigger(self, message, profile): + """This trigger catch normal message and put the in the Maildir box. + If the message is not of "normal" type, do nothing + @param message: message xmlstrem + @return: False if it's a normal message, True else""" + for e in message.elements(): + if e.name == "body": + type = message['type'] if message.hasAttribute('type') else 'chat' #FIXME: check specs + if message['type'] != 'normal': + return True + 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 @@ -241,20 +262,6 @@ for key in to_remove: del box_data[key] - - def MessageReceivedTrigger(self, message, profile): - """This trigger catch normal message and put the in the Maildir box. - If the message is not of "normal" type, do nothing - @param message: message xmlstrem - @return: False if it's a normal message, True else""" - for e in message.elements(): - if e.name == "body": - type = message['type'] if message.hasAttribute('type') else 'chat' #FIXME: check specs - if message['type'] != 'normal': - return True - self.accessMessageBox("INBOX", profile_key=profile).addMessage(message) - return False - def addObserver(self, callback, profile, boxname, signal="NEW_MESSAGE"): """Add an observer for maildir box changes @param callback: method to call when the the box is updated
--- a/src/tools/memory.py Tue Jan 18 01:04:20 2011 +0100 +++ b/src/tools/memory.py Tue Jan 18 01:07:12 2011 +0100 @@ -131,6 +131,8 @@ if self.params.has_key(name): info (_('The profile name already exists')) return 1 + if not self.host.trigger.point("ProfileCreation", name): + return 0 self.params[name]={} return 0