ZF-9632: Zend_Mail_Storage_Imap::getFolders() throws an exception when there is no subfolders in the mailbox

Issue Type: Bug Created: 2010-04-07T08:30:34.000+0000 Last Updated: 2012-11-20T21:38:07.000+0000 Status: Open Fix version(s): Reporter: Maciej Wiercinski (mwiercinski) Assignee: None Tags: - Zend_Mail_Storage

Related issues: Attachments:


From Zend_Mail_Storage_Imap code:

<pre class="highlight">
     * get root folder or given folder
     * @param  string $rootFolder get folder structure for given folder, else root
     * @return Zend_Mail_Storage_Folder root or wanted folder
     * @throws Zend_Mail_Storage_Exception
     * @throws Zend_Mail_Protocol_Exception
    public function getFolders($rootFolder = null)
        $folders = $this->_protocol->listMailbox((string)$rootFolder);
        if (!$folders) {
             * @see Zend_Mail_Storage_Exception
            require_once 'Zend/Mail/Storage/Exception.php';
            throw new Zend_Mail_Storage_Exception('folder not found');

When mailbox pointed by $rootFolder is empty (has no subdirectories), it throws an exception. I reckon it should return an empty iterator instead.

The IMAP chat the code would result with:

<pre class="literal">
TAG2 LIST "" "*"
TAG2 OK LIST completed

The IMAP implementation I was testing it against (courier) does not indicate errors if queried for inexistent folder

<pre class="literal">
TAG3 LIST "INBOX.this.does.not.exist" "*"
TAG3 OK LIST completed

It is possible, though, to list the contents of the inbox by querying parent directory with an appropriate wildcard, and then parse the data.

<pre class="literal">
TAG4 LIST "INBOX" "aaa*"
* LIST (\HasNoChildren) "." ""

TAG5 OK "" created.

TAG6 LIST "INBOX" "aaa*"
* LIST (\HasNoChildren) "." ""
* LIST (\HasChildren) "." ""
TAG6 OK LIST completed

Possible drawbacks I could imagine is having multiple directories matching the pattern resulting in unnecessary data being sent across the network & processed (in example above it would list all directories starting with aaa).

Other possible solution is to have two step process:

LIST "" "*", then if empty, check whether the directory exists itself by doing LIST "INBOX" "aaa"


No comments to display

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.