Skip to content
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
18 changes: 18 additions & 0 deletions ext/imap/php_imap.c
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,24 @@ PHP_FUNCTION(imap_reopen)
}
/* }}} */

PHP_FUNCTION(imap_is_open)
{
zval *imap_conn_obj;
php_imap_object *imap_conn_struct;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &imap_conn_obj, php_imap_ce) == FAILURE) {
RETURN_THROWS();
}

/* Manual reimplementation of the GET_IMAP_STREAM() macro that doesn't throw */
imap_conn_struct = imap_object_from_zend_object(Z_OBJ_P(imap_conn_obj));
/* Stream was closed */
if (imap_conn_struct->imap_stream == NULL) {
RETURN_FALSE;
}
RETURN_TRUE;
}

/* {{{ Append a new message to a specified mailbox */
PHP_FUNCTION(imap_append)
{
Expand Down
2 changes: 2 additions & 0 deletions ext/imap/php_imap.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,8 @@ function imap_reopen(IMAP\Connection $imap, string $mailbox, int $flags = 0, int

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

function imap_is_open(IMAP\Connection $imap): bool {}

function imap_num_msg(IMAP\Connection $imap): int|false {}

function imap_num_recent(IMAP\Connection $imap): int {}
Expand Down
14 changes: 9 additions & 5 deletions ext/imap/php_imap_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions ext/imap/tests/imap_is_open.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
--TEST--
Test imap_is_open()
--EXTENSIONS--
imap
--SKIPIF--
<?php
require_once(__DIR__.'/setup/skipif.inc');
?>
--FILE--
<?php

// include file for required variables in imap_open()
require_once(__DIR__.'/setup/imap_include.inc');

$mailbox_suffix = 'imapisopen';

// set up temp mailbox with 0 messages
$stream_id = setup_test_mailbox($mailbox_suffix, 0, $mailbox);

var_dump(imap_is_open($stream_id));

// Close connection
var_dump(imap_close($stream_id));
var_dump(imap_is_open($stream_id));

?>
--CLEAN--
<?php
$mailbox_suffix = 'imapisopen';
require_once(__DIR__.'/setup/clean.inc');
?>
--EXPECT--
Create a temporary mailbox and add 0 msgs
New mailbox created
bool(true)
bool(true)
bool(false)