From 81f9513ea4bef7828aed71afeb018a79bc3f1480 Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Fri, 20 Dec 2013 13:41:34 -0400 Subject: use soledad_writer for puts also --- mail/src/leap/mail/imap/server.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/mail/src/leap/mail/imap/server.py b/mail/src/leap/mail/imap/server.py index c79cf85..f77bf2c 100644 --- a/mail/src/leap/mail/imap/server.py +++ b/mail/src/leap/mail/imap/server.py @@ -755,7 +755,7 @@ class LeapMessage(WithMsgFields): logger.error("Unicode error {0}".format(e)) content = content.encode(charset, 'replace') fd.write(content) - # SHOULD use a separate BODY FIELD ... + # XXX SHOULD use a separate BODY FIELD ... fd.seek(0) return fd @@ -856,7 +856,12 @@ class SoledadDocWriter(object): empty = queue.empty() while not empty: item = queue.get() - self._soledad.create_doc(item) + payload = item['payload'] + mode = item['mode'] + if mode == "create": + self._soledad.create_doc(payload) + elif mode == "put": + self._soledad.put_doc(payload) empty = queue.empty() @@ -925,7 +930,7 @@ class MessageCollection(WithMsgFields, IndexedDB): # to be processed serially by the consumer (the writer). We just # need to `put` the new material on its plate. - self._soledad_writer = MessageProducer( + self.soledad_writer = MessageProducer( SoledadDocWriter(soledad), period=0.1) @@ -1003,7 +1008,10 @@ class MessageCollection(WithMsgFields, IndexedDB): content[self.UID_KEY] = uid logger.debug('enqueuing message for write') - self._soledad_writer.put(content) + + # XXX create namedtuple + self.soledad_writer.put({"mode": "create", + "payload": content}) # XXX have to decide what shall we do with errors with this change... #return self._soledad.create_doc(content) @@ -1650,7 +1658,7 @@ class SoledadMailbox(WithMsgFields): print "fetch %s, no msg found!!!" % msg_id if self.isWriteable(): - deferToThread(self._unset_recent_flag) + self._unset_recent_flag() return tuple(result) @@ -1761,8 +1769,9 @@ class SoledadMailbox(WithMsgFields): """ Updates document in u1db database """ - #log.msg('updating doc... %s ' % doc) - self._soledad.put_doc(doc) + # XXX create namedtuple + self.messages.soledad_writer.put({"mode": "put", + "payload": doc}) def __repr__(self): """ -- cgit v1.2.3 From 90b3bdd9b7cee630defdba57eb178c881e3b1984 Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Fri, 20 Dec 2013 16:36:21 -0400 Subject: safety catch against wrong last_uid --- mail/src/leap/mail/imap/server.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/mail/src/leap/mail/imap/server.py b/mail/src/leap/mail/imap/server.py index f77bf2c..d92ab9d 100644 --- a/mail/src/leap/mail/imap/server.py +++ b/mail/src/leap/mail/imap/server.py @@ -1430,7 +1430,22 @@ class SoledadMailbox(WithMsgFields): leap_assert(isinstance(uid, int), "uid has to be int") mbox = self._get_mbox() key = self.LAST_UID_KEY - mbox.content[key] = uid + + count = mbox.getMessageCount() + + # XXX safety-catch. If we do get duplicates, + # we want to avoid further duplication. + + if uid >= count: + value = uid + else: + # something is wrong, + # just set the last uid + # beyond the max msg count. + logger.debug("WRONG uid < count. Setting last uid to ", count) + value = count + + mbox.content[key] = value self._soledad.put_doc(mbox) last_uid = property( -- cgit v1.2.3 From 963b35ce4bf30319f0019d624190be10af03392c Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Fri, 20 Dec 2013 16:38:58 -0400 Subject: fix changes files --- mail/changes/bug_defer-unset-recent | 2 -- mail/changes/bug_enqueue-unset-recent | 2 ++ mail/changes/bug_safety-check-for-last-uid | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) delete mode 100644 mail/changes/bug_defer-unset-recent create mode 100644 mail/changes/bug_enqueue-unset-recent create mode 100644 mail/changes/bug_safety-check-for-last-uid diff --git a/mail/changes/bug_defer-unset-recent b/mail/changes/bug_defer-unset-recent deleted file mode 100644 index e651d11..0000000 --- a/mail/changes/bug_defer-unset-recent +++ /dev/null @@ -1,2 +0,0 @@ - o deferToThread unsetting of recent flag. this was holding the new - mails from being displayed soonish. diff --git a/mail/changes/bug_enqueue-unset-recent b/mail/changes/bug_enqueue-unset-recent new file mode 100644 index 0000000..8903804 --- /dev/null +++ b/mail/changes/bug_enqueue-unset-recent @@ -0,0 +1,2 @@ + o Enqueue unsetting of recent flag. this was holding the new + mails from being displayed soonish. diff --git a/mail/changes/bug_safety-check-for-last-uid b/mail/changes/bug_safety-check-for-last-uid new file mode 100644 index 0000000..bb0229f --- /dev/null +++ b/mail/changes/bug_safety-check-for-last-uid @@ -0,0 +1 @@ + o Sanity check on last_uid setter. Avoids incomplete fetches. -- cgit v1.2.3