Add support for special-use mailboxes (draft-ietf-morg-list-specialuse-02)
authorMichael M Slusarz <slusarz@curecanti.org>
Fri, 20 Aug 2010 21:43:12 +0000 (15:43 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Fri, 20 Aug 2010 21:43:12 +0000 (15:43 -0600)
framework/Imap_Client/lib/Horde/Imap/Client/Base.php
framework/Imap_Client/lib/Horde/Imap/Client/Cclient.php
framework/Imap_Client/lib/Horde/Imap/Client/Cclient/Pop3.php
framework/Imap_Client/lib/Horde/Imap/Client/Mock.php
framework/Imap_Client/lib/Horde/Imap/Client/Socket.php
framework/Imap_Client/lib/Horde/Imap/Client/Socket/Pop3.php
framework/Imap_Client/package.xml

index 682c6d4..1403c77 100644 (file)
@@ -695,22 +695,33 @@ abstract class Horde_Imap_Client_Base
      *
      * @param string $mailbox  The mailbox to create. Either in UTF7-IMAP or
      *                         UTF-8.
+     * @param array $opts      Additional options:
+     * <pre>
+     * 'special_use' - (array) An array of special-use flags to mark the
+     *                 mailbox with.  The server must support broadcast the
+     *                 CREATE-SPECIAL-USE capability string.
+     * </pre>
      *
      * @throws Horde_Imap_Client_Exception
      */
-    public function createMailbox($mailbox)
+    public function createMailbox($mailbox, array $opts = array())
     {
-        $this->_createMailbox(Horde_Imap_Client_Utf7imap::Utf8ToUtf7Imap($mailbox));
+        if (!$this->queryCapability('CREATE-SPECIAL-USE')) {
+            unset($opts['special_use']);
+        }
+
+        $this->_createMailbox(Horde_Imap_Client_Utf7imap::Utf8ToUtf7Imap($mailbox), $opts);
     }
 
     /**
      * Create a mailbox.
      *
      * @param string $mailbox  The mailbox to create (UTF7-IMAP).
+     * @param array $opts      Additional options. See self::createMailbox().
      *
      * @throws Horde_Imap_Client_Exception
      */
-    abstract protected function _createMailbox($mailbox);
+    abstract protected function _createMailbox($mailbox, $opts);
 
     /**
      * Delete a mailbox.
@@ -859,6 +870,14 @@ abstract class Horde_Imap_Client_Base
      * 'remote' - (boolean) Tell server to return mailboxes that reside on
      *            another server. Requires the LIST-EXTENDED extension.
      *            DEFAULT: false
+     * 'special_use' - (boolean) Tell server to return special-use attribute
+     *                 information (\Drafts, \Flagged, \Junk, \Sent, \Trash,
+     *                 \All, \Archive)). Server must support the SPECIAL-USE
+     *                 return option for this setting to have any effect.
+     *                 Server MAY return this attribute without this option.
+     *                 Aidditionaly, server SHOULD return this information if
+     *                 this option is given, but it is not guaranteed.
+     *                 DEFAULT: false
      * 'status' - (integer) Tell server to return status information. The
      *            value is a bitmask that may contain the following:
      *            Horde_Imap_Client::STATUS_MESSAGES,
index 27aff24..462e295 100644 (file)
@@ -340,11 +340,17 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
      * Create a mailbox.
      *
      * @param string $mailbox  The mailbox to create (UTF7-IMAP).
+     * @param array $opts      Additional options. See self::createMailbox().
      *
      * @throws Horde_Imap_Client_Exception
      */
-    protected function _createMailbox($mailbox)
+    protected function _createMailbox($mailbox, $opts)
     {
+        if (isset($opts['special_use'])) {
+            $this->_getSocket()->createMailbox($mailbox, $opts);
+            return;
+        }
+
         $this->login();
 
         $old_error = error_reporting(0);
index 569c7c8..8e33ca1 100644 (file)
@@ -125,10 +125,11 @@ class Horde_Imap_Client_Cclient_Pop3 extends Horde_Imap_Client_Cclient
      * Create a mailbox.
      *
      * @param string $mailbox  The mailbox to create (UTF7-IMAP).
+     * @param array $opts      Additional options. See self::createMailbox().
      *
      * @throws Horde_Imap_Client_Exception
      */
-    protected function _createMailbox($mailbox)
+    protected function _createMailbox($mailbox, $opts)
     {
         throw new Horde_Imap_Client_Exception('Creating mailboxes not supported on POP3 servers.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED);
     }
index 1ef5262..c87980a 100644 (file)
@@ -297,11 +297,13 @@ class Horde_Imap_Client_Mock extends Horde_Imap_Client_Base
     /**
      * Create a mailbox.
      *
-     * @param string $mailbox The mailbox to create (UTF7-IMAP).
+     * @param string $mailbox  The mailbox to create (UTF7-IMAP).
+     * @param array $opts      Additional options. See self::createMailbox().
+     *
      *
      * @throws Horde_Imap_Client_Exception
      */
-    protected function _createMailbox($mailbox)
+    protected function _createMailbox($mailbox, $opts)
     {
         $mailbox = $this->_parseFolder($mailbox);
         if (isset(self::$storage[$mailbox])) {
index ca7fbac..03fc67a 100644 (file)
@@ -40,8 +40,9 @@
  *   RFC 5530 - IMAP Response Codes
  *   RFC 5819 - LIST-STATUS
  *
- *   draft-ietf-morg-sortdisplay-02     SORT=DISPLAY
- *   draft-ietf-morg-inthread-00        THREAD=REFS
+ *   draft-ietf-morg-list-specialuse-02  CREATE-SPECIAL-USE
+ *   draft-ietf-morg-sortdisplay-02      SORT=DISPLAY
+ *   draft-ietf-morg-inthread-00         THREAD=REFS
  *
  *   [NO RFC] - XIMAPPROXY
  *       + Requires imapproxy v1.2.7-rc1 or later
@@ -905,18 +906,31 @@ class Horde_Imap_Client_Socket extends Horde_Imap_Client_Base
      * Create a mailbox.
      *
      * @param string $mailbox  The mailbox to create (UTF7-IMAP).
+     * @param array $opts      Additional options. See self::createMailbox().
      *
      * @throws Horde_Imap_Client_Exception
      */
-    protected function _createMailbox($mailbox)
+    protected function _createMailbox($mailbox, $opts)
     {
         $this->login();
 
-        // CREATE returns no untagged information (RFC 3501 [6.3.3])
-        $this->_sendLine(array(
+        $cmd = array(
             'CREATE',
             array('t' => Horde_Imap_Client::DATA_MAILBOX, 'v' => $mailbox)
-        ));
+        );
+
+        if (isset($opts['special_use'])) {
+            $cmd[] = 'USE';
+
+            $flags = array();
+            foreach ($opts['special_use'] as $val) {
+                $flags[] = array('t' => Horde_Imap_Client::DATA_ATOM, 'v' => $val);
+            }
+            $cmd[] = $flags;
+        }
+
+        // CREATE returns no untagged information (RFC 3501 [6.3.3])
+        $this->_sendLine($cmd);
     }
 
     /**
@@ -1083,6 +1097,10 @@ class Horde_Imap_Client_Socket extends Horde_Imap_Client_Base
                 $select_opts[] = 'RECURSIVEMATCH';
             }
 
+            if (!empty($options['special_use'])) {
+                $select_opts[] = 'SPECIAL-USE';
+            }
+
             if (!empty($select_opts)) {
                 $cmd[] = $select_opts;
             }
index 178f789..6a9535e 100644 (file)
@@ -453,10 +453,11 @@ class Horde_Imap_Client_Socket_Pop3 extends Horde_Imap_Client_Base
      * Create a mailbox.
      *
      * @param string $mailbox  The mailbox to create (UTF7-IMAP).
+     * @param array $opts      Additional options. See self::createMailbox().
      *
      * @throws Horde_Imap_Client_Exception
      */
-    protected function _createMailbox($mailbox)
+    protected function _createMailbox($mailbox, $opts)
     {
         throw new Horde_Imap_Client_Exception('Creating mailboxes not supported on POP3 servers.', Horde_Imap_Client_Exception::POP3_NOTSUPPORTED);
     }
index d30f63f..98c0424 100644 (file)
@@ -31,7 +31,8 @@ http://pear.php.net/dtd/package-2.0.xsd">
   <api>alpha</api>
  </stability>
  <license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
- <notes>* Add Horde_Imap_Client_Base::validSearchCharset().
+ <notes>* Add support for special-use mailboxes (draft-ietf-morg-list-specialuse-02).
+ * Add Horde_Imap_Client_Base::validSearchCharset().
  * Add Horde_Imap_Client_Base::fetchFromSectionString().
  * Add support for RFC 4469 (CATENATE).
  * Correctly output 8-bit strings (RFC 3501 [4.3]).