Subject: Unseen count on a selected mailbox

From: Mark Elvers <[email-masked]>
Date: Thu, 26 Sep 2002 17:40:24 +0100 (BST)

Hi, In my application using c-client 2002.RC5, I call mail_open() with the
OP_HALFOPEN flag then call mail_status() to get the unseen message count
which I store.  Then I open the mailbox fully.  I invalidate my stored
unseen variable if mm_exists(), or mm_flags() occurs.  If at some time
later I need to query the unseen count and my stored variable is invalid I
call mail_status() again, but I see the following via the mm_log()
callback:

mm_log(): CLIENT BUG DETECTED: STATUS on selected mailbox: faxes

It does work and returns the new unseen value.  I could search the mailbox
for unseen messages but that seems a lot of work to get the unseen count!

Any suggestions?

Thanks

Mark

-- 
------------------------------------------------------------------
 For information about this mailing list, and its archives, see: 
 http://www.washington.edu/imap/c-client-list.html
------------------------------------------------------------------

---

From: Mark Crispin <[email-masked]>
Date: Thu, 26 Sep 2002 09:51:12 -0700 (PDT)

On Thu, 26 Sep 2002 17:40:24 +0100 (BST), Mark Elvers wrote:
> I could search the mailbox

The simple answer is:

It seems like a lot work to search the mailbox for unseen messages to get the
unseen count, but that is *much* less work than mail_status().

As long as you make sure that the elts have valid (elt->valid) status, you can
look at the flags directly with something like:
  for (unseen = 0, msgno = 1; msgno <= stream->msgno; ++msgno)
    if (!mail_elt (stream,msgno)->seen) ++unseen;

You can make sure that the elts have valid status with mail_fetch_flags() or
mail_fetch_fast(), which only need to be called once in a session for any
message.  You don't have to worry about valid status issues at all unless you
are using IMAP.