Re: [PHP-DEV] imap4 search criteria

2010-02-04 Thread Dominik Gehl
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 *, 

[PHP-DEV] http://bugs.php.net DB seems to be down

2010-02-04 Thread Jess Portnoy

Hello all,

I can get to the system's index page just fine but any bug lookup 
results in:
The data center is offline. This might be a feature, and not a bug, but 
probably not.


It was probably reported already but in case it was not, thought I'd 
drop you a line.


Thanks,

--
May the source be with you,
Best regards,
Jess Portnoy


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DEV] SVN Account Request: scorninpc

2010-02-04 Thread Bruno P. Gonçalves
php-gtk extensions

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] imap4 search criteria

2010-02-04 Thread Dominik Gehl
 $pgm = imap_searchprogram_new();
 imap_searchprogram_criteria($pgm1,DRAFT SMALLER 34567 HEADER Message-Id 
 d76c58cd-c94d-4de4-b621-83d66437e...@dokdok.com FROM domi...@dokdok.com);
 
 I assume you meant '$pgm' above?

You are absolutely right !

In fact, you can also set every parameter in its own 
imap_searchprogram_criteria call, so the above (without the typo) would be 
equivalent to the four calls below:

imap_searchprogram_criteria($pgm,DRAFT);
imap_searchprogram_criteria($pgm,SMALLER 34567);
imap_searchprogram_criteria($pgm,HEADER  Message-Id 
d76c58cd-c94d-4de4-b621-83d66437e...@dokdok.com);
imap_searchprogram_criteria($pgm,FROM domi...@dokdok.com);

If you need a logical OR of several criteria, you would use the following calls:

$pgm1 = imap_searchprogram_new();
imap_searchprogram_criteria($pgm1,DRAFT);
$pgm2 = imap_searchprogram_new();
imap_searchprogram_criteria($pgm2,ANSWERED);
$pgm = imap_searchprogram_or($pgm1, $pgm2);
imap_search($mbox,$pgm);


Dominik
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php