core, plugin Maildir: added "ProfileCreation" Trigger

This trigger is user by maildir to create account data for the new profile
This commit is contained in:
Goffi 2011-01-18 01:07:12 +01:00
commit d1ae81f4c7
2 changed files with 25 additions and 16 deletions

View file

@ -69,13 +69,34 @@ class MaildirBox():
# - 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 @@ class MaildirBox():
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

View file

@ -131,6 +131,8 @@ class Param():
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