Skip to content

Commit 7b11212

Browse files
committed
Specific warning if UID message number does not exist
1 parent f2ff235 commit 7b11212

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

ext/imap/php_imap.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,7 +1256,7 @@ PHP_FUNCTION(imap_body)
12561256
zval *streamind;
12571257
zend_long msgno, flags = 0;
12581258
pils *imap_le_struct;
1259-
int msgindex;
1259+
unsigned long msgindex;
12601260
char *body;
12611261
unsigned long body_len = 0;
12621262

@@ -1283,11 +1283,14 @@ PHP_FUNCTION(imap_body)
12831283
IMAP server, then that's the price we pay for making
12841284
sure we don't crash. */
12851285
msgindex = mail_msgno(imap_le_struct->imap_stream, msgno);
1286+
if (msgindex == 0) {
1287+
php_error_docref(NULL, E_WARNING, "UID does not exist");
1288+
RETURN_FALSE;
1289+
}
12861290
} else {
1287-
msgindex = msgno;
1291+
msgindex = (unsigned long) msgno;
12881292
}
12891293

1290-
// TODO int overflow as can be seen in imap_body.phpt will result in 999 => <0 trigerring a ValueError
12911294
PHP_IMAP_CHECK_MSGNO(msgindex, 2);
12921295

12931296
/* TODO Shouldn't this pass msgindex??? */
@@ -1901,6 +1904,10 @@ PHP_FUNCTION(imap_fetchstructure)
19011904
IMAP server, then that's the price we pay for making
19021905
sure we don't crash. */
19031906
msgindex = mail_msgno(imap_le_struct->imap_stream, msgno);
1907+
if (msgindex == 0) {
1908+
php_error_docref(NULL, E_WARNING, "UID does not exist");
1909+
RETURN_FALSE;
1910+
}
19041911
} else {
19051912
msgindex = msgno;
19061913
}
@@ -2779,6 +2786,10 @@ PHP_FUNCTION(imap_fetchheader)
27792786
IMAP server, then that's the price we pay for making sure
27802787
we don't crash. */
27812788
msgindex = mail_msgno(imap_le_struct->imap_stream, msgno);
2789+
if (msgindex == 0) {
2790+
php_error_docref(NULL, E_WARNING, "UID does not exist");
2791+
RETURN_FALSE;
2792+
}
27822793
} else {
27832794
msgindex = msgno;
27842795
}

ext/imap/tests/imap_body.phpt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ Paul Sohier
77
<?php
88
require_once(__DIR__.'/skipif.inc');
99
?>
10-
--XFAIL--
11-
zend_long overflow when trying to fit integer into int
1210
--FILE--
1311
<?php
1412

@@ -28,7 +26,7 @@ try {
2826
}
2927

3028
//Access not existing
31-
var_dump(imap_body($stream_id, 999, FT_UID));
29+
var_dump(imap_body($stream_id, 255, FT_UID));
3230

3331
imap_close($stream_id);
3432

@@ -37,5 +35,5 @@ imap_close($stream_id);
3735
imap_body(): Argument #2 ($msg_no) must be greater than 0
3836
imap_body(): Argument #3 ($options) must be a bitmask of FT_UID, FT_PEEK, and FT_INTERNAL
3937

40-
Warning: imap_body(): Bad message number in %s on line %d
38+
Warning: imap_body(): UID does not exist in %s on line %d
4139
bool(false)

0 commit comments

Comments
 (0)