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


From Zend_Mail_Storage_Imap code:

     * 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:

TAG2 LIST "INBOX.aaa" "*"
TAG2 OK LIST completed

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

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.

TAG4 LIST "INBOX" "aaa*"
* LIST (\HasNoChildren) "." "INBOX.aaa"

TAG5 OK "INBOX.aaa.bbb" created.

TAG6 LIST "INBOX" "aaa*"
* LIST (\HasNoChildren) "." "INBOX.aaa.bbb"
* LIST (\HasChildren) "." "INBOX.aaa"
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 "INBOX.aaa" "*"}}, then if empty, check whether the directory exists itself by doing {{LIST "INBOX" "aaa"}}


No comments to display