summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2019-02-26 10:39:34 +0200
committerSergey Poznyakoff <gray@gnu.org>2019-02-26 10:39:34 +0200
commitde26c87ab7df32066f5408012d0d391fcb9c9535 (patch)
tree4b8a2ecfa31e168bffdcd509fd1a8fea1d200ab9
parent4bdc41ff901015acf19bf6ebedcc3dd1fa02f74b (diff)
downloadmailutils-de26c87ab7df32066f5408012d0d391fcb9c9535.tar.gz
mailutils-de26c87ab7df32066f5408012d0d391fcb9c9535.tar.bz2
Provide fallback mechanism for mu_mailbox_messages_recent and mu_mailbox_message_unseen
* libmailutils/mailbox/mailbox.c (mu_mailbox_messages_recent) (mu_mailbox_message_unseen): Fall back to iteration if no backend-specific method is provided.
-rw-r--r--libmailutils/mailbox/mailbox.c62
1 files changed, 60 insertions, 2 deletions
diff --git a/libmailutils/mailbox/mailbox.c b/libmailutils/mailbox/mailbox.c
index cc248fa90..6065e418a 100644
--- a/libmailutils/mailbox/mailbox.c
+++ b/libmailutils/mailbox/mailbox.c
@@ -489,15 +489,73 @@ mu_mailbox_messages_count (mu_mailbox_t mbox, size_t *num)
int
mu_mailbox_messages_recent (mu_mailbox_t mbox, size_t *num)
{
- _MBOX_CHECK_Q (mbox, _messages_recent);
+ size_t i, count, n;
+ int rc;
+
+ _MBOX_CHECK_FLAGS (mbox);
+ if (mbox->flags & MU_STREAM_QACCESS)
+ return MU_ERR_BADOP;
+ if (mbox->_messages_recent)
return mbox->_messages_recent (mbox, num);
+
+ rc = mu_mailbox_messages_count (mbox, &count);
+ if (rc)
+ return rc;
+ n = 0;
+ for (i = 1; i < count; i++)
+ {
+ mu_message_t msg;
+ mu_attribute_t attr;
+
+ rc = mu_mailbox_get_message (mbox, i, &msg);
+ if (rc)
+ return rc;
+ rc = mu_message_get_attribute (msg, &attr);
+ if (rc)
+ return rc;
+ if (mu_attribute_is_recent (attr))
+ n++;
+ }
+ *num = n;
+ return 0;
}
int
mu_mailbox_message_unseen (mu_mailbox_t mbox, size_t *num)
{
- _MBOX_CHECK_Q (mbox, _message_unseen);
+ int rc;
+ size_t i, count;
+
+ _MBOX_CHECK_FLAGS (mbox);
+ if (mbox->flags & MU_STREAM_QACCESS)
+ return MU_ERR_BADOP;
+ if (mbox->_message_unseen)
return mbox->_message_unseen (mbox, num);
+
+ rc = mu_mailbox_messages_count (mbox, &count);
+ if (rc)
+ return rc;
+ for (i = 1; i < count; i++)
+ {
+ mu_message_t msg;
+ mu_attribute_t attr;
+ int rc;
+
+ rc = mu_mailbox_get_message (mbox, i, &msg);
+ if (rc)
+ return rc;
+ rc = mu_message_get_attribute (msg, &attr);
+ if (rc)
+ return rc;
+ if (!mu_attribute_is_seen (attr))
+ {
+ *num = i;
+ return 0;
+ }
+ }
+
+ *num = 0;
+ return 0;
}
int

Return to:

Send suggestions and report system problems to the System administrator.