From cffce1a7dfbca91278862e7a173e661e6644e6ec Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Tue, 25 Feb 2014 12:19:21 -0400 Subject: Workaround for broken notify-after-copy --- src/leap/mail/imap/mailbox.py | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/src/leap/mail/imap/mailbox.py b/src/leap/mail/imap/mailbox.py index 947cf1b..9b1f4e5 100644 --- a/src/leap/mail/imap/mailbox.py +++ b/src/leap/mail/imap/mailbox.py @@ -474,7 +474,11 @@ class SoledadMailbox(WithMsgFields, MBoxParser): d = self._do_add_message(message, flags=flags, date=date) if PROFILE_CMD: do_profile_cmd(d, "APPEND") - # XXX should notify here probably + + # A better place for this would be the COPY/APPEND dispatcher + # in server.py, but qtreactor hangs when I do that, so this seems + # to work fine for now. + d.addCallback(lambda r: self.reactor.callLater(0, self.notify_new)) return d def _do_add_message(self, message, flags, date): @@ -485,7 +489,6 @@ class SoledadMailbox(WithMsgFields, MBoxParser): d = self.messages.add_msg(message, flags=flags, date=date) return d - @deferred_to_thread def notify_new(self, *args): """ Notify of new messages to all the listeners. @@ -494,13 +497,28 @@ class SoledadMailbox(WithMsgFields, MBoxParser): """ if not NOTIFY_NEW: return + + def cbNotifyNew(result): + exists, recent = result + for l in self.listeners: + l.newMessages(exists, recent) + d = self._get_notify_count() + d.addCallback(cbNotifyNew) + + @deferred_to_thread + def _get_notify_count(self): + """ + Get message count and recent count for this mailbox + Executed in a separate thread. Called from notify_new. + + :return: number of messages and number of recent messages. + :rtype: tuple + """ exists = self.getMessageCount() recent = self.getRecentCount() logger.debug("NOTIFY (%r): there are %s messages, %s recent" % ( self.mbox, exists, recent)) - - for l in self.listeners: - l.newMessages(exists, recent) + return exists, recent # commands, do not rename methods @@ -880,6 +898,11 @@ class SoledadMailbox(WithMsgFields, MBoxParser): d = defer.Deferred() if PROFILE_CMD: do_profile_cmd(d, "COPY") + + # A better place for this would be the COPY/APPEND dispatcher + # in server.py, but qtreactor hangs when I do that, so this seems + # to work fine for now. + d.addCallback(lambda r: self.reactor.callLater(0, self.notify_new)) deferLater(self.reactor, 0, self._do_copy, message, d) return d -- cgit v1.2.3 From 127ee651a09284524b185419e61914fe6911cf71 Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Tue, 25 Feb 2014 12:21:57 -0400 Subject: changes file --- changes/bug_5167_fix-notify-after-copy | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changes/bug_5167_fix-notify-after-copy diff --git a/changes/bug_5167_fix-notify-after-copy b/changes/bug_5167_fix-notify-after-copy new file mode 100644 index 0000000..36ecd0b --- /dev/null +++ b/changes/bug_5167_fix-notify-after-copy @@ -0,0 +1,2 @@ + o Fix bug in which destination folder sometimes was not showing messages after copy/append. + Closes: #5167 -- cgit v1.2.3 From 6480fe087e764ace849f552bef3339e1fcd85eff Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Tue, 25 Feb 2014 21:41:53 -0400 Subject: fix unread notification to UI --- changes/bug_5177_fix_unread_signal_to_ui | 1 + src/leap/mail/imap/mailbox.py | 37 ++++++++++++++++++++------------ 2 files changed, 24 insertions(+), 14 deletions(-) create mode 100644 changes/bug_5177_fix_unread_signal_to_ui diff --git a/changes/bug_5177_fix_unread_signal_to_ui b/changes/bug_5177_fix_unread_signal_to_ui new file mode 100644 index 0000000..eac79f2 --- /dev/null +++ b/changes/bug_5177_fix_unread_signal_to_ui @@ -0,0 +1 @@ + o Fix unread notifications to client UI. Only INBOX is notified. Closes: #5177 diff --git a/src/leap/mail/imap/mailbox.py b/src/leap/mail/imap/mailbox.py index 9b1f4e5..d8e6cb1 100644 --- a/src/leap/mail/imap/mailbox.py +++ b/src/leap/mail/imap/mailbox.py @@ -371,15 +371,7 @@ class SoledadMailbox(WithMsgFields, MBoxParser): :rtype: int """ with self.next_uid_lock: - if self._memstore: - return self.last_uid + 1 - else: - # XXX after lock, it should be safe to - # return just the increment here, and - # have a different method that actually increments - # the counter when really adding. - self.last_uid += 1 - return self.last_uid + return self.last_uid + 1 def getMessageCount(self): """ @@ -474,11 +466,12 @@ class SoledadMailbox(WithMsgFields, MBoxParser): d = self._do_add_message(message, flags=flags, date=date) if PROFILE_CMD: do_profile_cmd(d, "APPEND") - # A better place for this would be the COPY/APPEND dispatcher # in server.py, but qtreactor hangs when I do that, so this seems # to work fine for now. d.addCallback(lambda r: self.reactor.callLater(0, self.notify_new)) + d.addCallback(self.cb_signal_unread_to_ui) + d.addErrback(lambda f: log.msg(f.getTraceback())) return d def _do_add_message(self, message, flags, date): @@ -613,6 +606,7 @@ class SoledadMailbox(WithMsgFields, MBoxParser): self.reactor.callInThread(self._do_fetch, messages_asked, uid, d) if PROFILE_CMD: do_profile_cmd(d, "FETCH") + d.addCallback(self.cb_signal_unread_to_ui) return d # called in thread @@ -768,14 +762,27 @@ class SoledadMailbox(WithMsgFields, MBoxParser): for msgid in seq_messg) return result - def signal_unread_to_ui(self, *args, **kwargs): + def cb_signal_unread_to_ui(self, result): """ Sends unread event to ui. + Used as a callback in several commands. + + :param result: ignored + """ + d = self._get_unseen_deferred() + d.addCallback(self.__cb_signal_unread_to_ui) + return result + + @deferred_to_thread + def _get_unseen_deferred(self): + return self.getUnseenCount() - :param args: ignored - :param kwargs: ignored + def __cb_signal_unread_to_ui(self, unseen): + """ + Send the unread signal to UI. + :param unseen: number of unseen messages. + :type unseen: int """ - unseen = self.getUnseenCount() leap_events.signal(IMAP_UNREAD_MAIL, str(unseen)) def store(self, messages_asked, flags, mode, uid): @@ -816,6 +823,8 @@ class SoledadMailbox(WithMsgFields, MBoxParser): mode, uid, d) if PROFILE_CMD: do_profile_cmd(d, "STORE") + d.addCallback(self.cb_signal_unread_to_ui) + d.addErrback(lambda f: log.msg(f.getTraceback())) return d def _do_store(self, messages_asked, flags, mode, uid, observer): -- cgit v1.2.3