cvs: php4 /ext/imap php_imap.c

From: Date: Thu, 19 Oct 2000 01:32:51 +0000
Subject: cvs: php4 /ext/imap php_imap.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-2124@lists.php.net to get a copy of this message
chagenbu Wed Oct 18 18:32:51 2000 EDT Modified files: /php4/ext/imap php_imap.c Log: add an optional parameter to imap_sort to specify a search program that messages must match to be included in the sorted list. Index: php4/ext/imap/php_imap.c diff -u php4/ext/imap/php_imap.c:1.47 php4/ext/imap/php_imap.c:1.48 --- php4/ext/imap/php_imap.c:1.47 Tue Oct 17 09:11:26 2000 +++ php4/ext/imap/php_imap.c Wed Oct 18 18:32:50 2000 @@ -25,7 +25,7 @@ | PHP 4.0 updates: Zeev Suraski <zeev@zend.com> | +----------------------------------------------------------------------+ */ -/* $Id: php_imap.c,v 1.47 2000/10/17 16:11:26 chagenbu Exp $ */ +/* $Id: php_imap.c,v 1.48 2000/10/19 01:32:50 chagenbu Exp $ */ #define IMAP41 @@ -2579,31 +2579,39 @@ /* }}} */ -/* {{{ proto array imap_sort(int stream_id, int criteria, int reverse [, int options]) - Sort an array of message headers */ +/* {{{ proto array imap_sort(int stream_id, int criteria, int reverse [, int options [, string search_criteria]]) + Sort an array of message headers, optionally including only messages that meet specified criteria. */ PHP_FUNCTION(imap_sort) { - zval **streamind, **pgm, **rev, **flags; + zval **streamind, **pgm, **rev, **flags, **criteria; int ind, ind_type; unsigned long *slst, *sl; + char *search_criteria; SORTPGM *mypgm=NIL; SEARCHPGM *spg=NIL; pils *imap_le_struct; - int myargc=ZEND_NUM_ARGS(); - - if (myargc < 3 || myargc > 4 || zend_get_parameters_ex(myargc, &streamind, &pgm, &rev, &flags) ==FAILURE) { + int myargc = ZEND_NUM_ARGS(); + + if (myargc < 3 || myargc > 5 || zend_get_parameters_ex(myargc, &streamind, &pgm, &rev, &flags, &criteria) ==FAILURE) { ZEND_WRONG_PARAM_COUNT(); } convert_to_long_ex(streamind); convert_to_long_ex(rev); convert_to_long_ex(pgm); - if (Z_LVAL_PP(pgm)>SORTSIZE) { + if (Z_LVAL_PP(pgm) > SORTSIZE) { php_error(E_WARNING, "Unrecognized sort criteria"); RETURN_FALSE; } - if (myargc==4) { + if (myargc >= 4) { convert_to_long_ex(flags); } + if (myargc == 5) { + search_criteria = estrndup(Z_STRVAL_PP(criteria), Z_STRLEN_PP(criteria)); + spg = mail_criteria(search_criteria); + efree(search_criteria); + } else { + spg = mail_newsearchpgm(); + } ind = Z_LVAL_PP(streamind); imap_le_struct = (pils *) zend_list_find(ind, &ind_type); @@ -2611,15 +2619,14 @@ php_error(E_WARNING, "Unable to find stream pointer"); RETURN_FALSE; } - spg = mail_newsearchpgm(); mypgm = mail_newsortpgm(); mypgm->reverse = Z_LVAL_PP(rev); mypgm->function = (short) Z_LVAL_PP(pgm); mypgm->next = NIL; - array_init(return_value); - slst = mail_sort(imap_le_struct->imap_stream, NIL, spg, mypgm, myargc==4 ? Z_LVAL_PP(flags) : NIL); + slst = mail_sort(imap_le_struct->imap_stream, NIL, spg, mypgm, myargc >= 4 ? Z_LVAL_PP(flags) : NIL); + array_init(return_value); for (sl = slst; *sl; sl++) { add_next_index_long(return_value, *sl); }

« previous php.cvs (#2124) next »