#49425 [Opn->Csd]: imap_reopen() returns TRUE instead FALSE called with nonexistant mailbox

From: Date: Fri, 13 Nov 2009 22:29:14 +0000
Subject: #49425 [Opn->Csd]: imap_reopen() returns TRUE instead FALSE called with nonexistant mailbox
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-3148@lists.php.net to get a copy of this message
ID: 49425 Updated by: vrana@php.net Reported By: jake dot levitt at mailtrust dot com -Status: Open +Status: Closed Bug Type: Documentation problem Operating System: CentOS 5 PHP Version: 5.3.0 New Comment: This bug has been fixed in the documentation's XML sources. Since the online and downloadable versions of the documentation need some time to get updated, we would like to ask you to be a bit patient. Thank you for the report, and for helping us make our documentation better. "Returns TRUE if the stream is reopened, FALSE otherwise." Previous Comments: ------------------------------------------------------------------------ [2009-08-31 19:37:47] jake dot levitt at mailtrust dot com That may be how the function works, but it seems very misleading to me. imap_reopen() returns a boolean that is supposed to indicate success or failure of the imap_reopen() call. In this case that call is failing, so I think false should be returned. I don't think true should be returned to indicate that the mail resource is still valid, the user can determine that by calling imap_ping(). If you disagree with me then the documentation should at least be changed to indicate that the return value indicates the state of the mail resource and not the success or failure of the imap_reopen() call. ------------------------------------------------------------------------ [2009-08-31 19:29:56] jani@php.net Rephrasing a bit: The mailbox will be set to none, not the originally opened one.. ------------------------------------------------------------------------ [2009-08-31 19:24:37] jani@php.net Call to imap_reopen() with invalid mailbox does not close the already opened stream. mail_open() will not return NIL in such case, just sets the error and returns the original stream with the originally opened mailbox. As such, this is not a bug but undocumented "feature" of this function and should be documented on the imap_reopen() page. ------------------------------------------------------------------------ [2009-08-31 16:41:22] jake dot levitt at mailtrust dot com Description: ------------ When calling imap_reopen() on a folder that doesn't exist, the function returns true instead of the expected result of false. It seems this was reported back in 2002 but marked as bogus (http://bugs.php.net/bug.php?id=15197). I have reproduced this bug in the most recent version of php. Reproduce code: --------------- <?php $flags = '/novalidate-cert'; $host = 'imap.server.example.com:143'; $username = 'test.user@example.com'; $password = 'password'; $folder = 'INBOX'; $base_imap_string = '{' . $host . $flags . '}'; $connect_string = $base_imap_string . $folder; $mailbox = imap_open($connect_string, $username, $password, 0, 3); $connect_string = $base_imap_string . $folder . '.No such critter'; $reopen_success = imap_reopen($mailbox, $connect_string, 0, 3); $error_message = imap_last_error(); if (!$mailbox) { exit(0); } if ($reopen_success) { echo "Reopen SUCCEEDED and error message is: $error_message\n"; } else { echo "Reopen FAILED and error message is: $error_message\n"; } Expected result: ---------------- Output: Reopen FAILED and error message is: Mailbox doesn't exist: No such critter Actual result: -------------- Output: Reopen SUCCEEDED and error message is: Mailbox doesn't exist: No such critter ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=49425&edit=1

« previous php.doc.bugs (#3148) next »