tedious / Fetch

An IMAP library for PHP

Home Page:http://www.tedivm.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Obtaining the IMAP directory separator character

benr77 opened this issue · comments

Is there any way to get the IMAP directory separator character? Usually it can be '.' or '/' but it varies from mailserver to mailserver.

I am writing an app that needs to create mailboxes on a variety of different mailservers so I need to programmatically extract this separator character so I can correctly construct the path to the new mailbox etc.

There isn't currently, but if you find a way to do it I'd be happy to include it.

Looking at the PHP IMAP docs, you can call imap_getmailboxes() which will return detailed info about the mailboxes, including the IMAP separator. http://php.net/manual/en/function.imap-getmailboxes.php

So you could easily expose this via a new public method alongside the existing public method listMailboxes(). Perhaps listMailboxDetails() or something.
If you directly return the return value from imap_getmailboxes() then the user can decide how to deal with the information provided as there is other useful stuff aside from the delimiter.

In the meantime, I have also implemented a quick and dirty solution using the existing listMailBox() method, which greps the value out of the list of returned mailboxes and child mailboxes - this is assuming that some child mailboxes exist, but normally a mailbox will have at least Trash, Sent etc

foreach ($imap->listMailBox() as $mailBox)
{
    $imapSeparator = preg_replace("#.*}\w+([/.]{1}).*#", "$1", $mailBox);
    if (strlen($imapSeparator) == 1) break;
}

Closing this out as I've merged the pull request.