comparison src/plugins/plugin_misc_maildir.py @ 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 012c38b56cdd
children 27bc5d7732a3
comparison
equal deleted inserted replaced
258:aac82dee6091 259:11f71187d5e4
67 self.data=host.memory.getPrivate("MAILDIR_data") or dict(zip(pList(),len(pList())*[{"INBOX":{"cur_idx":0}}])) #Create empty box for each profile 67 self.data=host.memory.getPrivate("MAILDIR_data") or dict(zip(pList(),len(pList())*[{"INBOX":{"cur_idx":0}}])) #Create empty box for each profile
68 #a value in the dictionnary for a mailbox is a dictionnary with the following value 68 #a value in the dictionnary for a mailbox is a dictionnary with the following value
69 # - cur_idx: value of the current unique integer increment (UID) 69 # - cur_idx: value of the current unique integer increment (UID)
70 # - message_id (as returned by MaildirMailbox): a tuple of (UID, [flag1, flag2, ...]) 70 # - message_id (as returned by MaildirMailbox): a tuple of (UID, [flag1, flag2, ...])
71 71
72 #the trigger 72 #the triggers
73 host.trigger.add("MessageReceived", self.MessageReceivedTrigger) 73 host.trigger.add("MessageReceived", self.messageReceivedTrigger)
74 host.trigger.add("ProfileCreation", self.newProfileTrigger)
74 75
75 def __del__(self): 76 def __del__(self):
76 debug('Destroying MaildirBox') 77 debug('Destroying MaildirBox')
77 self.host.memory.setPrivate('MAILDIR_data',self.data) 78 self.host.memory.setPrivate('MAILDIR_data',self.data)
79
80 def messageReceivedTrigger(self, message, profile):
81 """This trigger catch normal message and put the in the Maildir box.
82 If the message is not of "normal" type, do nothing
83 @param message: message xmlstrem
84 @return: False if it's a normal message, True else"""
85 for e in message.elements():
86 if e.name == "body":
87 type = message['type'] if message.hasAttribute('type') else 'chat' #FIXME: check specs
88 if message['type'] != 'normal':
89 return True
90 self.accessMessageBox("INBOX", profile_key=profile).addMessage(message)
91 return False
92
93 def newProfileTrigger(self, profile):
94 """This trigger create necessary to manage mailbox for every new profile created"""
95 self.__mailboxes[profile] = {}
96 self.data[profile]={"INBOX":{"cur_idx":0}}
97 self.host.memory.setPrivate('MAILDIR_data',self.data)
98 return True
78 99
79 def accessMessageBox(self, boxname, observer=None, profile_key='@DEFAULT@'): 100 def accessMessageBox(self, boxname, observer=None, profile_key='@DEFAULT@'):
80 """Create and return a MailboxUser instance 101 """Create and return a MailboxUser instance
81 @param boxname: name of the box 102 @param boxname: name of the box
82 @param observer: method to call when a NewMessage arrive""" 103 @param observer: method to call when a NewMessage arrive"""
239 if key not in existant_id and key!="cur_idx": 260 if key not in existant_id and key!="cur_idx":
240 to_remove.append(key) 261 to_remove.append(key)
241 for key in to_remove: 262 for key in to_remove:
242 del box_data[key] 263 del box_data[key]
243 264
244
245 def MessageReceivedTrigger(self, message, profile):
246 """This trigger catch normal message and put the in the Maildir box.
247 If the message is not of "normal" type, do nothing
248 @param message: message xmlstrem
249 @return: False if it's a normal message, True else"""
250 for e in message.elements():
251 if e.name == "body":
252 type = message['type'] if message.hasAttribute('type') else 'chat' #FIXME: check specs
253 if message['type'] != 'normal':
254 return True
255 self.accessMessageBox("INBOX", profile_key=profile).addMessage(message)
256 return False
257
258 def addObserver(self, callback, profile, boxname, signal="NEW_MESSAGE"): 265 def addObserver(self, callback, profile, boxname, signal="NEW_MESSAGE"):
259 """Add an observer for maildir box changes 266 """Add an observer for maildir box changes
260 @param callback: method to call when the the box is updated 267 @param callback: method to call when the the box is updated
261 @param boxname: name of the box to observe 268 @param boxname: name of the box to observe
262 @param signal: which signal is observed by the caller""" 269 @param signal: which signal is observed by the caller"""