diff options
author | Kali Kaneko <kali@leap.se> | 2015-01-12 20:47:29 -0400 |
---|---|---|
committer | Kali Kaneko <kali@leap.se> | 2015-02-11 14:05:43 -0400 |
commit | f7030295a936cc5da33f50411b5ff60ae0eec7cc (patch) | |
tree | 43bc7699b79185729ac62860374ee43a19f917d9 /src/leap/mail/adaptors/soledad.py | |
parent | 9e2cf40db51889ec43cd4e27b55c7f14e0436c01 (diff) |
Use mailbox uuids
The previous implementation is naive, since it imposes a burden when
renaming mailboxes. We're using uuids in the local uid tables instead,
which is more cryptic but way more efficient.
* receive mbox uuid instead of name
* use mailbox uuid in identifiers
Diffstat (limited to 'src/leap/mail/adaptors/soledad.py')
-rw-r--r-- | src/leap/mail/adaptors/soledad.py | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/src/leap/mail/adaptors/soledad.py b/src/leap/mail/adaptors/soledad.py index 389307f..c5cfce0 100644 --- a/src/leap/mail/adaptors/soledad.py +++ b/src/leap/mail/adaptors/soledad.py @@ -338,7 +338,7 @@ class FlagsDocWrapper(SoledadDocumentWrapper): type_ = "flags" chash = "" - mbox = "inbox" + mbox_uuid = "" seen = False deleted = False recent = False @@ -350,11 +350,12 @@ class FlagsDocWrapper(SoledadDocumentWrapper): class __meta__(object): index = "mbox" - def set_mbox(self, mbox): + def set_mbox_uuid(self, mbox_uuid): # XXX raise error if already created, should use copy instead - new_id = constants.FDOCID.format(mbox=mbox, chash=self.chash) + mbox_uuid = mbox_uuid.replace('-', '_') + new_id = constants.FDOCID.format(mbox_uuid=mbox_uuid, chash=self.chash) self._future_doc_id = new_id - self.mbox = mbox + self.mbox_uuid = mbox_uuid class HeaderDocWrapper(SoledadDocumentWrapper): @@ -401,11 +402,12 @@ class MetaMsgDocWrapper(SoledadDocumentWrapper): hdoc = "" cdocs = [] - def set_mbox(self, mbox): + def set_mbox_uuid(self, mbox_uuid): # XXX raise error if already created, should use copy instead + mbox_uuid = mbox_uuid.replace('-', '_') chash = re.findall(constants.FDOCID_CHASH_RE, self.fdoc)[0] - new_id = constants.METAMSGID.format(mbox=mbox, chash=chash) - new_fdoc_id = constants.FDOCID.format(mbox=mbox, chash=chash) + new_id = constants.METAMSGID.format(mbox_uuid=mbox_uuid, chash=chash) + new_fdoc_id = constants.FDOCID.format(mbox_uuid=mbox_uuid, chash=chash) self._future_doc_id = new_id self.fdoc = new_fdoc_id @@ -518,14 +520,15 @@ class MessageWrapper(object): # 4. return new wrapper (new meta too!) raise NotImplementedError() - def set_mbox(self, mbox): + def set_mbox_uuid(self, mbox_uuid): """ Set the mailbox for this wrapper. This method should only be used before the Documents for the MessageWrapper have been created, will raise otherwise. """ - self.mdoc.set_mbox(mbox) - self.fdoc.set_mbox(mbox) + mbox_uuid = mbox.uuid.replace('-', '_') + self.mdoc.set_mbox_uuid(mbox_uuid) + self.fdoc.set_mbox_uuid(mbox_uuid) def set_flags(self, flags): # TODO serialize the get + update @@ -574,6 +577,7 @@ class MailboxWrapper(SoledadDocumentWrapper): class model(models.SerializableModel): type_ = "mbox" mbox = INBOX_NAME + uuid = None flags = [] recent = [] created = 1 @@ -889,7 +893,10 @@ def _parse_msg(raw): def _build_meta_doc(chash, cdocs_phashes): _mdoc = MetaMsgDocWrapper() - _mdoc.fdoc = constants.FDOCID.format(mbox=INBOX_NAME, chash=chash) + # FIXME passing the inbox name because we don't have the uuid at this + # point. + + _mdoc.fdoc = constants.FDOCID.format(mbox_uuid=INBOX_NAME, chash=chash) _mdoc.hdoc = constants.HDOCID.format(chash=chash) _mdoc.cdocs = [constants.CDOCID.format(phash=p) for p in cdocs_phashes] return _mdoc.serialize() |