# HG changeset patch # User Goffi # Date 1295309232 -3600 # Node ID 11f71187d5e454d98563d2a31f8aec40714e3ce5 # Parent aac82dee60917f46572358064e012ef674058241 core, plugin Maildir: added "ProfileCreation" Trigger This trigger is user by maildir to create account data for the new profile diff -r aac82dee6091 -r 11f71187d5e4 src/plugins/plugin_misc_maildir.py --- 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 diff -r aac82dee6091 -r 11f71187d5e4 src/tools/memory.py --- 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