php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #49425 imap_reopen() returns TRUE instead FALSE called with nonexistant mailbox
Submitted: 2009-08-31 16:41 UTC Modified: 2009-11-13 22:29 UTC
From: jake dot levitt at mailtrust dot com Assigned:
Status: Closed Package: Documentation problem
PHP Version: 5.3.0 OS: CentOS 5
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jake dot levitt at mailtrust dot com
New email:
PHP Version: OS:

 

 [2009-08-31 16:41 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-08-31 19:24 UTC] 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 19:29 UTC] jani@php.net
Rephrasing a bit: The mailbox will be set to none, not the originally 
opened one..
 [2009-08-31 19:37 UTC] 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-11-13 22:29 UTC] vrana@php.net
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."
 [2009-11-13 22:29 UTC] svn@php.net
Automatic comment from SVN on behalf of vrana
Revision: http://svn.php.net/viewvc/?view=revision&revision=290715
Log: Return value (bug #49425)
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Dec 05 08:00:02 2025 UTC