Here's the patch inline:
diff -u --recursive ../orig/php-5.2.12/ext/imap/php_imap.c ./ext/imap/php_imap.c
--- ../orig/php-5.2.12/ext/imap/php_imap.c 2009-09-22 14:18:57.0
-0400
+++ ./ext/imap/php_imap.c 2010-02-03 14:16:41.0 -0500
@@ -152,6 +152,9 @@
PHP_FE(imap_timeout,
NULL)
#if defined(HAVE_IMAP2000) || defined(HAVE_IMAP2001)
+ PHP_FE(imap_searchprogram_new,
NULL)
+ PHP_FE(imap_searchprogram_or,
NULL)
+ PHP_FE(imap_searchprogram_setcriterion,
NULL)
PHP_FE(imap_get_quota,
NULL)
PHP_FE(imap_get_quotaroot,
NULL)
PHP_FE(imap_set_quota,
NULL)
@@ -209,6 +212,7 @@
/* True globals, no need for thread safety */
static int le_imap;
+static int le_imap_searchpgm;
#define PHP_IMAP_CHECK_MSGNO(msgindex) \
if ((msgindex 1) || ((unsigned) msgindex
imap_le_struct-imap_stream-nmsgs)) { \
@@ -673,6 +677,7 @@
*/
le_imap = zend_register_list_destructors_ex(mail_close_it, NULL,
imap, module_number);
+ le_imap_searchpgm = zend_register_list_destructors_ex(NULL, NULL,
imapsearchpgm, module_number);
return SUCCESS;
}
/* }}} */
@@ -3693,7 +3698,9 @@
char *search_criteria;
MESSAGELIST *cur;
int argc = ZEND_NUM_ARGS();
+ int criteria_is_string;
SEARCHPGM *pgm = NIL;
+ pisearchpgms *php_searchpgm;
if (argc 2 || argc 4 || zend_get_parameters_ex(argc, streamind,
criteria, search_flags, charset) == FAILURE) {
ZEND_WRONG_PARAM_COUNT();
@@ -3701,8 +3708,25 @@
ZEND_FETCH_RESOURCE(imap_le_struct, pils *, streamind, -1, imap,
le_imap);
- convert_to_string_ex(criteria);
- search_criteria = estrndup(Z_STRVAL_PP(criteria),
Z_STRLEN_PP(criteria));
+ switch (Z_TYPE_PP(criteria)) {
+ case IS_STRING:
+ convert_to_string_ex(criteria);
+ search_criteria = estrndup(Z_STRVAL_PP(criteria),
Z_STRLEN_PP(criteria));
+ pgm = mail_criteria(search_criteria);
+ criteria_is_string=1;
+ break;
+
+ case IS_RESOURCE:
+ ZEND_FETCH_RESOURCE(php_searchpgm, pisearchpgms *,
criteria, -1, imapsearchpgm, le_imap_searchpgm);
+ pgm = php_searchpgm-searchpgm;
+ criteria_is_string=0;
+ break;
+
+ default:
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, Second
argumented is expected to be either a string or a searchprogram resource, %s
given, zend_zval_type_name(*criteria));
+RETURN_FALSE;
+ }
+
if (argc == 2) {
flags = SE_FREE;
@@ -3714,17 +3738,18 @@
}
}
- pgm = mail_criteria(search_criteria);
IMAPG(imap_messages) = IMAPG(imap_messages_tail) = NIL;
mail_search_full(imap_le_struct-imap_stream, (argc == 4 ?
Z_STRVAL_PP(charset) : NIL), pgm, flags);
- if (pgm !(flags SE_FREE)) {
+ if (pgm criteria_is_string !(flags SE_FREE)) {
mail_free_searchpgm(pgm);
}
if (IMAPG(imap_messages) == NIL) {
- efree(search_criteria);
+ if (criteria_is_string) {
+ efree(search_criteria);
+ }
RETURN_FALSE;
}
@@ -3736,7 +3761,9 @@
cur = cur-next;
}
mail_free_messagelist(IMAPG(imap_messages),
IMAPG(imap_messages_tail));
- efree(search_criteria);
+ if (criteria_is_string) {
+ efree(search_criteria);
+ }
}
/* }}} */
@@ -4425,6 +4452,148 @@
}
/* }}} */
+/* {{{ proto mixed imap_search_program_new()
+ Get new search program */
+PHP_FUNCTION(imap_searchprogram_new)
+{
+ pisearchpgms *php_searchpgm;
+
+ if (ZEND_NUM_ARGS() != 0) {
+ ZEND_WRONG_PARAM_COUNT();
+ }
+
+ php_searchpgm = emalloc(sizeof(pisearchpgms));
+ php_searchpgm-searchpgm = mail_newsearchpgm();
+ ZEND_REGISTER_RESOURCE(return_value, php_searchpgm, le_imap_searchpgm);
+}
+/* }}} */
+
+PHP_FUNCTION(imap_searchprogram_or)
+{
+ zval **zpgm1, **zpgm2;
+ pisearchpgms *php_searchpgm_or;
+ pisearchpgms *php_searchpgm_1;
+ pisearchpgms *php_searchpgm_2;
+
+ if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, zpgm1, zpgm2)
== FAILURE) {
+ ZEND_WRONG_PARAM_COUNT();
+ }
+
+ ZEND_FETCH_RESOURCE(php_searchpgm_1, pisearchpgms *,