Skip to content

Commit 52a891a

Browse files
committed
Add a new imap_is_open() function to check that a connection object is still valid
1 parent 4631e9d commit 52a891a

File tree

6 files changed

+73
-5
lines changed

6 files changed

+73
-5
lines changed

NEWS

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ PHP NEWS
2424
. Fixed bug GH-8517 (Random crash of FPM master process in
2525
fpm_stdio_child_said). (Jakub Zelenka)
2626

27+
- Imap:
28+
. Fixed bug GH-10051 (IMAP: there's no way to check if a IMAP\Connection is
29+
still open). (Girgias)
30+
2731
- MBString:
2832
. Fixed bug GH-9535 (The behavior of mb_strcut in mbstring has been changed in
2933
PHP8.1). (Nathan Freeman)

UPGRADING

+3
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,9 @@ PHP 8.2 UPGRADE NOTES
234234
- Curl:
235235
. curl_upkeep() (libcurl >= 7.62.0)
236236

237+
- IMAP:
238+
. imap_is_open() (Only as of PHP 8.2.1)
239+
237240
- mysqli:
238241
. mysqli_execute_query()
239242

ext/imap/php_imap.c

+18
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

+2
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

+9-5
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

+37
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)