summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKali Kaneko <kali@leap.se>2014-02-11 01:37:23 -0400
committerKali Kaneko <kali@leap.se>2014-02-17 11:39:48 -0400
commit50e87dd236965b8e3ae126e96333950019a2efd7 (patch)
treefd98dc1ddde34c0aea4e595051b719f15ac3f6fa
parent0af609c7141ac95386f72c4c3f67aea97cad2673 (diff)
do not get last_uid from the set of soledad messages
but always from the counter instead. once assigned, the uid must never be reused, unless the uidvalidity mailbox value changes. doing otherwise will cause messages not to be shown until next session. Also, renamed get_mbox method for clarity.
-rw-r--r--mail/src/leap/mail/imap/mailbox.py26
1 files changed, 12 insertions, 14 deletions
diff --git a/mail/src/leap/mail/imap/mailbox.py b/mail/src/leap/mail/imap/mailbox.py
index 122875b7..018f88ef 100644
--- a/mail/src/leap/mail/imap/mailbox.py
+++ b/mail/src/leap/mail/imap/mailbox.py
@@ -108,6 +108,7 @@ class SoledadMailbox(WithMsgFields, MBoxParser):
_listeners = defaultdict(set)
next_uid_lock = threading.Lock()
+ last_uid_lock = threading.Lock()
_fdoc_primed = {}
@@ -196,7 +197,7 @@ class SoledadMailbox(WithMsgFields, MBoxParser):
self.listeners.remove(listener)
# TODO move completely to soledadstore, under memstore reponsibility.
- def _get_mbox(self):
+ def _get_mbox_doc(self):
"""
Return mailbox document.
@@ -220,7 +221,7 @@ class SoledadMailbox(WithMsgFields, MBoxParser):
:returns: tuple of flags for this mailbox
:rtype: tuple of str
"""
- mbox = self._get_mbox()
+ mbox = self._get_mbox_doc()
if not mbox:
return None
flags = mbox.content.get(self.FLAGS_KEY, [])
@@ -235,7 +236,7 @@ class SoledadMailbox(WithMsgFields, MBoxParser):
"""
leap_assert(isinstance(flags, tuple),
"flags expected to be a tuple")
- mbox = self._get_mbox()
+ mbox = self._get_mbox_doc()
if not mbox:
return None
mbox.content[self.FLAGS_KEY] = map(str, flags)
@@ -250,7 +251,7 @@ class SoledadMailbox(WithMsgFields, MBoxParser):
:return: True if the mailbox is closed
:rtype: bool
"""
- mbox = self._get_mbox()
+ mbox = self._get_mbox_doc()
return mbox.content.get(self.CLOSED_KEY, False)
def _set_closed(self, closed):
@@ -261,7 +262,7 @@ class SoledadMailbox(WithMsgFields, MBoxParser):
:type closed: bool
"""
leap_assert(isinstance(closed, bool), "closed needs to be boolean")
- mbox = self._get_mbox()
+ mbox = self._get_mbox_doc()
mbox.content[self.CLOSED_KEY] = closed
self._soledad.put_doc(mbox)
@@ -290,8 +291,8 @@ class SoledadMailbox(WithMsgFields, MBoxParser):
"""
Prime memstore with last_uid value
"""
- set_exist = set(self.messages.all_uid_iter())
- last = max(set_exist) if set_exist else 0
+ mbox = self._get_mbox_doc()
+ last = mbox.content.get('lastuid', 0)
logger.info("Priming Soledad last_uid to %s" % (last,))
self._memstore.set_last_soledad_uid(self.mbox, last)
@@ -321,7 +322,7 @@ class SoledadMailbox(WithMsgFields, MBoxParser):
:return: unique validity identifier
:rtype: int
"""
- mbox = self._get_mbox()
+ mbox = self._get_mbox_doc()
return mbox.content.get(self.CREATED_KEY, 1)
def getUID(self, message):
@@ -483,12 +484,9 @@ class SoledadMailbox(WithMsgFields, MBoxParser):
exists = self.getMessageCount()
recent = self.getRecentCount()
logger.debug("NOTIFY (%r): there are %s messages, %s recent" % (
- self.mbox,
- exists,
- recent))
+ self.mbox, exists, recent))
for l in self.listeners:
- logger.debug('notifying...')
l.newMessages(exists, recent)
# commands, do not rename methods
@@ -507,7 +505,7 @@ class SoledadMailbox(WithMsgFields, MBoxParser):
# we should postpone the removal
# XXX move to memory store??
- self._soledad.delete_doc(self._get_mbox())
+ self._soledad.delete_doc(self._get_mbox_doc())
def _close_cb(self, result):
self.closed = True
@@ -756,7 +754,7 @@ class SoledadMailbox(WithMsgFields, MBoxParser):
:type observer: deferred
"""
# XXX implement also sequence (uid = 0)
- # XXX we should prevent cclient from setting Recent flag?
+ # XXX we should prevent client from setting Recent flag?
leap_assert(not isinstance(flags, basestring),
"flags cannot be a string")
flags = tuple(flags)