diff 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
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