Skip to content

Promote warnings to Error in IMAP #6164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
432 changes: 254 additions & 178 deletions ext/imap/php_imap.c

Large diffs are not rendered by default.

23 changes: 15 additions & 8 deletions ext/imap/tests/imap_body.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
imap_body() incorrect parameter count
imap_body() ValueError
--CREDITS--
Paul Sohier
#phptestfest utrecht
Expand All @@ -14,19 +14,26 @@ require_once(__DIR__.'/imap_include.inc');
$stream_id = imap_open($default_mailbox, $username, $password) or
die("Cannot connect to mailbox $default_mailbox: " . imap_last_error());

imap_body($stream_id,-1);
imap_body($stream_id,1,-1);
try {
imap_body($stream_id,-1);
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
}
try {
imap_body($stream_id,1,-1);
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
}

//Access not existing
var_dump(imap_body($stream_id, 999, FT_UID));
var_dump(imap_body($stream_id, 255, FT_UID));

imap_close($stream_id);

?>
--EXPECTF--
Warning: imap_body(): Bad message number in %s on line %d
imap_body(): Argument #2 ($msg_no) must be greater than 0
imap_body(): Argument #3 ($options) must be a bitmask of FT_UID, FT_PEEK, and FT_INTERNAL

Warning: imap_body(): Invalid value for the options parameter in %s on line %d

Warning: imap_body(): Bad message number in %s on line %d
Warning: imap_body(): UID does not exist in %s on line %d
bool(false)
19 changes: 9 additions & 10 deletions ext/imap/tests/imap_close_variation4.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ foreach($inputs as $input) {
imap_delete($stream_id, $i);
}
echo "\n-- Iteration $iterator --\n";
var_dump( $check = imap_close($stream_id, $input) );
try {
var_dump( $check = imap_close($stream_id, $input) );
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
$check = false;
}

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

-- Iteration 3 --

Warning: imap_close(): Invalid value for the flags parameter in %s on line %d
bool(false)
imap_close(): Argument #2 ($options) must be CL_EXPUNGE or 0

-- Iteration 4 --

Warning: imap_close(): Invalid value for the flags parameter in %s on line %d
bool(false)
imap_close(): Argument #2 ($options) must be CL_EXPUNGE or 0

-- Iteration 5 --

Warning: imap_close(): Invalid value for the flags parameter in %s on line %d
bool(false)
imap_close(): Argument #2 ($options) must be CL_EXPUNGE or 0
29 changes: 12 additions & 17 deletions ext/imap/tests/imap_fetch_overview_variation3.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,32 @@ $options = array ('1',
true,
1.000000000000001,
0.00001e5,
PHP_INT_MAX,
-PHP_INT_MAX
245
);

// iterate over each element of $options array
$iterator = 1;
imap_check($stream_id);
foreach($options as $option) {
echo "\nTesting with option value:";
var_dump($option);
$overview = imap_fetch_overview($stream_id, $msg_uid, $option);
if ($overview) {
echo "imap_fetch_overview() returns an object\n";
try {
$overview = imap_fetch_overview($stream_id, $msg_uid, $option);
if ($overview) {
echo "imap_fetch_overview() returns an object\n";
}
$iterator++;
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
}
}

?>
--CLEAN--
<?php
require_once(__DIR__.'/clean.inc');
?>
--EXPECTF--
--EXPECT--
*** Testing imap_fetch_overview() : usage variations ***
Create a temporary mailbox and add 1 msgs
.. mailbox '{%s}%s' created
.. mailbox '{127.0.0.1:143/norsh}INBOX.phpttest' created
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wildcard got lost.


Testing with option value:string(1) "1"
imap_fetch_overview() returns an object
Expand All @@ -64,10 +64,5 @@ imap_fetch_overview() returns an object
Testing with option value:float(1)
imap_fetch_overview() returns an object

Testing with option value:int(%d)

Warning: imap_fetch_overview(): Invalid value for the options parameter in %s on line %d

Testing with option value:int(-%d)

Warning: imap_fetch_overview(): Invalid value for the options parameter in %s on line %d
Testing with option value:int(245)
imap_fetch_overview(): Argument #3 ($options) must be FT_UID or 0
25 changes: 13 additions & 12 deletions ext/imap/tests/imap_fetchbody_variation4.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,16 @@ $iterator = 1;
imap_check($stream_id);
foreach($options as $option) {
echo "\n-- Iteration $iterator --\n";
if(is_string(imap_fetchbody($stream_id, $msg_uid, $section, $option))) {
echo "FT_UID valid\n";
} else {
echo "FT_UID not valid\n";

try {
if(is_string(imap_fetchbody($stream_id, $msg_uid, $section, $option))) {
echo "FT_UID valid\n";
} else {
echo "FT_UID not valid\n";
}
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
}
$iterator++;
}

Expand All @@ -44,10 +49,10 @@ foreach($options as $option) {
<?php
require_once(__DIR__.'/clean.inc');
?>
--EXPECTF--
--EXPECT--
*** Testing imap_fetchbody() : usage variations ***
Create a temporary mailbox and add 1 msgs
.. mailbox '{%s}%s' created
.. mailbox '{127.0.0.1:143/norsh}INBOX.phpttest' created
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wildcard got lost.


-- Iteration 1 --
FT_UID valid
Expand All @@ -62,11 +67,7 @@ FT_UID valid
FT_UID valid

-- Iteration 5 --

Warning: imap_fetchbody(): Invalid value for the options parameter in %s on line %d
FT_UID not valid
imap_fetchbody(): Argument #4 ($options) must be a bitmask of FT_UID, FT_PEEK, and FT_INTERNAL

-- Iteration 6 --

Warning: imap_fetchbody(): Invalid value for the options parameter in %s on line %d
FT_UID not valid
imap_fetchbody(): Argument #4 ($options) must be a bitmask of FT_UID, FT_PEEK, and FT_INTERNAL
13 changes: 5 additions & 8 deletions ext/imap/tests/imap_fetchbody_variation6.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ $sequences = [0, /* out of range */ 4, 1];

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

-- $msg_no is 0 --

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

imap_fetchbody(): Argument #2 ($msg_no) must be greater than 0

-- $msg_no is 4 --

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


-- $msg_no is 1 --
string(42) "1: this is a test message, please ignore
"
24 changes: 12 additions & 12 deletions ext/imap/tests/imap_fetchheader_variation3.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,26 @@ $iterator = 1;
imap_check($stream_id);
foreach($options as $option) {
echo "\n-- Iteration $iterator --\n";
if(is_string(imap_fetchheader($stream_id, $msg_uid, $option))) {
echo "FT_UID valid\n";
} else {
echo "FT_UID not valid\n";
try {
if (is_string(imap_fetchheader($stream_id, $msg_uid, $option))) {
echo "FT_UID valid\n";
} else {
echo "FT_UID not valid\n";
}
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
}
$iterator++;
}
?>
--CLEAN--
<?php
require_once(__DIR__.'/clean.inc');
?>
--EXPECTF--
--EXPECT--
*** Testing imap_fetchheader() : usage variations ***
Create a temporary mailbox and add 1 msgs
.. mailbox '{%s}%s' created
.. mailbox '{127.0.0.1:143/norsh}INBOX.phpttest' created
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wildcard got lost.


-- Iteration 1 --
FT_UID valid
Expand All @@ -60,11 +64,7 @@ FT_UID valid
FT_UID valid

-- Iteration 5 --

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

-- Iteration 6 --

Warning: imap_fetchheader(): Invalid value for the options parameter in %s on line %d
FT_UID not valid
imap_fetchheader(): Argument #3 ($options) must be a bitmask of FT_UID, FT_PREFETCHTEXT, and FT_INTERNAL
13 changes: 5 additions & 8 deletions ext/imap/tests/imap_fetchheader_variation5.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ $sequences = [0, /* out of range */ 4, 1];

foreach($sequences as $msg_no) {
echo "\n-- \$msg_no is $msg_no --\n";
var_dump($overview = imap_fetchheader($stream_id, $msg_no));
if (!$overview) {
echo imap_last_error() . "\n";
try {
var_dump(imap_fetchheader($stream_id, $msg_no));
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
}
}

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

-- $msg_no is 0 --

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

imap_fetchheader(): Argument #2 ($msg_no) must be greater than 0

-- $msg_no is 4 --

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


-- $msg_no is 1 --
string(%d) "From: foo@anywhere.com
Subject: Test msg 1
Expand Down
7 changes: 6 additions & 1 deletion ext/imap/tests/imap_fetchstructure_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ require_once(__DIR__.'/skipif.inc');
require_once(__DIR__.'/imap_include.inc');
$stream_id = setup_test_mailbox('', 1);

imap_fetchstructure($stream_id,0);
try {
imap_fetchstructure($stream_id,0);
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
}

$z = imap_fetchstructure($stream_id,1);

Expand All @@ -39,6 +43,7 @@ require_once('clean.inc');
--EXPECTF--
Create a temporary mailbox and add 1 msgs
.. mailbox '{127.0.0.1:143/norsh}INBOX.phpttest' created
imap_fetchstructure(): Argument #2 ($msg_no) must be greater than 0
bool(true)
bool(true)
bool(true)
Expand Down
11 changes: 8 additions & 3 deletions ext/imap/tests/imap_gc_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ require_once(__DIR__.'/skipif.inc');
require_once(__DIR__.'/imap_include.inc');
$stream_id = imap_open($default_mailbox, $username, $password) or
die("Cannot connect to mailbox $default_mailbox: " . imap_last_error());
imap_gc($stream_id, -1);

try {
imap_gc($stream_id, -1);
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
}

?>
--EXPECTF--
Warning: imap_gc(): Invalid value for the flags parameter in %s on line %d
--EXPECT--
imap_gc(): Argument #2 ($flags) must be a bitmask of IMAP_GC_TEXTS, IMAP_GC_ELT, and IMAP_GC_ENV
22 changes: 15 additions & 7 deletions ext/imap/tests/imap_open_error.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
imap_open() incorrect parameter count
imap_open() ValueErrors
--CREDITS--
Paul Sohier
#phptestfest utrecht
Expand All @@ -12,19 +12,27 @@ require_once(__DIR__.'/skipif.inc');

echo "Checking with incorrect parameters\n" ;
imap_open('', '', '');
imap_open('', '', '', -1);

try {
imap_open('', '', '', -1);
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
}

require_once(__DIR__.'/imap_include.inc');
imap_open($default_mailbox, $username, $password, NIL, -1);

try {
imap_open($default_mailbox, $username, $password, NIL, -1);
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
}

?>
--EXPECTF--
Checking with incorrect parameters

Warning: imap_open(): Couldn't open stream in %s on line %d

Warning: imap_open(): Couldn't open stream in %s on line %d

Warning: imap_open(): Retries must be greater or equal to 0 in %s on line %d
imap_open(): Argument #4 ($options) must be a bitmask of the OP_* constants, and CL_EXPUNGE
imap_open(): Argument #5 ($n_retries) must be greater than or equal to 0

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