6.0.0-alpha14
7/3/25

[#14330] IMP sends IMAP commands without the namespace
Summary IMP sends IMAP commands without the namespace
Queue Horde Groupware Webmail Edition
Queue Version 5.2.0
Type Bug
State Resolved
Priority 3. High
Owners mrubinsk (at) horde (dot) org
Requester quinn (at) strangecode (dot) com
Created 04/15/2016 (3366 days ago)
Due
Updated 11/13/2017 (2789 days ago)
Assigned
Resolved 11/13/2017 (2789 days ago)
Github Issue Link
Github Pull Request
Milestone
Patch No

History
11/13/2017 03:15:15 AM Michael Rubinsky Comment #3
Assigned to Michael Rubinsky
State ⇒ Resolved
Reply to this comment
Going to assume this was fixed by this commit, as there was no feedback.
04/23/2016 06:33:57 AM Git Commit Comment #2 Reply to this comment
Changes have been made in Git (master):

commit d2d6fbbc8886d3e364debe6d431d9d014035cfa8
Author: Michael J Rubinsky <mrubinsk@horde.org>
Date:   Sat Apr 23 02:28:05 2016 -0400

     Fix returning a shared namespace name.

     HIC_Base::listMailboxes returns an array by default with the name in
     the key, and an array as the value. Possibly related to Bug: 14330.

  .../Imap_Client/lib/Horde/Imap/Client/Base.php     |    4 ++--
  1 files changed, 2 insertions(+), 2 deletions(-)

http://github.com/horde/horde/commit/d2d6fbbc8886d3e364debe6d431d9d014035cfa8
04/15/2016 02:06:33 AM quinn (at) strangecode (dot) com Comment #1
Priority ⇒ 3. High
Patch ⇒ No
Milestone ⇒
Queue ⇒ Horde Groupware Webmail Edition
Summary ⇒ IMP sends IMAP commands without the namespace
Type ⇒ Bug
State ⇒ Unconfirmed
Reply to this comment
I have had difficulty setting the IMAP path prefix in horde webmail 
5.2 on a CentOS 6 server running Courier-IMAP 4.1.2. When creating 
folders I was getting the error, "The mailbox 'New folder' was not 
created. This is what the server said: IMAP error reported by server."

The imp_imap debug log shows that it is trying to create folders
without the `INBOX.` prefix, which I think is the reason it is failing:

        S: * OK [CAPABILITY IMAP4rev1] Courier-IMAP ready. Copyright 1998-2005
        Double Precision, Inc.  See COPYING for distribution information.
        C: 1 LOGIN quinn@example.com [PASSWORD]
        S: 1 OK LOGIN Ok.
        C: 2 LSUB "" New folder
        S: 2 OK LSUB completed
        C: 3 LIST "" New folder
        S: 3 OK LIST completed
        C: 4 CREATE New folder
        S: 4 NO Invalid mailbox name.
        C: 5 LOGOUT
        S: * BYE Courier-IMAP server shutting down
        S: 5 OK LOGOUT completed

I *am* able to create a folder if I manually include the IMAP prefix
to its name, i.e. I go to Folder Actions > Create Mailbox and then use
a folder name literally as `INBOX.New folder`. The new folder is created
with that name literally and `INBOX.New folder` is created on the server and
is displayed in IMP's sidebar. =\

As far as I can tell, this is configured using the 'namespace' option
in backends.local.php, but I have tried the following variations with
no success:

      'namespace' => array('INBOX.')
      'namespace' => array('#INBOX.')
      'namespace' => array('INBOX/')
      'namespace' => array('#INBOX/')

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 New folder` instead of `CREATE INBOX.New 
folder`).

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 `INBOXNew folder` instead of `INBOX.New folder` (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. The IMAP transactions now send the prefix 
correctly:

        S: * OK [CAPABILITY IMAP4rev1] Courier-IMAP ready. Copyright 
1998-2005 Double Precision, Inc.  See COPYING for distribution 
information.
        C: 1 LOGIN q@asdf.com [PASSWORD]
        S: 1 OK LOGIN Ok.
        C: 2 LIST "" INBOX.
        S: * LIST (\Marked \HasChildren) "." "INBOX"
        S: 2 OK LIST completed
        C: 3 LSUB "" "INBOX.New folder"
        S: 3 OK LSUB completed
        C: 4 LIST "" "INBOX.New folder"
        S: 4 OK LIST completed
        C: 5 CREATE "INBOX.New folder"
        S: 5 OK "INBOX.New folder" created.
        C: 6 LSUB "" "INBOX.New folder"
        S: 6 OK LSUB completed
        C: 7 LIST "" "INBOX.New folder"
        S: * LIST (\HasNoChildren) "." "INBOX.New folder"
        S: 7 OK LIST completed
        C: 8 LOGOUT
        S: * BYE Courier-IMAP server shutting down
        S: 8 OK LOGOUT completed

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.

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

------------------------------
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@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.

Saved Queries