diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2019-02-26 10:39:34 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2019-02-26 10:39:34 +0200 |
commit | de26c87ab7df32066f5408012d0d391fcb9c9535 (patch) | |
tree | 4b8a2ecfa31e168bffdcd509fd1a8fea1d200ab9 | |
parent | 4bdc41ff901015acf19bf6ebedcc3dd1fa02f74b (diff) | |
download | mailutils-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.c | 66 |
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) | |||
489 | int | 489 | int |
490 | mu_mailbox_messages_recent (mu_mailbox_t mbox, size_t *num) | 490 | mu_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 | ||
496 | int | 523 | int |
497 | mu_mailbox_message_unseen (mu_mailbox_t mbox, size_t *num) | 524 | mu_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 | ||
503 | int | 561 | int |