diff options
Diffstat (limited to 'src/leap/mail/adaptors')
-rw-r--r-- | src/leap/mail/adaptors/soledad.py | 40 | ||||
-rw-r--r-- | src/leap/mail/adaptors/soledad_indexes.py | 4 |
2 files changed, 42 insertions, 2 deletions
diff --git a/src/leap/mail/adaptors/soledad.py b/src/leap/mail/adaptors/soledad.py index d21638c..74c34f9 100644 --- a/src/leap/mail/adaptors/soledad.py +++ b/src/leap/mail/adaptors/soledad.py @@ -930,6 +930,42 @@ class SoledadMailAdaptor(SoledadIndexMixin): d.addCallbacks(delete_fdoc_and_mdoc_flagged, err) return d + # count messages + + def get_count_unseen(self, store, mbox_uuid): + """ + Get the number of unseen messages for a given mailbox. + + :param store: instance of Soledad. + :param mbox_uuid: the uuid for this mailbox. + :rtype: int + """ + type_ = FlagsDocWrapper.model.type_ + uuid = mbox_uuid.replace('-', '_') + + unseen_index = indexes.TYPE_MBOX_SEEN_IDX + + d = store.get_count_from_index(unseen_index, type_, uuid, "0") + d.addErrback(self._errback) + return d + + def get_count_recent(self, store, mbox_uuid): + """ + Get the number of recent messages for a given mailbox. + + :param store: instance of Soledad. + :param mbox_uuid: the uuid for this mailbox. + :rtype: int + """ + type_ = FlagsDocWrapper.model.type_ + uuid = mbox_uuid.replace('-', '_') + + recent_index = indexes.TYPE_MBOX_RECENT_IDX + + d = store.get_count_from_index(recent_index, type_, uuid, "1") + d.addErrback(self._errback) + return d + # Mailbox handling def get_or_create_mbox(self, store, name): @@ -937,6 +973,7 @@ class SoledadMailAdaptor(SoledadIndexMixin): Get the mailbox with the given name, or create one if it does not exist. + :param store: instance of Soledad :param name: the name of the mailbox :type name: str """ @@ -970,6 +1007,9 @@ class SoledadMailAdaptor(SoledadIndexMixin): """ return MailboxWrapper.get_all(store) + def _errback(self, f): + f.printTraceback() + def _split_into_parts(raw): # TODO signal that we can delete the original message!----- diff --git a/src/leap/mail/adaptors/soledad_indexes.py b/src/leap/mail/adaptors/soledad_indexes.py index 856dfb4..d2f8b71 100644 --- a/src/leap/mail/adaptors/soledad_indexes.py +++ b/src/leap/mail/adaptors/soledad_indexes.py @@ -51,7 +51,7 @@ TYPE_MBOX_UUID_IDX = 'by-type-and-mbox-uuid' TYPE_SUBS_IDX = 'by-type-and-subscribed' TYPE_MSGID_IDX = 'by-type-and-message-id' TYPE_MBOX_SEEN_IDX = 'by-type-and-mbox-and-seen' -TYPE_MBOX_RECT_IDX = 'by-type-and-mbox-and-recent' +TYPE_MBOX_RECENT_IDX = 'by-type-and-mbox-and-recent' TYPE_MBOX_DEL_IDX = 'by-type-and-mbox-and-deleted' TYPE_MBOX_C_HASH_IDX = 'by-type-and-mbox-and-contenthash' TYPE_C_HASH_IDX = 'by-type-and-contenthash' @@ -97,7 +97,7 @@ MAIL_INDEXES = { # messages TYPE_MBOX_SEEN_IDX: [TYPE, MBOX_UUID, 'bool(seen)'], - TYPE_MBOX_RECT_IDX: [TYPE, MBOX_UUID, 'bool(recent)'], + TYPE_MBOX_RECENT_IDX: [TYPE, MBOX_UUID, 'bool(recent)'], TYPE_MBOX_DEL_IDX: [TYPE, MBOX_UUID, 'bool(deleted)'], # incoming queue |