Skip to content

Commit d188ee2

Browse files
committed
This also affects imap_reopen()
1 parent b59a58e commit d188ee2

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

ext/imap/php_imap.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,11 @@ PHP_FUNCTION(imap_reopen)
905905
GET_IMAP_STREAM(imap_conn_struct, imap_conn_obj);
906906

907907
/* TODO Verify these are the only options available as they are pulled from the php.net documentation */
908-
if (options && ((options & ~(OP_READONLY | OP_ANONYMOUS | OP_HALFOPEN | OP_EXPUNGE | CL_EXPUNGE)) != 0)) {
908+
/* Check for PHP_EXPUNGE and not CL_EXPUNGE as the user land facing CL_EXPUNGE constant is defined
909+
* to something different to prevent clashes between CL_EXPUNGE and an OP_* constant allowing setting
910+
* the CL_EXPUNGE flag which will expunge when the mailbox is closed (be that manually, or via the
911+
* IMAPConnection object being destroyed naturally at the end of the PHP script */
912+
if (options && ((options & ~(OP_READONLY | OP_ANONYMOUS | OP_HALFOPEN | OP_EXPUNGE | PHP_EXPUNGE)) != 0)) {
909913
zend_argument_value_error(3, "must be a bitmask of OP_READONLY, OP_ANONYMOUS, OP_HALFOPEN, "
910914
"OP_EXPUNGE, and CL_EXPUNGE");
911915
RETURN_THROWS();

ext/imap/tests/bug80800.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ require_once(__DIR__.'/setup/skipif.inc');
1010
require_once __DIR__.'/setup/imap_include.inc';
1111

1212
$mail_box = imap_open(IMAP_DEFAULT_MAILBOX, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_PASSWORD, flags: CL_EXPUNGE);
13+
var_dump(imap_reopen($mail_box, IMAP_DEFAULT_MAILBOX, flags: CL_EXPUNGE));
1314
imap_close($mail_box);
1415

1516
echo 'Connected without any issues', "\n";
1617

1718
?>
1819
--EXPECT--
20+
bool(true)
1921
Connected without any issues
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
--TEST--
2+
Test imap_reopen() using the CL_EXPUNGE flag
3+
--SKIPIF--
4+
<?php
5+
require_once(__DIR__.'/setup/skipif.inc');
6+
?>
7+
--FILE--
8+
<?php
9+
10+
// include file for required variables in imap_open()
11+
require_once(__DIR__.'/setup/imap_include.inc');
12+
13+
$mailbox_suffix = 'imapreopenwithclexpunge';
14+
15+
// set up temp mailbox with 3 messages
16+
$stream_id = setup_test_mailbox($mailbox_suffix , 3, $mailbox);
17+
18+
var_dump(imap_reopen($stream_id, IMAP_DEFAULT_MAILBOX . '.' . IMAP_MAILBOX_PHPT_PREFIX . $mailbox_suffix, flags: CL_EXPUNGE));
19+
20+
// mark messages in inbox for deletion
21+
for ($i = 1; $i < 4; $i++) {
22+
imap_delete($stream_id, $i);
23+
}
24+
25+
echo "\n-- Call to imap_close() --\n";
26+
var_dump( imap_close($stream_id) );
27+
28+
// check that CL_EXPUNGE in previous imap_reopen() call worked
29+
$stream_id = imap_open($mailbox, IMAP_MAILBOX_USERNAME, IMAP_MAILBOX_PASSWORD);
30+
echo "There are now " . imap_num_msg($stream_id) . " msgs in mailbox '$mailbox'\n";
31+
32+
// Close connection
33+
var_dump( imap_close($stream_id) );
34+
?>
35+
--CLEAN--
36+
<?php
37+
$mailbox_suffix = 'imapreopenwithclexpunge';
38+
require_once(__DIR__.'/setup/clean.inc');
39+
?>
40+
--EXPECTF--
41+
Create a temporary mailbox and add 3 msgs
42+
New mailbox created
43+
44+
-- Call to imap_close() --
45+
bool(true)
46+
There are now 0 msgs in mailbox '%sINBOX.phpttestimapclosebasic'
47+
bool(true)

0 commit comments

Comments
 (0)