summaryrefslogtreecommitdiff
path: root/src/leap/mail/imap/server.py
diff options
context:
space:
mode:
authorKali Kaneko <kali@leap.se>2013-10-31 22:34:50 -0200
committerTomás Touceda <chiiph@leap.se>2013-11-01 10:19:59 -0300
commit64cbb0d02e312a91c324b49ddb99bfb691b4e2cd (patch)
treeccb71bfb288bcebdb9ca4647960b1720dccca706 /src/leap/mail/imap/server.py
parentd9eaccecf3a4e9677140092bd29e13ea662658f9 (diff)
notify MUA of new mail as it gets added to mailbox
Diffstat (limited to 'src/leap/mail/imap/server.py')
-rw-r--r--src/leap/mail/imap/server.py48
1 files changed, 38 insertions, 10 deletions
diff --git a/src/leap/mail/imap/server.py b/src/leap/mail/imap/server.py
index 9e3e23e..7a9f810 100644
--- a/src/leap/mail/imap/server.py
+++ b/src/leap/mail/imap/server.py
@@ -573,7 +573,7 @@ class SoledadBackedAccount(WithMsgFields, IndexedDB):
return "<SoledadBackedAccount (%s)>" % self._account_name
#######################################
-# Soledad Message, MessageCollection
+# LeapMessage, MessageCollection
# and Mailbox
#######################################
@@ -1099,6 +1099,7 @@ class SoledadMailbox(WithMsgFields):
which we instantiate and make accessible in the `messages` attribute.
"""
implements(imap4.IMailboxInfo, imap4.IMailbox, imap4.ICloseableMailbox)
+ # XXX should finish the implementation of IMailboxListener
messages = None
_closed = False
@@ -1115,6 +1116,8 @@ class SoledadMailbox(WithMsgFields):
CMD_UIDVALIDITY = "UIDVALIDITY"
CMD_UNSEEN = "UNSEEN"
+ listeners = []
+
def __init__(self, mbox, soledad=None, rw=1):
"""
SoledadMailbox constructor. Needs to get passed a name, plus a
@@ -1147,15 +1150,35 @@ class SoledadMailbox(WithMsgFields):
if not self.getFlags():
self.setFlags(self.INIT_FLAGS)
- # XXX what is/was this used for? --------
- # ---> mail/imap4.py +1155,
- # _cbSelectWork makes use of this
- # probably should implement hooks here
- # using leap.common.events
- self.listeners = []
- self.addListener = self.listeners.append
- self.removeListener = self.listeners.remove
- #------------------------------------------
+ # the server itself is a listener to the mailbox.
+ # so we can notify it (and should!) after chanes in flags
+ # and number of messages.
+ print "emptying the listeners"
+ map(lambda i: self.listeners.remove(i), self.listeners)
+
+ def addListener(self, listener):
+ """
+ Rdds a listener to the listeners queue.
+
+ :param listener: listener to add
+ :type listener: an object that implements IMailboxListener
+ """
+ logger.debug('adding mailbox listener: %s' % listener)
+ self.listeners.append(listener)
+
+ def removeListener(self, listener):
+ """
+ Removes a listener from the listeners queue.
+
+ :param listener: listener to remove
+ :type listener: an object that implements IMailboxListener
+ """
+ logger.debug('removing mailbox listener: %s' % listener)
+ try:
+ self.listeners.remove(listener)
+ except ValueError:
+ logger.error(
+ "removeListener: cannot remove listener %s" % listener)
def _get_mbox(self):
"""
@@ -1180,6 +1203,7 @@ class SoledadMailbox(WithMsgFields):
#return map(str, self.INIT_FLAGS)
# XXX CHECK against thunderbird XXX
+ # XXX I think this is slightly broken.. :/
mbox = self._get_mbox()
if not mbox:
@@ -1352,6 +1376,10 @@ class SoledadMailbox(WithMsgFields):
self.messages.add_msg(message, flags=flags, date=date,
uid=uid_next)
+ exists = len(self.messages)
+ recent = len(self.messages.get_recent())
+ for listener in self.listeners:
+ listener.newMessages(exists, recent)
return defer.succeed(None)
# commands, do not rename methods