php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #18282 imap_open return doesn't return FALSE when mailbox doesn't exist
Submitted: 2002-07-11 14:12 UTC Modified: 2002-07-12 20:10 UTC
From: valerio at dei dot unipd dot it Assigned:
Status: Not a bug Package: IMAP related
PHP Version: 4.2.1 OS: Linux
Private report: No CVE-ID: None
 [2002-07-11 14:12 UTC] valerio at dei dot unipd dot it
imap_open($server_strings.$mailbox, $username,$passwd,$options)
should return FALSE when username/password are correct
but mailbox doesn't exist.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-07-11 14:21 UTC] sniper@php.net
Please give us a short but complete example script
which can be used to reproduce this..


 [2002-07-12 04:22 UTC] valerio at dei dot unipd dot it
This script output nothing (I mean _nothing_) when mailbox
with name "this_file_doesnt_exist" isn't there.

<?php
print "BEFORE IMAP_OPEN<br>";
$my_stream=imap_open("{localhost:143}this_file_doesnt_exist","realusername", "rightpassword",OP_READONLY);
if ($my_stream) {
/* uncomment me if you want to see $my_stream value */
/*print $my_stream; */
$barney=imap_fetchbody($my_stream,1,"1");    
print $barney;
imap_close($my_stream);
}
print "AFTER IMAP_OPEN<br>";
?>

My current workaround is a imap_open("{localhost:143}",...,OP_HALFOPEN), imap_listmailbox and comparison on all values to check the existence of a particular mailbox name before opening it.
 [2002-07-12 04:32 UTC] sniper@php.net
Your 'workaround' really is the correct way to do it..
In your test script, the connection is established,
just the mailbox select fails.

Try add this right after the imap_open() line:

  echo imap_last_error();




 [2002-07-12 05:20 UTC] valerio at dei dot unipd dot it
Sorry, but I don't think so.
The function names are imap_open() and imap_reopen not imap_connect().
If mailbox doesn't exist imap_lasterror() return an useless nil.
During an IMAP transaction when you act a "SELECT" on a
unexisting mailbox you get an error:
. select alskj
. NO SELECT failed: Can't open mailbox alskj: no such mailbox

Probably there is a weakness in how open_mail() in lib c-client return streams.
Talking about my workaround ... suppose you have thousands
of mailbox...it's not so optimized to check all of them just to open one.
Then suppose that between imap_listbox and imap_reopen the file vanished. What would you get? The script output an empty page.
Regards
	Valerio
 [2002-07-12 20:10 UTC] sniper@php.net
Yes, it's c-client thing. Not much we can do about that.

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 13:01:29 2024 UTC