Skip to content

Commit ce0c983

Browse files
committed
Promote warnings to Error in IMAP
1 parent 3b67f18 commit ce0c983

11 files changed

+323
-236
lines changed

ext/imap/php_imap.c

Lines changed: 223 additions & 152 deletions
Large diffs are not rendered by default.

ext/imap/tests/imap_body.phpt

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,31 @@
11
--TEST--
2-
imap_body() incorrect parameter count
2+
imap_body() ValueError
33
--CREDITS--
44
Paul Sohier
55
#phptestfest utrecht
66
--SKIPIF--
77
<?php
88
require_once(__DIR__.'/skipif.inc');
99
?>
10+
--XFAIL--
11+
zend_long overflow when trying to fit integer into int
1012
--FILE--
1113
<?php
1214

1315
require_once(__DIR__.'/imap_include.inc');
1416
$stream_id = imap_open($default_mailbox, $username, $password) or
1517
die("Cannot connect to mailbox $default_mailbox: " . imap_last_error());
1618

17-
imap_body($stream_id,-1);
18-
imap_body($stream_id,1,-1);
19+
try {
20+
imap_body($stream_id,-1);
21+
} catch (\ValueError $e) {
22+
echo $e->getMessage() . \PHP_EOL;
23+
}
24+
try {
25+
imap_body($stream_id,1,-1);
26+
} catch (\ValueError $e) {
27+
echo $e->getMessage() . \PHP_EOL;
28+
}
1929

2030
//Access not existing
2131
var_dump(imap_body($stream_id, 999, FT_UID));
@@ -24,9 +34,8 @@ imap_close($stream_id);
2434

2535
?>
2636
--EXPECTF--
27-
Warning: imap_body(): Bad message number in %s on line %d
28-
29-
Warning: imap_body(): Invalid value for the options parameter in %s on line %d
37+
imap_body(): Argument #2 ($msg_no) must be greater than 0
38+
imap_body(): Argument #3 ($options) must be a bitmask of FT_UID, FT_PEEK, and FT_INTERNAL
3039

3140
Warning: imap_body(): Bad message number in %s on line %d
3241
bool(false)

ext/imap/tests/imap_close_variation4.phpt

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@ foreach($inputs as $input) {
2828
imap_delete($stream_id, $i);
2929
}
3030
echo "\n-- Iteration $iterator --\n";
31-
var_dump( $check = imap_close($stream_id, $input) );
31+
try {
32+
var_dump( $check = imap_close($stream_id, $input) );
33+
} catch (\ValueError $e) {
34+
echo $e->getMessage() . \PHP_EOL;
35+
$check = false;
36+
}
3237

3338
// check that imap_close was successful, if not call imap_close and explicitly set CL_EXPUNGE
3439
if(false === $check) {
@@ -71,16 +76,10 @@ bool(true)
7176
CL_EXPUNGE was set
7277

7378
-- Iteration 3 --
74-
75-
Warning: imap_close(): Invalid value for the flags parameter in %s on line %d
76-
bool(false)
79+
imap_close(): Argument #2 ($options) must be CL_EXPUNGE or 0
7780

7881
-- Iteration 4 --
79-
80-
Warning: imap_close(): Invalid value for the flags parameter in %s on line %d
81-
bool(false)
82+
imap_close(): Argument #2 ($options) must be CL_EXPUNGE or 0
8283

8384
-- Iteration 5 --
84-
85-
Warning: imap_close(): Invalid value for the flags parameter in %s on line %d
86-
bool(false)
85+
imap_close(): Argument #2 ($options) must be CL_EXPUNGE or 0

ext/imap/tests/imap_fetch_overview_variation3.phpt

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,32 +25,32 @@ $options = array ('1',
2525
true,
2626
1.000000000000001,
2727
0.00001e5,
28-
PHP_INT_MAX,
29-
-PHP_INT_MAX
28+
245
3029
);
3130

32-
// iterate over each element of $options array
33-
$iterator = 1;
3431
imap_check($stream_id);
3532
foreach($options as $option) {
3633
echo "\nTesting with option value:";
3734
var_dump($option);
38-
$overview = imap_fetch_overview($stream_id, $msg_uid, $option);
39-
if ($overview) {
40-
echo "imap_fetch_overview() returns an object\n";
35+
try {
36+
$overview = imap_fetch_overview($stream_id, $msg_uid, $option);
37+
if ($overview) {
38+
echo "imap_fetch_overview() returns an object\n";
4139
}
42-
$iterator++;
40+
} catch (\ValueError $e) {
41+
echo $e->getMessage() . \PHP_EOL;
42+
}
4343
}
4444

4545
?>
4646
--CLEAN--
4747
<?php
4848
require_once(__DIR__.'/clean.inc');
4949
?>
50-
--EXPECTF--
50+
--EXPECT--
5151
*** Testing imap_fetch_overview() : usage variations ***
5252
Create a temporary mailbox and add 1 msgs
53-
.. mailbox '{%s}%s' created
53+
.. mailbox '{127.0.0.1:143/norsh}INBOX.phpttest' created
5454

5555
Testing with option value:string(1) "1"
5656
imap_fetch_overview() returns an object
@@ -64,10 +64,5 @@ imap_fetch_overview() returns an object
6464
Testing with option value:float(1)
6565
imap_fetch_overview() returns an object
6666

67-
Testing with option value:int(%d)
68-
69-
Warning: imap_fetch_overview(): Invalid value for the options parameter in %s on line %d
70-
71-
Testing with option value:int(-%d)
72-
73-
Warning: imap_fetch_overview(): Invalid value for the options parameter in %s on line %d
67+
Testing with option value:int(245)
68+
imap_fetch_overview(): Argument #3 ($options) must be FT_UID or 0

ext/imap/tests/imap_fetchbody_variation4.phpt

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,16 @@ $iterator = 1;
3131
imap_check($stream_id);
3232
foreach($options as $option) {
3333
echo "\n-- Iteration $iterator --\n";
34-
if(is_string(imap_fetchbody($stream_id, $msg_uid, $section, $option))) {
35-
echo "FT_UID valid\n";
36-
} else {
37-
echo "FT_UID not valid\n";
34+
35+
try {
36+
if(is_string(imap_fetchbody($stream_id, $msg_uid, $section, $option))) {
37+
echo "FT_UID valid\n";
38+
} else {
39+
echo "FT_UID not valid\n";
3840
}
41+
} catch (\ValueError $e) {
42+
echo $e->getMessage() . \PHP_EOL;
43+
}
3944
$iterator++;
4045
}
4146

@@ -44,10 +49,10 @@ foreach($options as $option) {
4449
<?php
4550
require_once(__DIR__.'/clean.inc');
4651
?>
47-
--EXPECTF--
52+
--EXPECT--
4853
*** Testing imap_fetchbody() : usage variations ***
4954
Create a temporary mailbox and add 1 msgs
50-
.. mailbox '{%s}%s' created
55+
.. mailbox '{127.0.0.1:143/norsh}INBOX.phpttest' created
5156

5257
-- Iteration 1 --
5358
FT_UID valid
@@ -62,11 +67,7 @@ FT_UID valid
6267
FT_UID valid
6368

6469
-- Iteration 5 --
65-
66-
Warning: imap_fetchbody(): Invalid value for the options parameter in %s on line %d
67-
FT_UID not valid
70+
imap_fetchbody(): Argument #4 ($options) must be a bitmask of FT_UID, FT_PEEK, and FT_INTERNAL
6871

6972
-- Iteration 6 --
70-
71-
Warning: imap_fetchbody(): Invalid value for the options parameter in %s on line %d
72-
FT_UID not valid
73+
imap_fetchbody(): Argument #4 ($options) must be a bitmask of FT_UID, FT_PEEK, and FT_INTERNAL

ext/imap/tests/imap_fetchbody_variation6.phpt

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ $sequences = [0, /* out of range */ 4, 1];
2323

2424
foreach($sequences as $msg_no) {
2525
echo "\n-- \$msg_no is $msg_no --\n";
26-
var_dump($overview = imap_fetchbody($stream_id, $msg_no, $section));
27-
if (!$overview) {
28-
echo imap_last_error() . "\n";
26+
try {
27+
var_dump(imap_fetchbody($stream_id, $msg_no, $section));
28+
} catch (\ValueError $e) {
29+
echo $e->getMessage() . \PHP_EOL;
2930
}
3031
}
3132
?>
@@ -39,17 +40,13 @@ Create a temporary mailbox and add 3 msgs
3940
.. mailbox '{%s}%s' created
4041

4142
-- $msg_no is 0 --
42-
43-
Warning: imap_fetchbody(): Bad message number in %s on line %d
44-
bool(false)
45-
43+
imap_fetchbody(): Argument #2 ($msg_no) must be greater than 0
4644

4745
-- $msg_no is 4 --
4846

4947
Warning: imap_fetchbody(): Bad message number in %s on line %d
5048
bool(false)
5149

52-
5350
-- $msg_no is 1 --
5451
string(42) "1: this is a test message, please ignore
5552
"

ext/imap/tests/imap_fetchheader_variation3.phpt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,26 @@ $iterator = 1;
3030
imap_check($stream_id);
3131
foreach($options as $option) {
3232
echo "\n-- Iteration $iterator --\n";
33-
if(is_string(imap_fetchheader($stream_id, $msg_uid, $option))) {
34-
echo "FT_UID valid\n";
35-
} else {
36-
echo "FT_UID not valid\n";
33+
try {
34+
if (is_string(imap_fetchheader($stream_id, $msg_uid, $option))) {
35+
echo "FT_UID valid\n";
36+
} else {
37+
echo "FT_UID not valid\n";
3738
}
39+
} catch (\ValueError $e) {
40+
echo $e->getMessage() . \PHP_EOL;
41+
}
3842
$iterator++;
3943
}
4044
?>
4145
--CLEAN--
4246
<?php
4347
require_once(__DIR__.'/clean.inc');
4448
?>
45-
--EXPECTF--
49+
--EXPECT--
4650
*** Testing imap_fetchheader() : usage variations ***
4751
Create a temporary mailbox and add 1 msgs
48-
.. mailbox '{%s}%s' created
52+
.. mailbox '{127.0.0.1:143/norsh}INBOX.phpttest' created
4953

5054
-- Iteration 1 --
5155
FT_UID valid
@@ -60,11 +64,7 @@ FT_UID valid
6064
FT_UID valid
6165

6266
-- Iteration 5 --
63-
64-
Warning: imap_fetchheader(): Invalid value for the options parameter in %s on line %d
65-
FT_UID not valid
67+
imap_fetchheader(): Argument #3 ($options) must be a bitmask of FT_UID, FT_PREFETCHTEXT, and FT_INTERNAL
6668

6769
-- Iteration 6 --
68-
69-
Warning: imap_fetchheader(): Invalid value for the options parameter in %s on line %d
70-
FT_UID not valid
70+
imap_fetchheader(): Argument #3 ($options) must be a bitmask of FT_UID, FT_PREFETCHTEXT, and FT_INTERNAL

ext/imap/tests/imap_fetchheader_variation5.phpt

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ $sequences = [0, /* out of range */ 4, 1];
2121

2222
foreach($sequences as $msg_no) {
2323
echo "\n-- \$msg_no is $msg_no --\n";
24-
var_dump($overview = imap_fetchheader($stream_id, $msg_no));
25-
if (!$overview) {
26-
echo imap_last_error() . "\n";
24+
try {
25+
var_dump(imap_fetchheader($stream_id, $msg_no));
26+
} catch (\ValueError $e) {
27+
echo $e->getMessage() . \PHP_EOL;
2728
}
2829
}
2930

@@ -40,17 +41,13 @@ Create a temporary mailbox and add 3 msgs
4041
.. mailbox '{%s}%s' created
4142

4243
-- $msg_no is 0 --
43-
44-
Warning: imap_fetchheader(): Bad message number in %s on line %d
45-
bool(false)
46-
44+
imap_fetchheader(): Argument #2 ($msg_no) must be greater than 0
4745

4846
-- $msg_no is 4 --
4947

5048
Warning: imap_fetchheader(): Bad message number in %s on line %d
5149
bool(false)
5250

53-
5451
-- $msg_no is 1 --
5552
string(%d) "From: foo@anywhere.com
5653
Subject: Test msg 1

ext/imap/tests/imap_fetchstructure_basic.phpt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ require_once(__DIR__.'/skipif.inc');
1212
require_once(__DIR__.'/imap_include.inc');
1313
$stream_id = setup_test_mailbox('', 1);
1414

15-
imap_fetchstructure($stream_id,0);
15+
try {
16+
imap_fetchstructure($stream_id,0);
17+
} catch (\ValueError $e) {
18+
echo $e->getMessage() . \PHP_EOL;
19+
}
1620

1721
$z = imap_fetchstructure($stream_id,1);
1822

@@ -39,6 +43,7 @@ require_once('clean.inc');
3943
--EXPECTF--
4044
Create a temporary mailbox and add 1 msgs
4145
.. mailbox '{127.0.0.1:143/norsh}INBOX.phpttest' created
46+
imap_fetchstructure(): Argument #2 ($msg_no) must be greater than 0
4247
bool(true)
4348
bool(true)
4449
bool(true)

ext/imap/tests/imap_gc_error.phpt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,13 @@ require_once(__DIR__.'/skipif.inc');
1313
require_once(__DIR__.'/imap_include.inc');
1414
$stream_id = imap_open($default_mailbox, $username, $password) or
1515
die("Cannot connect to mailbox $default_mailbox: " . imap_last_error());
16-
imap_gc($stream_id, -1);
16+
17+
try {
18+
imap_gc($stream_id, -1);
19+
} catch (\ValueError $e) {
20+
echo $e->getMessage() . \PHP_EOL;
21+
}
1722

1823
?>
19-
--EXPECTF--
20-
Warning: imap_gc(): Invalid value for the flags parameter in %s on line %d
24+
--EXPECT--
25+
imap_gc(): Argument #2 ($flags) must be a bitmask of IMAP_GC_TEXTS, IMAP_GC_ELT, and IMAP_GC_ENV

ext/imap/tests/imap_open_error.phpt

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
imap_open() incorrect parameter count
2+
imap_open() ValueErrors
33
--CREDITS--
44
Paul Sohier
55
#phptestfest utrecht
@@ -12,19 +12,27 @@ require_once(__DIR__.'/skipif.inc');
1212

1313
echo "Checking with incorrect parameters\n" ;
1414
imap_open('', '', '');
15-
imap_open('', '', '', -1);
15+
16+
try {
17+
imap_open('', '', '', -1);
18+
} catch (\ValueError $e) {
19+
echo $e->getMessage() . \PHP_EOL;
20+
}
1621

1722
require_once(__DIR__.'/imap_include.inc');
18-
imap_open($default_mailbox, $username, $password, NIL, -1);
23+
24+
try {
25+
imap_open($default_mailbox, $username, $password, NIL, -1);
26+
} catch (\ValueError $e) {
27+
echo $e->getMessage() . \PHP_EOL;
28+
}
1929

2030
?>
2131
--EXPECTF--
2232
Checking with incorrect parameters
2333

2434
Warning: imap_open(): Couldn't open stream in %s on line %d
25-
26-
Warning: imap_open(): Couldn't open stream in %s on line %d
27-
28-
Warning: imap_open(): Retries must be greater or equal to 0 in %s on line %d
35+
imap_open(): Argument #4 ($options) must be a bitmask of OP_READONLY, OP_ANONYMOUS, OP_HALFOPEN, CL_EXPUNGE, OP_DEBUG, OP_SHORTCACHE, OP_SILENT, OP_PROTOTYPE, and OP_SECURE
36+
imap_open(): Argument #5 ($n_retries) must be greater than or equal to 0
2937

3038
Notice: Unknown: Can't open mailbox : no such mailbox (errflg=2) in Unknown on line 0

0 commit comments

Comments
 (0)