Skip to content

Commit 4a36513

Browse files
committed
Merge branch 'PHP-8.2'
* PHP-8.2: Add a new imap_is_open() function to check that a connection object is still valid
2 parents f8ff105 + 52a891a commit 4a36513

File tree

4 files changed

+66
-5
lines changed

4 files changed

+66
-5
lines changed

ext/imap/php_imap.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,24 @@ PHP_FUNCTION(imap_reopen)
781781
}
782782
/* }}} */
783783

784+
PHP_FUNCTION(imap_is_open)
785+
{
786+
zval *imap_conn_obj;
787+
php_imap_object *imap_conn_struct;
788+
789+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &imap_conn_obj, php_imap_ce) == FAILURE) {
790+
RETURN_THROWS();
791+
}
792+
793+
/* Manual reimplementation of the GET_IMAP_STREAM() macro that doesn't throw */
794+
imap_conn_struct = imap_object_from_zend_object(Z_OBJ_P(imap_conn_obj));
795+
/* Stream was closed */
796+
if (imap_conn_struct->imap_stream == NULL) {
797+
RETURN_FALSE;
798+
}
799+
RETURN_TRUE;
800+
}
801+
784802
/* {{{ Append a new message to a specified mailbox */
785803
PHP_FUNCTION(imap_append)
786804
{

ext/imap/php_imap.stub.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,8 @@ function imap_reopen(IMAP\Connection $imap, string $mailbox, int $flags = 0, int
411411

412412
function imap_close(IMAP\Connection $imap, int $flags = 0): bool {}
413413

414+
function imap_is_open(IMAP\Connection $imap): bool {}
415+
414416
function imap_num_msg(IMAP\Connection $imap): int|false {}
415417

416418
function imap_num_recent(IMAP\Connection $imap): int {}

ext/imap/php_imap_arginfo.h

Lines changed: 9 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/imap/tests/imap_is_open.phpt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
--TEST--
2+
Test imap_is_open()
3+
--EXTENSIONS--
4+
imap
5+
--SKIPIF--
6+
<?php
7+
require_once(__DIR__.'/setup/skipif.inc');
8+
?>
9+
--FILE--
10+
<?php
11+
12+
// include file for required variables in imap_open()
13+
require_once(__DIR__.'/setup/imap_include.inc');
14+
15+
$mailbox_suffix = 'imapisopen';
16+
17+
// set up temp mailbox with 0 messages
18+
$stream_id = setup_test_mailbox($mailbox_suffix, 0, $mailbox);
19+
20+
var_dump(imap_is_open($stream_id));
21+
22+
// Close connection
23+
var_dump(imap_close($stream_id));
24+
var_dump(imap_is_open($stream_id));
25+
26+
?>
27+
--CLEAN--
28+
<?php
29+
$mailbox_suffix = 'imapisopen';
30+
require_once(__DIR__.'/setup/clean.inc');
31+
?>
32+
--EXPECT--
33+
Create a temporary mailbox and add 0 msgs
34+
New mailbox created
35+
bool(true)
36+
bool(true)
37+
bool(false)

0 commit comments

Comments
 (0)