Skip to content

Commit a17c5a5

Browse files
author
Ilia Alshanetsky
committed
Fixed bug #22505 (Allow imap_sort() and imap_search() to specify a charset)
1 parent 490da4f commit a17c5a5

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

ext/imap/php_imap.c

+15-9
Original file line numberDiff line numberDiff line change
@@ -2393,19 +2393,19 @@ PHP_FUNCTION(imap_clearflag_full)
23932393
}
23942394
/* }}} */
23952395

2396-
/* {{{ proto array imap_sort(resource stream_id, int criteria, int reverse [, int options [, string search_criteria]])
2396+
/* {{{ proto array imap_sort(resource stream_id, int criteria, int reverse [, int options [, string search_criteria [, string charset]]])
23972397
Sort an array of message headers, optionally including only messages that meet specified criteria. */
23982398
PHP_FUNCTION(imap_sort)
23992399
{
2400-
zval **streamind, **pgm, **rev, **flags, **criteria;
2400+
zval **streamind, **pgm, **rev, **flags, **criteria, **charset;
24012401
pils *imap_le_struct;
24022402
unsigned long *slst, *sl;
24032403
char *search_criteria;
24042404
SORTPGM *mypgm=NIL;
24052405
SEARCHPGM *spg=NIL;
24062406
int myargc = ZEND_NUM_ARGS();
24072407

2408-
if (myargc < 3 || myargc > 5 || zend_get_parameters_ex(myargc, &streamind, &pgm, &rev, &flags, &criteria) == FAILURE) {
2408+
if (myargc < 3 || myargc > 6 || zend_get_parameters_ex(myargc, &streamind, &pgm, &rev, &flags, &criteria, &charset) == FAILURE) {
24092409
ZEND_WRONG_PARAM_COUNT();
24102410
}
24112411

@@ -2420,10 +2420,13 @@ PHP_FUNCTION(imap_sort)
24202420
if (myargc >= 4) {
24212421
convert_to_long_ex(flags);
24222422
}
2423-
if (myargc == 5) {
2423+
if (myargc >= 5) {
24242424
search_criteria = estrndup(Z_STRVAL_PP(criteria), Z_STRLEN_PP(criteria));
24252425
spg = mail_criteria(search_criteria);
24262426
efree(search_criteria);
2427+
if (myargc == 6) {
2428+
convert_to_string_ex(charset);
2429+
}
24272430
} else {
24282431
spg = mail_newsearchpgm();
24292432
}
@@ -2433,7 +2436,7 @@ PHP_FUNCTION(imap_sort)
24332436
mypgm->function = (short) Z_LVAL_PP(pgm);
24342437
mypgm->next = NIL;
24352438

2436-
slst = mail_sort(imap_le_struct->imap_stream, NIL, spg, mypgm, myargc >= 4 ? Z_LVAL_PP(flags) : NIL);
2439+
slst = mail_sort(imap_le_struct->imap_stream, (myargc == 6 ? Z_STRVAL_PP(charset) : NIL), spg, mypgm, (myargc >= 4 ? Z_LVAL_PP(flags) : NIL));
24372440

24382441
if (spg) {
24392442
mail_free_searchpgm(&spg);
@@ -3381,18 +3384,18 @@ PHP_FUNCTION(imap_mail)
33813384
}
33823385
/* }}} */
33833386

3384-
/* {{{ proto array imap_search(resource stream_id, string criteria [, int options])
3387+
/* {{{ proto array imap_search(resource stream_id, string criteria [, int options [, string charset]])
33853388
Return a list of messages matching the given criteria */
33863389
PHP_FUNCTION(imap_search)
33873390
{
3388-
zval **streamind, **criteria, **search_flags;
3391+
zval **streamind, **criteria, **search_flags, **charset;
33893392
pils *imap_le_struct;
33903393
long flags;
33913394
char *search_criteria;
33923395
MESSAGELIST *cur;
33933396
int argc = ZEND_NUM_ARGS();
33943397

3395-
if (argc < 2 || argc > 3 || zend_get_parameters_ex(argc, &streamind, &criteria, &search_flags) == FAILURE) {
3398+
if (argc < 2 || argc > 4 || zend_get_parameters_ex(argc, &streamind, &criteria, &search_flags, &charset) == FAILURE) {
33963399
ZEND_WRONG_PARAM_COUNT();
33973400
}
33983401

@@ -3406,10 +3409,13 @@ PHP_FUNCTION(imap_search)
34063409
} else {
34073410
convert_to_long_ex(search_flags);
34083411
flags = Z_LVAL_PP(search_flags);
3412+
if (argc == 4) {
3413+
convert_to_string_ex(charset);
3414+
}
34093415
}
34103416

34113417
IMAPG(imap_messages) = IMAPG(imap_messages_tail) = NIL;
3412-
mail_search_full(imap_le_struct->imap_stream, NIL, mail_criteria(search_criteria), flags);
3418+
mail_search_full(imap_le_struct->imap_stream, (argc == 4 ? Z_STRVAL_PP(charset) : NIL), mail_criteria(search_criteria), flags);
34133419
if (IMAPG(imap_messages) == NIL) {
34143420
efree(search_criteria);
34153421
RETURN_FALSE;

0 commit comments

Comments
 (0)