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:
parent
75db4c47b6
commit
d1ae81f4c7
1 changed files with 25 additions and 16 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue