[imp] Namespace issues with Courier (was "How to set the IMAP path prefix in horde webmail 5.2?")

Quinn Comendant quinn at strangecode.com
Tue Feb 9 04:15:37 UTC 2016


An update…

Quoting Quinn Comendant <quinn at strangecode.com>:

> Does anybody know how to set the IMAP path prefix in the latest  
> horde/imp? I'm getting the error when creating folders, "The mailbox  
> 'Sent' was not created. This is what the server said: IMAP error  
> reported by server."


I believe the correct method of setting the IMAP path prefix is to  
define the following in backends.local.php:

     'namespace' => array('INBOX.'),

However, that alone has not solved the problem. I may have found  
issues with horde/imp or our server configuration. Now, even with the  
namespace specified thusly, IMP is still sending IMAP commands without  
the namespace (i.e., "CREATE Sent" instead of "CREATE INBOX.Sent").

I have read the source code of horde/imp and found the following  
changes were required for this to work:

## /var/www/html/horde/imp/lib/Imap.php : 474

The `getNamespace()` function defined here would return null when the  
specified mailbox was the default, despite `$this->getNamespaces()`  
returning a valid result. To solve this I added the following at line  
474:

     if ($mailbox === self::NS_DEFAULT && $ns->count() == 1) {
         return end(end($ns));
     }

## /usr/share/pear/Horde/Imap/Client/Base.php : 742

Here, the name of the namespace is an array and would result in an  
array-to-string conversion, with the resulting namespace name "Array"  
instead of the correct name "INBOX". I've added a tertiary clause to  
test if it is an array before assigning the value. Secondly, the  
namespace name lacking the delimiter would result in the use of folder  
names such as "INBOXSent" instead of "INBOX.Sent" (because in other  
parts of the code where the namespace is used the namespace is  
concatenated with the folder name with no delimiter), so I added the  
delimiter to the name here. The following is a modification of line 742:

     $ob->name = (is_array($val) ? end($val) : $val) . $val['delimiter'];

With these two changes, horde/imp is now successfully creating  
folders, displaying folders, auto-creating special folders, and moving  
messages between folders.

If I have discovered bugs in horde/imp 5.2, please let me know how  
best I can contribute these changes (pull request on github?) or if  
you  believe this is a problem with my Courier IMAP configuration, I  
would appreciate some help identifying if that may be the case.

Attached is IMP's imap log output during a successful folder creation  
operation (also so you can see imap capabilities, etc).

Regards,
Quinn
-------------- next part --------------
------------------------------
>> Mon, 08 Feb 2016 22:08:14 -0600
>> Connection to: imap://localhost:993/
>> Server connection took 0.0094 seconds.
S: * OK [CAPABILITY IMAP4rev1] Courier-IMAP ready. Copyright 1998-2005 Double Precision, Inc.  See COPYING for distribution information.
C: 1 LOGIN q at asdf.com [PASSWORD]
S: 1 OK LOGIN Ok.
>> Command 1 took 0.0381 seconds.
>> CACHE: Using the Horde_Imap_Client_Cache_Backend_Cache storage driver.
C: 2 LIST "" INBOX.
S: * LIST (\Marked \HasChildren) "." "INBOX"
S: 2 OK LIST completed
>> Command 2 took 0.077 seconds.
C: 3 LSUB "" "INBOX.New folder"
S: 3 OK LSUB completed
>> Command 3 took 0.0014 seconds.
C: 4 LIST "" "INBOX.New folder"
S: 4 OK LIST completed
>> Command 4 took 0.0006 seconds.
C: 5 CREATE "INBOX.New folder"
S: 5 OK "INBOX.New folder" created.
>> Command 5 took 0.0087 seconds.
C: 6 LSUB "" "INBOX.New folder"
S: 6 OK LSUB completed
>> Command 6 took 0.0003 seconds.
C: 7 LIST "" "INBOX.New folder"
S: * LIST (\HasNoChildren) "." "INBOX.New folder"
S: 7 OK LIST completed
>> Command 7 took 0.0008 seconds.
C: 8 LOGOUT
S: * BYE Courier-IMAP server shutting down
S: 8 OK LOGOUT completed
>> Command 8 took 0.0012 seconds.


More information about the imp mailing list