[imp] Virtual INBOX and Trash weirdness

Darragh Bailey felix at compsoc.nuigalway.ie
Wed Jul 20 02:00:19 PDT 2005


Quoting Michael M Slusarz <slusarz at mail.curecanti.org>:

> Quoting Darragh Bailey <felix at compsoc.nuigalway.ie>:
> >
> > Spotted this sometime ago on a website I help maintain and keep
> > meaning to look
> > at adding some code to solve it. One of the suggestions that I came
> > up with was
> > to use a combination of 2 functions and the session
> >
> > use function
> > object imap_status ( resource imap_stream, string mailbox, int options)
> >
> > to retreive the unread messages, but will also return unread deleted
> > messages.
> >
> > Store this number in the session as the total unread messages.
> >
> > use function
> > array imap_search ( resource imap_stream, string criteria [, int options
> [,
> > string charset]])
> > In which you can specify "UNREAD UNDELETED"
> >
> > store the size of the array as the unread messages.
> >
> > Then you need only call the imap_search function in the future if the
> total
> > unread messages stored in the session and the number returned by
> imap_status
> > differ.
> >
> >
> > No idea though just how expensive it is to call imap_search, nor in
> > general how
> > often it would get called.
>
> imap_search() have to be called for *every* polled folder *every* time
> either the folder screen is displayed or the sidebar is refreshed.  and
> imap_search() is a much more intense resource hog than imap_status().
>
> michael

Reading my comments and then yours, I'm not certain how you came up with the
idea that it would be necessary to use imap_search on all folders every time
there is a refresh.


I was aware of the expense of calling imap_search, I stated that I didn't know
how expensive it was, but that in the solution I was looking to avoid calling it
each time on all folders.


How, by storing information in the session on the true number of unread messages
(from imap_search), and the number that imap_status would return. Meaning that
for each folder you would only need to call imap_search if a call to imap_status
returned a number different than what was stored in the session from the
previous call to imap_status.

Since you have to call imap_status for each folder anyway currently to get the
number of unread messages, depending on how you store the information in the
session you should be able to only have to call imap_search on the folders where
the numbers differ. This avoids calling it on "*every* polled folder *every*
time"


As I said, I don't know in practice how often imap_search would actually get
called or what load it is likely to result in. But the idea should avoid having
to call to it every time except in the most extreme cases where the mailbox is
continuously getting new mail.


There is a difference between what I actually said and what it appears to be
suggested that I said in your comments. I wasn't advocating using imap_search
*every* time, but it could be used to get the accurate number, and use of
imap_status to reduce the number of times you need to call it to be certain of
the validity of the count.


--
Darragh

"Nothing's foolproof to a sufficently talented fool"


More information about the imp mailing list