- IMAP
. Fixed bug #80438 (imap_msgno() incorrectly warns and return false on valid UIDs in PHP 8.0.0). (girgias)
+ . Fix a regression with valid UIDs in imap_savebody() (girgias)
+ . Make warnings for invalid message numbers/UIDs between functions consistent (girgias)
- Intl:
. Fixed bug #80425 (MessageFormatAdapter::getArgTypeList redefined). (Nikita)
RETURN_FALSE; \
} \
+#define PHP_IMAP_CHECK_MSGNO_MAYBE_UID_PRE_FLAG_CHECKS(msgindex, arg_pos) \
+ if (msgindex < 1) { \
+ zend_argument_value_error(arg_pos, "must be greater than 0"); \
+ RETURN_THROWS(); \
+ } \
+
+#define PHP_IMAP_CHECK_MSGNO_MAYBE_UID_POST_FLAG_CHECKS(msgindex, arg_pos, func_flags, uid_flag) \
+ if (func_flags & uid_flag) { \
+ /* This should be cached; if it causes an extra RTT to the IMAP server, */ \
+ /* then that's the price we pay for making sure we don't crash. */ \
+ unsigned int msg_no_from_uid = mail_msgno(imap_le_struct->imap_stream, msgindex); \
+ if (msg_no_from_uid == 0) { \
+ php_error_docref(NULL, E_WARNING, "UID does not exist"); \
+ RETURN_FALSE; \
+ } \
+ } else { \
+ if (((unsigned) msgindex) > imap_le_struct->imap_stream->nmsgs) { \
+ php_error_docref(NULL, E_WARNING, "Bad message number"); \
+ RETURN_FALSE; \
+ } \
+ } \
+
/* {{{ mail_close_it */
static void mail_close_it(zend_resource *rsrc)
{
zval *streamind;
zend_long msgno, flags = 0;
pils *imap_le_struct;
- unsigned long msgindex;
char *body;
unsigned long body_len = 0;
RETURN_THROWS();
}
- if (msgno < 1) {
- zend_argument_value_error(2, "must be greater than 0");
- RETURN_THROWS();
- }
+ PHP_IMAP_CHECK_MSGNO_MAYBE_UID_PRE_FLAG_CHECKS(msgno, 2);
if (flags && ((flags & ~(FT_UID|FT_PEEK|FT_INTERNAL)) != 0)) {
zend_argument_value_error(3, "must be a bitmask of FT_UID, FT_PEEK, and FT_INTERNAL");
RETURN_THROWS();
}
- if (flags && (flags & FT_UID)) {
- /* This should be cached; if it causes an extra RTT to the
- IMAP server, then that's the price we pay for making
- sure we don't crash. */
- msgindex = mail_msgno(imap_le_struct->imap_stream, msgno);
- if (msgindex == 0) {
- php_error_docref(NULL, E_WARNING, "UID does not exist");
- RETURN_FALSE;
- }
- } else {
- msgindex = (unsigned long) msgno;
- }
-
- PHP_IMAP_CHECK_MSGNO(msgindex, 2);
+ PHP_IMAP_CHECK_MSGNO_MAYBE_UID_POST_FLAG_CHECKS(msgno, 2, flags, FT_UID);
- /* TODO Shouldn't this pass msgindex??? */
body = mail_fetchtext_full (imap_le_struct->imap_stream, msgno, &body_len, flags);
if (body_len == 0) {
RETVAL_EMPTY_STRING();
}
/* }}} */
+/* TODO UID Tests */
/* {{{ Copy specified message to a mailbox */
PHP_FUNCTION(imap_mail_copy)
{
}
/* }}} */
+/* TODO UID Tests */
/* {{{ Move specified message to a mailbox */
PHP_FUNCTION(imap_mail_move)
{
RETURN_THROWS();
}
+ // TODO Check sequence validity?
+
if (flags && ((flags & ~FT_UID) != 0)) {
zend_argument_value_error(3, "must be FT_UID or 0");
RETURN_THROWS();
}
mail_setflag_full(imap_le_struct->imap_stream, ZSTR_VAL(sequence), "\\DELETED", flags);
- RETVAL_TRUE;
+ RETURN_TRUE;
}
/* }}} */
zend_long msgno, flags = 0;
pils *imap_le_struct;
BODY *body;
- int msgindex;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl|l", &streamind, &msgno, &flags) == FAILURE) {
RETURN_THROWS();
RETURN_THROWS();
}
- if (msgno < 1) {
- zend_argument_value_error(2, "must be greater than 0");
- RETURN_THROWS();
- }
+ PHP_IMAP_CHECK_MSGNO_MAYBE_UID_PRE_FLAG_CHECKS(msgno, 2);
if (flags && ((flags & ~FT_UID) != 0)) {
zend_argument_value_error(3, "must be FT_UID or 0");
RETURN_THROWS();
}
- object_init(return_value);
+ PHP_IMAP_CHECK_MSGNO_MAYBE_UID_POST_FLAG_CHECKS(msgno, 2, flags, FT_UID);
- if (flags & FT_UID) {
- /* This should be cached; if it causes an extra RTT to the
- IMAP server, then that's the price we pay for making
- sure we don't crash. */
- msgindex = mail_msgno(imap_le_struct->imap_stream, msgno);
- if (msgindex == 0) {
- php_error_docref(NULL, E_WARNING, "UID does not exist");
- RETURN_FALSE;
- }
- } else {
- msgindex = msgno;
- }
- PHP_IMAP_CHECK_MSGNO(msgindex, 2);
+ object_init(return_value);
- /* TODO Shouldn't this pass msgindex??? */
- mail_fetchstructure_full(imap_le_struct->imap_stream, msgno, &body , (ZEND_NUM_ARGS() == 3 ? flags : NIL));
+ mail_fetchstructure_full(imap_le_struct->imap_stream, msgno, &body , flags);
if (!body) {
php_error_docref(NULL, E_WARNING, "No body information available");
RETURN_THROWS();
}
- if (msgno < 1) {
- zend_argument_value_error(2, "must be greater than 0");
- RETURN_THROWS();
- }
+ PHP_IMAP_CHECK_MSGNO_MAYBE_UID_PRE_FLAG_CHECKS(msgno, 2);
if (flags && ((flags & ~(FT_UID|FT_PEEK|FT_INTERNAL)) != 0)) {
zend_argument_value_error(4, "must be a bitmask of FT_UID, FT_PEEK, and FT_INTERNAL");
RETURN_THROWS();
}
- if (!(flags & FT_UID)) {
- /* only perform the check if the msgno is a message number and not a UID */
- PHP_IMAP_CHECK_MSGNO(msgno, 2);
- }
+ PHP_IMAP_CHECK_MSGNO_MAYBE_UID_POST_FLAG_CHECKS(msgno, 2, flags, FT_UID);
body = mail_fetchbody_full(imap_le_struct->imap_stream, msgno, ZSTR_VAL(sec), &len, flags);
RETURN_THROWS();
}
- if (msgno < 1) {
- zend_argument_value_error(2, "must be greater than 0");
+ if ((imap_le_struct = (pils *)zend_fetch_resource(Z_RES_P(streamind), "imap", le_imap)) == NULL) {
RETURN_THROWS();
}
+ PHP_IMAP_CHECK_MSGNO_MAYBE_UID_PRE_FLAG_CHECKS(msgno, 2);
+
if (flags && ((flags & ~(FT_UID|FT_PEEK|FT_INTERNAL)) != 0)) {
zend_argument_value_error(4, "must be a bitmask of FT_UID, FT_PEEK, and FT_INTERNAL");
RETURN_THROWS();
}
- if ((imap_le_struct = (pils *)zend_fetch_resource(Z_RES_P(streamind), "imap", le_imap)) == NULL) {
- RETURN_THROWS();
- }
-
- if (!(flags & FT_UID)) {
- /* only perform the check if the msgno is a message number and not a UID */
- PHP_IMAP_CHECK_MSGNO(msgno, 2);
- }
+ PHP_IMAP_CHECK_MSGNO_MAYBE_UID_POST_FLAG_CHECKS(msgno, 2, flags, FT_UID);
body = mail_fetch_mime(imap_le_struct->imap_stream, msgno, ZSTR_VAL(sec), &len, flags);
RETURN_THROWS();
}
- // TODO Fix for UID and normal MSGNO
- //PHP_IMAP_CHECK_MSGNO(msgno, 3);
+ PHP_IMAP_CHECK_MSGNO_MAYBE_UID_PRE_FLAG_CHECKS(msgno, 3)
if (flags && ((flags & ~(FT_UID|FT_PEEK|FT_INTERNAL)) != 0)) {
zend_argument_value_error(5, "must be a bitmask of FT_UID, FT_PEEK, and FT_INTERNAL");
RETURN_THROWS();
}
- // TODO Drop this?
- if (!imap_le_struct) {
- RETURN_FALSE;
- }
+ PHP_IMAP_CHECK_MSGNO_MAYBE_UID_POST_FLAG_CHECKS(msgno, 3, flags, FT_UID);
switch (Z_TYPE_P(out))
{
PHP_FUNCTION(imap_fetchheader)
{
zval *streamind;
- zend_long msgno, flags = 0L;
+ zend_long msgno, flags = 0;
pils *imap_le_struct;
- int msgindex;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl|l", &streamind, &msgno, &flags) == FAILURE) {
RETURN_THROWS();
RETURN_THROWS();
}
- // TODO Check for msgno < 1 now or wait later for PHP_IMAP_CHECK_MSGNO check?
+ PHP_IMAP_CHECK_MSGNO_MAYBE_UID_PRE_FLAG_CHECKS(msgno, 2);
if (flags && ((flags & ~(FT_UID|FT_INTERNAL|FT_PREFETCHTEXT)) != 0)) {
zend_argument_value_error(3, "must be a bitmask of FT_UID, FT_PREFETCHTEXT, and FT_INTERNAL");
RETURN_THROWS();
}
- if (flags & FT_UID) {
- /* This should be cached; if it causes an extra RTT to the
- IMAP server, then that's the price we pay for making sure
- we don't crash. */
- msgindex = mail_msgno(imap_le_struct->imap_stream, msgno);
- if (msgindex == 0) {
- php_error_docref(NULL, E_WARNING, "UID does not exist");
- RETURN_FALSE;
- }
- } else {
- msgindex = msgno;
- }
-
- PHP_IMAP_CHECK_MSGNO(msgindex, 2);
+ PHP_IMAP_CHECK_MSGNO_MAYBE_UID_POST_FLAG_CHECKS(msgno, 2, flags, FT_UID);
- /* TODO Check shouldn't this pass msgindex???? */
- RETVAL_STRING(mail_fetchheader_full(imap_le_struct->imap_stream, msgno, NIL, NIL, (ZEND_NUM_ARGS() == 3 ? flags : NIL)));
+ RETVAL_STRING(mail_fetchheader_full(imap_le_struct->imap_stream, msgno, NIL, NIL, flags));
}
/* }}} */
--TEST--
-imap_body() ValueError
+imap_body() errors: ValueError and Warnings
--CREDITS--
Paul Sohier
#phptestfest utrecht
require_once(__DIR__.'/setup/imap_include.inc');
-$imap_stream = setup_test_mailbox("imapbodyvalueerror", 0);
+$imap_mail_box = setup_test_mailbox("imapbodyerror", 0);
try {
- imap_body($imap_stream,-1);
+ imap_body($imap_mail_box, -1);
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
}
try {
- imap_body($imap_stream,1,-1);
+ imap_body($imap_mail_box, 1, -1);
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
}
-//Access not existing
-var_dump(imap_body($imap_stream, 255, FT_UID));
+// Access not existing
+var_dump(imap_body($imap_mail_box, 255));
+var_dump(imap_body($imap_mail_box, 255, FT_UID));
-imap_close($imap_stream);
+imap_close($imap_mail_box);
?>
--CLEAN--
<?php
-$mailbox_suffix = 'imapbodyvalueerror';
+$mailbox_suffix = 'imapbodyerror';
require_once(__DIR__ . '/setup/clean.inc');
?>
--EXPECTF--
imap_body(): Argument #2 ($message_num) must be greater than 0
imap_body(): Argument #3 ($flags) must be a bitmask of FT_UID, FT_PEEK, and FT_INTERNAL
+Warning: imap_body(): Bad message number in %s on line %d
+bool(false)
+
Warning: imap_body(): UID does not exist in %s on line %d
bool(false)
--- /dev/null
+--TEST--
+imap_fetchbody() errors: ValueError and Warnings
+--SKIPIF--
+<?php
+require_once(__DIR__.'/setup/skipif.inc');
+?>
+--FILE--
+<?php
+
+require_once(__DIR__.'/setup/imap_include.inc');
+
+$imap_mail_box = setup_test_mailbox("imapfetchbodyerrors", 0);
+
+$section = '';
+
+try {
+ imap_fetchbody($imap_mail_box, -1, $section);
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+try {
+ imap_fetchbody($imap_mail_box, 1, $section, -1);
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+
+// Access not existing
+var_dump(imap_fetchbody($imap_mail_box, 255, $section));
+var_dump(imap_fetchbody($imap_mail_box, 255, $section, FT_UID));
+
+imap_close($imap_mail_box);
+
+?>
+--CLEAN--
+<?php
+$mailbox_suffix = 'imapfetchbodyerrors';
+require_once(__DIR__ . '/setup/clean.inc');
+?>
+--EXPECTF--
+Create a temporary mailbox and add 0 msgs
+New mailbox created
+imap_fetchbody(): Argument #2 ($message_num) must be greater than 0
+imap_fetchbody(): Argument #4 ($flags) must be a bitmask of FT_UID, FT_PEEK, and FT_INTERNAL
+
+Warning: imap_fetchbody(): Bad message number in %s on line %d
+bool(false)
+
+Warning: imap_fetchbody(): UID does not exist in %s on line %d
+bool(false)
--- /dev/null
+--TEST--
+imap_fetchheader() errors: ValueError and Warnings
+--SKIPIF--
+<?php
+require_once(__DIR__.'/setup/skipif.inc');
+?>
+--FILE--
+<?php
+
+require_once(__DIR__.'/setup/imap_include.inc');
+
+$imap_mail_box = setup_test_mailbox("imapfetchheadererrors", 0);
+
+try {
+ imap_fetchheader($imap_mail_box, -1);
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+try {
+ imap_fetchheader($imap_mail_box, 1, -1);
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+
+// Access not existing
+var_dump(imap_fetchheader($imap_mail_box, 255));
+var_dump(imap_fetchheader($imap_mail_box, 255, FT_UID));
+
+imap_close($imap_mail_box);
+
+?>
+--CLEAN--
+<?php
+$mailbox_suffix = 'imapfetchheadererrors';
+require_once(__DIR__ . '/setup/clean.inc');
+?>
+--EXPECTF--
+Create a temporary mailbox and add 0 msgs
+New mailbox created
+imap_fetchheader(): Argument #2 ($message_num) must be greater than 0
+imap_fetchheader(): Argument #3 ($flags) must be a bitmask of FT_UID, FT_PREFETCHTEXT, and FT_INTERNAL
+
+Warning: imap_fetchheader(): Bad message number in %s on line %d
+bool(false)
+
+Warning: imap_fetchheader(): UID does not exist in %s on line %d
+bool(false)
--- /dev/null
+--TEST--
+imap_fetchmime() errors: ValueError and Warnings
+--SKIPIF--
+<?php
+require_once(__DIR__.'/setup/skipif.inc');
+?>
+--FILE--
+<?php
+
+require_once(__DIR__.'/setup/imap_include.inc');
+
+$imap_mail_box = setup_test_mailbox("imapfetchmimeerrors", 0);
+
+$section = '';
+
+try {
+ imap_fetchmime($imap_mail_box, -1, $section);
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+try {
+ imap_fetchmime($imap_mail_box, 1, $section, -1);
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+
+// Access not existing
+var_dump(imap_fetchmime($imap_mail_box, 255, $section));
+var_dump(imap_fetchmime($imap_mail_box, 255, $section, FT_UID));
+
+imap_close($imap_mail_box);
+
+?>
+--CLEAN--
+<?php
+$mailbox_suffix = 'imapfetchmimeerrors';
+require_once(__DIR__ . '/setup/clean.inc');
+?>
+--EXPECTF--
+Create a temporary mailbox and add 0 msgs
+New mailbox created
+imap_fetchmime(): Argument #2 ($message_num) must be greater than 0
+imap_fetchmime(): Argument #4 ($flags) must be a bitmask of FT_UID, FT_PEEK, and FT_INTERNAL
+
+Warning: imap_fetchmime(): Bad message number in %s on line %d
+bool(false)
+
+Warning: imap_fetchmime(): UID does not exist in %s on line %d
+bool(false)
--- /dev/null
+--TEST--
+imap_fetchstructure() errors: ValueError and Warnings
+--SKIPIF--
+<?php
+require_once(__DIR__.'/setup/skipif.inc');
+?>
+--FILE--
+<?php
+
+require_once(__DIR__.'/setup/imap_include.inc');
+
+$imap_mail_box = setup_test_mailbox("imapfetchstructureerrors", 0);
+
+try {
+ imap_fetchstructure($imap_mail_box, -1);
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+try {
+ imap_fetchstructure($imap_mail_box, 1, -1);
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+
+// Access not existing
+var_dump(imap_fetchstructure($imap_mail_box, 255));
+var_dump(imap_fetchstructure($imap_mail_box, 255, FT_UID));
+
+imap_close($imap_mail_box);
+
+?>
+--CLEAN--
+<?php
+$mailbox_suffix = 'imapfetchstructureerrors';
+require_once(__DIR__ . '/setup/clean.inc');
+?>
+--EXPECTF--
+Create a temporary mailbox and add 0 msgs
+New mailbox created
+imap_fetchstructure(): Argument #2 ($message_num) must be greater than 0
+imap_fetchstructure(): Argument #3 ($flags) must be FT_UID or 0
+
+Warning: imap_fetchstructure(): Bad message number in %s on line %d
+bool(false)
+
+Warning: imap_fetchstructure(): UID does not exist in %s on line %d
+bool(false)
--- /dev/null
+--TEST--
+imap_savebody() errors: ValueError and Warnings
+--SKIPIF--
+<?php
+require_once(__DIR__.'/setup/skipif.inc');
+?>
+--FILE--
+<?php
+
+require_once(__DIR__.'/setup/imap_include.inc');
+
+$imap_mail_box = setup_test_mailbox("imapsavebodyerrors", 0);
+
+$section = '';
+
+try {
+ imap_savebody($imap_mail_box, '', -1, $section);
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+try {
+ imap_savebody($imap_mail_box, '', 1, $section, -1);
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+
+// Access not existing
+var_dump(imap_savebody($imap_mail_box, '', 255, $section));
+var_dump(imap_savebody($imap_mail_box, '', 255, $section, FT_UID));
+
+imap_close($imap_mail_box);
+
+?>
+--CLEAN--
+<?php
+$mailbox_suffix = 'imapsavebodyerrors';
+require_once(__DIR__ . '/setup/clean.inc');
+?>
+--EXPECTF--
+Create a temporary mailbox and add 0 msgs
+New mailbox created
+imap_savebody(): Argument #3 ($message_num) must be greater than 0
+imap_savebody(): Argument #5 ($flags) must be a bitmask of FT_UID, FT_PEEK, and FT_INTERNAL
+
+Warning: imap_savebody(): Bad message number in %s on line %d
+bool(false)
+
+Warning: imap_savebody(): UID does not exist in %s on line %d
+bool(false)