Subject: My C-client Search Fetches Extra Envs

From: Adam Treister <[email-masked]>
Date: Wed, 8 Sep 93 17:34:35 -0800

Mark, (or anyone with a good answer):

I'm having a pb: Mailstrom goes off to fetch all envelopes at places where it
shouldn't, eg: close mailbox or iconify window.  Whats happening is that the
client is doing a search (on close, it searches for deleted messages to decide
if it should ask if the user wants to expunge) and the search is requiring a run
thru the cache to check the searched flag.  Is there another way to know if
there were hits, without fetching extra envelopes, while still not mucking into
c-client's layer?

(Granted, much of the delay is that I'm dumping the envelopes in my debug window
and this slows things down alot, but in the case of big mailboxes, its important
to only fetch the minimum amount.)

Adam
-------------------

Here are Mailstrom's Search and GetElement routines:

short	Mailbox ::  Search(char *criteria)
{
	short	i, numFound;

	if (!stream) 	return(0);

	mail_search (stream, criteria);

	numFound = 0;
	for (i = 1; i <= NMSGS(stream); i ++)
	{
		MESSAGECACHE *element = GetElement(i);
		if (element->searched)
			numFound ++;
	}
	return(numFound);

}

/********************************************************/
MESSAGECACHE* Mailbox :: GetElement(long msgNo)
{
	BODY *body;
	ENVELOPE *env;
	MESSAGECACHE *element;
	
	ASSERT(msgNo != 0);
	if (msgNo AND stream)
	{
		env = mail_fetchstructure (stream,msgNo,&body);
		element = mail_elt(stream,msgNo);
		return(element);
	}
	else return NULL;
}

---

From: Mark Crispin <[email-masked]>
Date: Wed, 8 Sep 1993 21:07:06 -0700 (PDT)

Adam -

The newest version of the IMAP toolkit, just installed on the CAC ftp archive,
offers a c-client has the ability to turn off prefetch of envelopes when doing
an IMAP search when caching is enabled.

To use this facility, make sure you #include imap2.h as well as mail.h, and do
something like
  mail_parameters (mail_open (NIL,"{x/imap2}",OP_PROTOTYPE),SET_PREFETCH,NIL);
early in your program.  The mail_open() call returns the prototype stream that
you then feed to mail_parameters; you don't need to worry about calling
mail_close() on it.

Something like
  mail_parameters (mail_open (NIL,"{x/imap2}",OP_PROTOTYPE),SET_PREFETCH,
                   (void *) T);
will re-enable search prefetching of envelopes.

-- Mark --