bhayden | 18 May 20:31

Using spg (search) in mail_sort

Background: working on mods to Cambridge's Prayer webmail, which uses 
c-client.

Current issue: mail_sort works as expected, consistently, with one 
exception. Any search program (spg) passed to it seems to be completely 
ignored. I've tried many different approaches for the last 48 hours and 
nothing has worked, so I'm curious if there are known issues with this. If 
not, I'll be happy to provide any further detail (code and debugging info).

Basic relevant snip:

    search_pgm = mail_newsearchpgm();   /* Basic search program */
    search_pgm->undeleted = T;
    sort_pgm = mail_newsortpgm();
    stream->dtb->sort = &mail_sort_msgs;
    sort_pgm->function = SORTARRIVAL;
    if (!
        (tmp =
         mail_sort(stream, NIL, search_pgm, sort_pgm, (SO_FREE | SE_FREE))))
    {
           return (NIL);
    }

I also tried, among other things, making an explicit assignment:

   stream->dtb->sort = &mail_sort_msgs;

in order to make sure that mail_sort_msgs, with its call to 
mail_search_full, was being used. It was, and still no difference. It 
appears that the search program is being invoked, but matches all messages 
(Continue reading)

Mark Crispin | 18 May 22:26

Re: Using spg (search) in mail_sort

On Sun, 18 May 2008, bhayden <at> umn.edu wrote:
> Current issue: mail_sort works as expected, consistently, with one exception. 
> Any search program (spg) passed to it seems to be completely ignored. I've 
> tried many different approaches for the last 48 hours and nothing has worked, 
> so I'm curious if there are known issues with this.

I sympathize with your frustration.  Nonetheless, the searching capability 
of mail_sort() works.  The problem is either in your program or possibly 
in your IMAP server.

Here is how you can prove that mail_sort() works.  UW imapd calls 
mail_sort() to implement sorting.  You can see what it does to call 
mail_sort(), starting at approximately line 700 in imapd.c.

Given that imapd calls mail_sort(), here is how you can test it with an 
arrival sort for undeleted messages.  Run imapd from the shell, and type 
the commands in manually.  The following what happened when I did it at 
home:

 	1 select inbox
 	* 22 EXISTS
 	* 0 RECENT
 	* OK [UIDVALIDITY 1204587420] UID validity status
 	* OK [UIDNEXT 67] Predicted next UID
 	* FLAGS (Note Flames Request $NotJunk $Junk $Forwarded \Answered \Flagged \Deleted \Draft \Seen)
 	* OK [PERMANENTFLAGS (Note Flames Request $NotJunk $Junk $Forwarded \* \Answered \Flagged \Deleted
\Draft \Seen)] Permanent flags
 	1 OK [READ-WRITE] SELECT completed
 	2 sort (arrival) utf-8 deleted
 	* SORT
(Continue reading)

bhayden | 19 May 00:31

Re: Using spg (search) in mail_sort

On May 18 2008, Mark Crispin wrote:

>On Sun, 18 May 2008, bhayden <at> umn.edu wrote:
>> Current issue: mail_sort works as expected, consistently, with one 
>> exception. Any search program (spg) passed to it seems to be completely 
>> ignored. I've tried many different approaches for the last 48 hours and 
>> nothing has worked, so I'm curious if there are known issues with this.
>
>I sympathize with your frustration.  Nonetheless, the searching capability 
>of mail_sort() works.  The problem is either in your program or possibly 
>in your IMAP server.

It is indeed in the local program. Thank you for your test suggestions, 
they were helpful (particularly the mtest example.

>>   stream->dtb->sort = &mail_sort_msgs;
>
>Do not do this, nor any other modifications to DTBs or other c-client 
>internals.  At best, doing so is harmless.  Far more likely, this kind of 
>skullduggery will create bizarre problems that nobody will have a hope of 
>finding.

Duly noted. I make a habit of respecting the "internal use only" warning in 
the c-client docs. I only tried in this instant to confirm for my own 
curiosity...

-Brian
_______________________________________________
Imap-uw mailing list
Imap-uw <at> u.washington.edu
(Continue reading)

bhayden | 19 May 18:00

Re: Using spg (search) in mail_sort

On May 18 2008, Mark Crispin wrote:

>On Sun, 18 May 2008, bhayden <at> umn.edu wrote:
>> Current issue: mail_sort works as expected, consistently, with one 
>> exception. Any search program (spg) passed to it seems to be completely 
>> ignored. I've tried many different approaches for the last 48 hours and 
>> nothing has worked, so I'm curious if there are known issues with this.
>
>I sympathize with your frustration.  Nonetheless, the searching capability 
>of mail_sort() works.  The problem is either in your program or possibly 
>in your IMAP server.

Follow-on question: When mail_sort or mail_thread is called with a search 
program that may narrow the number of messages, is there a way to tell "at 
a glance" from the returns of those calls how many messages met the search 
criteria?

>From what I can tell it seems to be down to the app to walk the results and 
make a count. Currently (naming the unsigned long * return of mail_sort 
"sort_result" for this example), I'm using this:

        for (i = 0; sort_result[i] > 0; i++)

as for all messages that did not match the search_pgm, there is a zero 
entry at the end of the sorted array. Is this bad and wrong, or is there a 
better way to do this?

-Brian
_______________________________________________
Imap-uw mailing list
(Continue reading)

Mark Crispin | 19 May 18:35

Re: Using spg (search) in mail_sort

On Mon, 19 May 2008, bhayden <at> umn.edu wrote:
> From what I can tell it seems to be down to the app to walk the results and 
> make a count.

That's one way.  What is returned is a 0-terminated array.

>       for (i = 0; sort_result[i] > 0; i++)

Note that message numbers are unsigned, so test for non-zero, not 
greater than zero.
       for (i = 0; sort_result[i]; i++)

There are two other ways to get the number of sorted messages.

If you arm a sortresults_t callback, the number of messages sorted is 
returned as the third argument to the callback.

Last, and certainly least, the number of sorted messages is returned in 
the nmsgs member of the sortpgm (assuming that you don't use SO_FREE).  I 
won't count upon that however; it's intended to use against the progress 
member and not to size the return array.

So, either use the callback or count the members of the array.

-- Mark --

http://panda.com/mrc
Democracy is two wolves and a sheep deciding what to eat for lunch.
Liberty is a well-armed sheep contesting the vote.
_______________________________________________
(Continue reading)


Gmane