Skip to content

Commit 5d7d5e2

Browse files
committed
Add proper default values for optional arguments in IMAP
Closes GH-6179
1 parent 7fde991 commit 5d7d5e2

File tree

4 files changed

+31
-41
lines changed

4 files changed

+31
-41
lines changed

UPGRADING

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,10 @@ PHP 8.0 UPGRADE NOTES
325325
. iconv() implementations which do not properly set errno in case of errors
326326
are no longer supported.
327327

328+
- IMAP:
329+
. The unused default_host argument of imap_headerinfo() has been removed.
330+
. The imap_header() function which is an alias of imap_headerinfo() has been removed.
331+
328332
- Intl:
329333
. The deprecated constant INTL_IDNA_VARIANT_2003 has been removed.
330334
RFC: https://wiki.php.net/rfc/deprecate-and-remove-intl_idna_variant_2003

ext/imap/php_imap.c

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -702,10 +702,10 @@ static void php_imap_do_open(INTERNAL_FUNCTION_PARAMETERS, int persistent)
702702
zend_long retries = 0, flags = NIL, cl_flags = NIL;
703703
MAILSTREAM *imap_stream;
704704
pils *imap_le_struct;
705-
zval *params = NULL;
705+
HashTable *params = NULL;
706706
int argc = ZEND_NUM_ARGS();
707707

708-
if (zend_parse_parameters(argc, "PSS|lla", &mailbox, &user,
708+
if (zend_parse_parameters(argc, "PSS|llh", &mailbox, &user,
709709
&passwd, &flags, &retries, &params) == FAILURE) {
710710
RETURN_THROWS();
711711
}
@@ -723,7 +723,7 @@ static void php_imap_do_open(INTERNAL_FUNCTION_PARAMETERS, int persistent)
723723
if (params) {
724724
zval *disabled_auth_method;
725725

726-
if ((disabled_auth_method = zend_hash_str_find(Z_ARRVAL_P(params), "DISABLE_AUTHENTICATOR", sizeof("DISABLE_AUTHENTICATOR") - 1)) != NULL) {
726+
if ((disabled_auth_method = zend_hash_str_find(params, "DISABLE_AUTHENTICATOR", sizeof("DISABLE_AUTHENTICATOR") - 1)) != NULL) {
727727
switch (Z_TYPE_P(disabled_auth_method)) {
728728
case IS_STRING:
729729
if (Z_STRLEN_P(disabled_auth_method) > 1) {
@@ -866,7 +866,7 @@ PHP_FUNCTION(imap_append)
866866
pils *imap_le_struct;
867867
STRING st;
868868

869-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rSS|SS", &streamind, &folder, &message, &flags, &internal_date) == FAILURE) {
869+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rSS|S!S!", &streamind, &folder, &message, &flags, &internal_date) == FAILURE) {
870870
RETURN_THROWS();
871871
}
872872

@@ -1603,15 +1603,14 @@ PHP_FUNCTION(imap_undelete)
16031603
PHP_FUNCTION(imap_headerinfo)
16041604
{
16051605
zval *streamind;
1606-
zend_string *defaulthost = NULL;
16071606
int argc = ZEND_NUM_ARGS();
16081607
zend_long msgno, fromlength, subjectlength;
16091608
pils *imap_le_struct;
16101609
MESSAGECACHE *cache;
16111610
ENVELOPE *en;
16121611
char dummy[2000], fulladdress[MAILTMPLEN + 1];
16131612

1614-
if (zend_parse_parameters(argc, "rl|llS", &streamind, &msgno, &fromlength, &subjectlength, &defaulthost) == FAILURE) {
1613+
if (zend_parse_parameters(argc, "rl|ll", &streamind, &msgno, &fromlength, &subjectlength) == FAILURE) {
16151614
RETURN_THROWS();
16161615
}
16171616

@@ -2645,9 +2644,8 @@ PHP_FUNCTION(imap_sort)
26452644
char *search_criteria;
26462645
SORTPGM *mypgm=NIL;
26472646
SEARCHPGM *spg=NIL;
2648-
int argc = ZEND_NUM_ARGS();
26492647

2650-
if (zend_parse_parameters(argc, "rll|lSS", &streamind, &pgm, &rev, &flags, &criteria, &charset) == FAILURE) {
2648+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rll|lS!S!", &streamind, &pgm, &rev, &flags, &criteria, &charset) == FAILURE) {
26512649
RETURN_THROWS();
26522650
}
26532651

@@ -2659,13 +2657,11 @@ PHP_FUNCTION(imap_sort)
26592657
php_error_docref(NULL, E_WARNING, "Unrecognized sort criteria");
26602658
RETURN_FALSE;
26612659
}
2662-
if (argc >= 4) {
2663-
if (flags < 0) {
2664-
php_error_docref(NULL, E_WARNING, "Search options parameter has to be greater than or equal to 0");
2665-
RETURN_FALSE;
2666-
}
2660+
if (flags < 0) {
2661+
php_error_docref(NULL, E_WARNING, "Search options parameter has to be greater than or equal to 0");
2662+
RETURN_FALSE;
26672663
}
2668-
if (argc >= 5) {
2664+
if (criteria) {
26692665
search_criteria = estrndup(ZSTR_VAL(criteria), ZSTR_LEN(criteria));
26702666
spg = mail_criteria(search_criteria);
26712667
efree(search_criteria);
@@ -2678,7 +2674,7 @@ PHP_FUNCTION(imap_sort)
26782674
mypgm->function = (short) pgm;
26792675
mypgm->next = NIL;
26802676

2681-
slst = mail_sort(imap_le_struct->imap_stream, (argc == 6 ? ZSTR_VAL(charset) : NIL), spg, mypgm, (argc >= 4 ? flags : NIL));
2677+
slst = mail_sort(imap_le_struct->imap_stream, (charset ? ZSTR_VAL(charset) : NIL), spg, mypgm, flags);
26822678

26832679
if (spg && !(flags & SE_FREE)) {
26842680
mail_free_searchpgm(&spg);
@@ -3579,7 +3575,7 @@ PHP_FUNCTION(imap_mail)
35793575
zend_string *to=NULL, *message=NULL, *headers=NULL, *subject=NULL, *cc=NULL, *bcc=NULL, *rpath=NULL;
35803576
int argc = ZEND_NUM_ARGS();
35813577

3582-
if (zend_parse_parameters(argc, "PPP|PPPP", &to, &subject, &message,
3578+
if (zend_parse_parameters(argc, "PPP|P!P!P!P!", &to, &subject, &message,
35833579
&headers, &cc, &bcc, &rpath) == FAILURE) {
35843580
RETURN_THROWS();
35853581
}

ext/imap/php_imap.stub.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/**
66
* @return resource|false
77
*/
8-
function imap_open(string $mailbox, string $user, string $password, int $options = 0, int $n_retries = 0, array $params = UNKNOWN) {}
8+
function imap_open(string $mailbox, string $user, string $password, int $options = 0, int $n_retries = 0, array $params = []) {}
99

1010
/**
1111
* @param resource $stream_id
@@ -27,13 +27,7 @@ function imap_num_recent($stream_id): int|false {}
2727
function imap_headers($stream_id): array|false {}
2828

2929
/** @param resource $stream_id */
30-
function imap_headerinfo($stream_id, int $msg_no, int $from_length = 0, int $subject_length = 0, string $default_host = UNKNOWN): stdClass|false {}
31-
32-
/**
33-
* @param resource $stream_id
34-
* @alias imap_headerinfo
35-
*/
36-
function imap_header($stream_id, int $msg_no, int $from_length = 0, int $subject_length = 0, string $default_host = UNKNOWN): stdClass|false {}
30+
function imap_headerinfo($stream_id, int $msg_no, int $from_length = 0, int $subject_length = 0): stdClass|false {}
3731

3832
function imap_rfc822_parse_headers(string $headers, string $default_host = "UNKNOWN"): stdClass {}
3933

@@ -148,7 +142,7 @@ function imap_subscribe($stream_id, string $mailbox): bool {}
148142
function imap_unsubscribe($stream_id, string $mailbox): bool {}
149143

150144
/** @param resource $stream_id */
151-
function imap_append($stream_id, string $folder, string $message, string $options = UNKNOWN, string $internal_date = UNKNOWN): bool {}
145+
function imap_append($stream_id, string $folder, string $message, ?string $options = null, ?string $internal_date = null): bool {}
152146

153147
/** @param resource $stream_id */
154148
function imap_ping($stream_id): bool {}
@@ -180,7 +174,7 @@ function imap_setflag_full($stream_id, string $sequence, string $flag, int $opti
180174
function imap_clearflag_full($stream_id, string $sequence, string $flag, int $options = 0): bool {}
181175

182176
/** @param resource $stream_id */
183-
function imap_sort($stream_id, int $criteria, int $reverse, int $options = 0, string $search_criteria = UNKNOWN, string $charset = UNKNOWN): array|false {}
177+
function imap_sort($stream_id, int $criteria, int $reverse, int $options = 0, ?string $search_criteria = null, ?string $charset = null): array|false {}
184178

185179
/** @param resource $stream_id */
186180
function imap_uid($stream_id, int $msg_no): int|false {}
@@ -258,4 +252,4 @@ function imap_setacl($stream_id, string $mailbox, string $id, string $rights): b
258252
function imap_getacl($stream_id, string $mailbox): array|false {}
259253
#endif
260254

261-
function imap_mail(string $to, string $subject, string $message, string $additional_headers = UNKNOWN, string $cc = UNKNOWN, string $bcc = UNKNOWN, string $rpath = UNKNOWN): bool {}
255+
function imap_mail(string $to, string $subject, string $message, ?string $additional_headers = null, ?string $cc = null, ?string $bcc = null, ?string $rpath = null): bool {}

ext/imap/php_imap_arginfo.h

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 4991f82d78672ab23044864fa6dd75851952965c */
2+
* Stub hash: e501d6869d721ad720a1a7c8b597b96e9591d5ed */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_open, 0, 0, 3)
55
ZEND_ARG_TYPE_INFO(0, mailbox, IS_STRING, 0)
66
ZEND_ARG_TYPE_INFO(0, user, IS_STRING, 0)
77
ZEND_ARG_TYPE_INFO(0, password, IS_STRING, 0)
88
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, options, IS_LONG, 0, "0")
99
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, n_retries, IS_LONG, 0, "0")
10-
ZEND_ARG_TYPE_INFO(0, params, IS_ARRAY, 0)
10+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, params, IS_ARRAY, 0, "[]")
1111
ZEND_END_ARG_INFO()
1212

1313
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imap_reopen, 0, 2, _IS_BOOL, 0)
@@ -37,11 +37,8 @@ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_imap_headerinfo, 0, 2, stdCl
3737
ZEND_ARG_TYPE_INFO(0, msg_no, IS_LONG, 0)
3838
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, from_length, IS_LONG, 0, "0")
3939
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, subject_length, IS_LONG, 0, "0")
40-
ZEND_ARG_TYPE_INFO(0, default_host, IS_STRING, 0)
4140
ZEND_END_ARG_INFO()
4241

43-
#define arginfo_imap_header arginfo_imap_headerinfo
44-
4542
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_imap_rfc822_parse_headers, 0, 1, stdClass, 0)
4643
ZEND_ARG_TYPE_INFO(0, headers, IS_STRING, 0)
4744
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, default_host, IS_STRING, 0, "\"UNKNOWN\"")
@@ -173,8 +170,8 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imap_append, 0, 3, _IS_BOOL, 0)
173170
ZEND_ARG_INFO(0, stream_id)
174171
ZEND_ARG_TYPE_INFO(0, folder, IS_STRING, 0)
175172
ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0)
176-
ZEND_ARG_TYPE_INFO(0, options, IS_STRING, 0)
177-
ZEND_ARG_TYPE_INFO(0, internal_date, IS_STRING, 0)
173+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, options, IS_STRING, 1, "null")
174+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, internal_date, IS_STRING, 1, "null")
178175
ZEND_END_ARG_INFO()
179176

180177
#define arginfo_imap_ping arginfo_imap_expunge
@@ -217,8 +214,8 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_imap_sort, 0, 3, MAY_BE_ARRAY|MA
217214
ZEND_ARG_TYPE_INFO(0, criteria, IS_LONG, 0)
218215
ZEND_ARG_TYPE_INFO(0, reverse, IS_LONG, 0)
219216
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, options, IS_LONG, 0, "0")
220-
ZEND_ARG_TYPE_INFO(0, search_criteria, IS_STRING, 0)
221-
ZEND_ARG_TYPE_INFO(0, charset, IS_STRING, 0)
217+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, search_criteria, IS_STRING, 1, "null")
218+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, charset, IS_STRING, 1, "null")
222219
ZEND_END_ARG_INFO()
223220

224221
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_imap_uid, 0, 2, MAY_BE_LONG|MAY_BE_FALSE)
@@ -342,10 +339,10 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imap_mail, 0, 3, _IS_BOOL, 0)
342339
ZEND_ARG_TYPE_INFO(0, to, IS_STRING, 0)
343340
ZEND_ARG_TYPE_INFO(0, subject, IS_STRING, 0)
344341
ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0)
345-
ZEND_ARG_TYPE_INFO(0, additional_headers, IS_STRING, 0)
346-
ZEND_ARG_TYPE_INFO(0, cc, IS_STRING, 0)
347-
ZEND_ARG_TYPE_INFO(0, bcc, IS_STRING, 0)
348-
ZEND_ARG_TYPE_INFO(0, rpath, IS_STRING, 0)
342+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, additional_headers, IS_STRING, 1, "null")
343+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, cc, IS_STRING, 1, "null")
344+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, bcc, IS_STRING, 1, "null")
345+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, rpath, IS_STRING, 1, "null")
349346
ZEND_END_ARG_INFO()
350347

351348

@@ -440,7 +437,6 @@ static const zend_function_entry ext_functions[] = {
440437
ZEND_FE(imap_num_recent, arginfo_imap_num_recent)
441438
ZEND_FE(imap_headers, arginfo_imap_headers)
442439
ZEND_FE(imap_headerinfo, arginfo_imap_headerinfo)
443-
ZEND_FALIAS(imap_header, imap_headerinfo, arginfo_imap_header)
444440
ZEND_FE(imap_rfc822_parse_headers, arginfo_imap_rfc822_parse_headers)
445441
ZEND_FE(imap_rfc822_write_address, arginfo_imap_rfc822_write_address)
446442
ZEND_FE(imap_rfc822_parse_adrlist, arginfo_imap_rfc822_parse_adrlist)

0 commit comments

Comments
 (0)