ID:               21168
 Updated by:       [EMAIL PROTECTED]
-Summary:          imap_search() does not support the OR keyword
 Reported By:      slusarz at colorado dot edu
 Status:           Open
-Bug Type:         IMAP related
+Bug Type:         Feature/Change Request
 Operating System: unknown
 PHP Version:      4.3.3-dev, 5.0.0-dev
 New Comment:

reclassified (not bug, a feature request)



Previous Comments:
------------------------------------------------------------------------

[2003-06-16 17:34:38] [EMAIL PROTECTED]

The troble is that extending imap_search to support the OR keyword
(using the current c-client) would require ugly lexing of the search
parameter and is outside the scope of what PHP should be doing to
interface to the imap library.

That said, it doesn't seem unreasonable to introduce a completely
separate interface which allows the user to generate their own search
programs.  Something like:

$ret = imap_search_ex($stream,
imap_search_or(imap_search_criteria("From =
'[EMAIL PROTECTED]'"),imap_search_and(imap_search_criteria("From =
'[EMAIL PROTECTED]'"),imap_search_criteria("To = '[EMAIL PROTECTED]'"))));

which would be the equivalent of:

>From = '[EMAIL PROTECTED]' OR (From = '[EMAIL PROTECTED]' AND To =
'[EMAIL PROTECTED]')

This is not a minor addition either, but is more within PHP's scope...

------------------------------------------------------------------------

[2003-06-16 17:18:36] [EMAIL PROTECTED]

Yes, it is a PHP problem. c-client has provided the necessary
interfaces for a long time. Excuse the large documentation dump, but:

                           Mailbox Searching

void mail_search (MAILSTREAM *stream,char *criteria);
void mail_search_full (MAILSTREAM *stream,char *charset,SEARCHPGM
*pgm,
                       long flags);
        stream  stream to search
        charset MIME character set to use when searching strings
        pgm     search program
        flags   option flags

     This function causes a mailbox search, using the given MIME
charset (NIL means the default, US-ASCII) and the given search
program.
A search program is a structure that holds the following data:

SEARCHSET *msgno;       a set of message sequence numbers
SEARCHSET *uid;         a set of unique identifiers
SEARCHOR *or;           OR result of two search programs
SEARCHPGMLIST *not;     AND result of list of NOT'ed search programs
SEARCHHEADER *header;   message headers
STRINGLIST *bcc;        string(s) appear in bcc list
STRINGLIST *body;       string(s) appear in message body text
STRINGLIST *cc;         string(s) appear in cc list
STRINGLIST *from;       string(s) appear in from
STRINGLIST *keyword;    user flag string(s) set
STRINGLIST *unkeyword;  user flag strings() not set
STRINGLIST *subject;    string(s) appear in subject
STRINGLIST *text;       string(s) appear in message header or body
STRINGLIST *to;         string(s) appear in to list
unsigned long larger;   larger than this many octets
unsigned long smaller;  smaller than this many octes
        The following dates are in form:
                ((year - BASEYEAR) << 9) + (month << 5) + day
unsigned short sentbefore;
                        sent before this date
unsigned short senton;  sent on this date
unsigned short sentsince;
                        sent since this date
unsigned short before;  received before this date
unsigned short on;      received on this date
unsigned short since;   received since this date
unsigned int answered : 1;
                        message answered
unsigned int unanswered : 1;
                        message not answered
unsigned int deleted : 1;
                        message deleted
unsigned int undeleted : 1;
                        message not deleted
unsigned int draft : 1; message is a draft
unsigned int undraft : 1;
                        message is not a draft
unsigned int flagged : 1;
                        message flagged as urgent
unsigned int unflagged : 1;
                        message not flagged as urgent
unsigned int recent : 1;
                        message recent since last parse of mailbox
unsigned int old : 1;   message not recent since last parse of mailbox
unsigned int seen : 1;  message read
unsigned int unseen : 1;
                        message not read

     The following auxillary structures are used by search programs:
        SEARCHHEADER:   header line searching
char *line;             header line field name
char *text;             text header line
SEARCHHEADER *next;     next SEARCHHEADER in list (AND'ed)

        SEARCHSET:      message number set
unsigned long first;    first number in set
unsigned long last;     if non-zero, last number in set
SEARCHSET *next;        next SEARCHSET in list (AND'ed)

        SEARCHOR:       two search programs, OR'ed together
SEARCHPGM *first;       first program
SEARCHPGM *second;      second program
SEARCHOR *next;         next SEARCHOR in list

        SEARCHPGMLIST:  list of search programs
SEARCHPGM *pgm;         search program (AND'd with others in list)
SEARCHPGMLIST *next;    next SEARCHPGM in list

     mail_search(), the older interface, accepts a search criteria
argument as a character string in IMAP2 (RFC-1176) format.  Do not try
to use any IMAP4 search criteria with this interface.

So, we just need to use the right calls. It's a pain that c-client
doesn't let you just pass in the right search string, though.

------------------------------------------------------------------------

[2003-06-16 16:46:45] slusarz at colorado dot edu

The workaround we developed, using PHP code, can be found at:
http://cvs.horde.org/cvs.php/horde/lib/IMAP/Search.php

------------------------------------------------------------------------

[2003-06-16 16:35:15] [EMAIL PROTECTED]

This is really not a php problem to solve, PHP uses mail_criteria(), an
imap function used to determine the nature of the search.
Unfortunately, this function only supports IMAP2 functionality and does
not support IMAP4 directives, which is what prevents you from using OR
keyword.
Until the author of c-client decided to introduce mail_criteria()
equivalent that supports IMAP4 don't expect to see OR keyword support
in PHP.

------------------------------------------------------------------------

[2002-12-23 19:00:02] slusarz at colorado dot edu

I sent this to Dan in August and haven't seen anything done about it
yet, so I will put it here.  Note that the c-client DOES support the OR
keyword (see the MARC article listed below) - it appears that PHP is
not configuring the search correctly to use the keyword though.

-----

Quoting Dan Kalowsky <[EMAIL PROTECTED]>:

| Hi there,
| 
| Jon Pairse has given me your email regarding a commit you did on the
IMP
| project for HORDE.  Not being very familiar with IMP, any chance you
can
| give me a sample piece of PHP code for what doesn't work with the
| imap_search() function in PHP?
| 
| I'll see if I can get that fixed for 4.3.0

For imap_search() code, go to:
http://cvs.horde.org/co.php/imp/lib/Filter.php?login=2&r=1.20

The code is in the _matchFilter() method.  It generates a search query
that 
looks like the following:

UNDELETED OR FIELD1 "FOOBAR1" OR FIELD2 "FOOBAR2" FIELD3 "FOOBAR3"

Running this query directly on my imap installation (courier-imap 1.5),
it 
correctly does an OR search on FIELD1, FIELD2, FIELD3.  This search
returns 
no results in PHP on the same mailbox.

My lame attempt to figure out the problem can be found here:
http://marc.theaimsgroup.com/?l=imp&m=102832554619977&w=2

-----

------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=21168&edit=1

Reply via email to