summaryrefslogtreecommitdiff
path: root/mail
diff options
context:
space:
mode:
Diffstat (limited to 'mail')
-rw-r--r--mail/src/leap/mail/adaptors/soledad.py40
-rw-r--r--mail/src/leap/mail/adaptors/soledad_indexes.py4
-rw-r--r--mail/src/leap/mail/imap/mailbox.py5
-rw-r--r--mail/src/leap/mail/mail.py23
4 files changed, 60 insertions, 12 deletions
diff --git a/mail/src/leap/mail/adaptors/soledad.py b/mail/src/leap/mail/adaptors/soledad.py
index d21638cd..74c34f9e 100644
--- a/mail/src/leap/mail/adaptors/soledad.py
+++ b/mail/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/mail/src/leap/mail/adaptors/soledad_indexes.py b/mail/src/leap/mail/adaptors/soledad_indexes.py
index 856dfb44..d2f8b71a 100644
--- a/mail/src/leap/mail/adaptors/soledad_indexes.py
+++ b/mail/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
diff --git a/mail/src/leap/mail/imap/mailbox.py b/mail/src/leap/mail/imap/mailbox.py
index 045636e1..c826e86e 100644
--- a/mail/src/leap/mail/imap/mailbox.py
+++ b/mail/src/leap/mail/imap/mailbox.py
@@ -714,13 +714,10 @@ class IMAPMailbox(object):
:param result: ignored
"""
- d = self._get_unseen_deferred()
+ d = defer.maybeDeferred(self.getUnseenCount)
d.addCallback(self.__cb_signal_unread_to_ui)
return result
- def _get_unseen_deferred(self):
- return defer.maybeDeferred(self.getUnseenCount)
-
def __cb_signal_unread_to_ui(self, unseen):
"""
Send the unread signal to UI.
diff --git a/mail/src/leap/mail/mail.py b/mail/src/leap/mail/mail.py
index aa499c0c..d986f59f 100644
--- a/mail/src/leap/mail/mail.py
+++ b/mail/src/leap/mail/mail.py
@@ -295,6 +295,7 @@ class MessageCollection(object):
# server to accept deferreds.
# [ ] Use inheritance for the mailbox-collection instead of handling the
# special cases everywhere?
+ # [ ] or maybe a mailbox_only decorator...
# Account should provide an adaptor instance when creating this collection.
adaptor = None
@@ -419,14 +420,24 @@ class MessageCollection(object):
return d
def count_recent(self):
- # FIXME HACK
- # TODO ------------------------ implement this
- return 3
+ """
+ Count the recent messages in this collection.
+ :return: a Deferred that will fire with the integer for the count.
+ :rtype: Deferred
+ """
+ if not self.is_mailbox_collection():
+ raise NotImplementedError()
+ return self.adaptor.get_count_recent(self.store, self.mbox_uuid)
def count_unseen(self):
- # FIXME hack
- # TODO ------------------------ implement this
- return 3
+ """
+ Count the unseen messages in this collection.
+ :return: a Deferred that will fire with the integer for the count.
+ :rtype: Deferred
+ """
+ if not self.is_mailbox_collection():
+ raise NotImplementedError()
+ return self.adaptor.get_count_unseen(self.store, self.mbox_uuid)
def get_uid_next(self):
"""