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.c66
1 files changed, 62 insertions, 4 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)
489int 489int
490mu_mailbox_messages_recent (mu_mailbox_t mbox, size_t *num) 490mu_mailbox_messages_recent (mu_mailbox_t mbox, size_t *num)
491{ 491{
492 _MBOX_CHECK_Q (mbox, _messages_recent); 492 size_t i, count, n;
493 return mbox->_messages_recent (mbox, num); 493 int rc;
494
495 _MBOX_CHECK_FLAGS (mbox);
496 if (mbox->flags & MU_STREAM_QACCESS)
497 return MU_ERR_BADOP;
498 if (mbox->_messages_recent)
499 return mbox->_messages_recent (mbox, num);
500
501 rc = mu_mailbox_messages_count (mbox, &count);
502 if (rc)
503 return rc;
504 n = 0;
505 for (i = 1; i < count; i++)
506 {
507 mu_message_t msg;
508 mu_attribute_t attr;
509
510 rc = mu_mailbox_get_message (mbox, i, &msg);
511 if (rc)
512 return rc;
513 rc = mu_message_get_attribute (msg, &attr);
514 if (rc)
515 return rc;
516 if (mu_attribute_is_recent (attr))
517 n++;
518 }
519 *num = n;
520 return 0;
494} 521}
495 522
496int 523int
497mu_mailbox_message_unseen (mu_mailbox_t mbox, size_t *num) 524mu_mailbox_message_unseen (mu_mailbox_t mbox, size_t *num)
498{ 525{
499 _MBOX_CHECK_Q (mbox, _message_unseen); 526 int rc;
500 return mbox->_message_unseen (mbox, num); 527 size_t i, count;
528
529 _MBOX_CHECK_FLAGS (mbox);
530 if (mbox->flags & MU_STREAM_QACCESS)
531 return MU_ERR_BADOP;
532 if (mbox->_message_unseen)
533 return mbox->_message_unseen (mbox, num);
534
535 rc = mu_mailbox_messages_count (mbox, &count);
536 if (rc)
537 return rc;
538 for (i = 1; i < count; i++)
539 {
540 mu_message_t msg;
541 mu_attribute_t attr;
542 int rc;
543
544 rc = mu_mailbox_get_message (mbox, i, &msg);
545 if (rc)
546 return rc;
547 rc = mu_message_get_attribute (msg, &attr);
548 if (rc)
549 return rc;
550 if (!mu_attribute_is_seen (attr))
551 {
552 *num = i;
553 return 0;
554 }
555 }
556
557 *num = 0;
558 return 0;
501} 559}
502 560
503int 561int

Return to:

Send suggestions and report system problems to the System administrator.