Add Horde_Imap_Client_Utils::createUrl()
authorMichael M Slusarz <slusarz@curecanti.org>
Tue, 27 Oct 2009 23:05:15 +0000 (17:05 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Wed, 28 Oct 2009 00:44:20 +0000 (18:44 -0600)
framework/Imap_Client/lib/Horde/Imap/Client/Utils.php
framework/Imap_Client/package.xml

index 50ef1b2..239c70e 100644 (file)
@@ -335,6 +335,69 @@ class Horde_Imap_Client_Utils
     }
 
     /**
+     * Create a POP3 (RFC 2384) or IMAP (RFC 5092/5593) URL.
+     *
+     * @param array $data  The data used to create the URL. See the return
+     *                     value from parseUrl() for the available fields.
+     *                     REQUIRED: 'type', 'hostspec'
+     *
+     * @return string  A URL string.
+     */
+    public function createUrl($data)
+    {
+        $url = $data['type'] . '://';
+
+        if (isset($data['username'])) {
+            $url .= $data['username'];
+        }
+
+        if (isset($data['auth'])) {
+            $url .= ';AUTH=' . $data['auth'] . '@';
+        } elseif (isset($data['username'])) {
+            $url .= '@';
+        }
+
+        $url .= $data['hostspec'];
+
+        if (isset($data['port']) && ($data['port'] != 143)) {
+            $url .= ':' . $data['port'];
+        }
+
+        $url .= '/';
+
+        if ($data['type'] == 'imap') {
+            $url .= urlencode($data['mailbox']);
+
+            if (!empty($data['uidvalidity'])) {
+                $url .= ';UIDVALIDITY=' . $data['uidvalidity'];
+            }
+
+            if (isset($data['search'])) {
+                $url .= '?' . urlencode($data['search']);
+            } else {
+                if (isset($data['uid'])) {
+                    $url .= '/;UID=' . $data['uid'];
+                }
+
+                if (isset($data['section'])) {
+                    $url .= '/;SECTION=' . $data['section'];
+                }
+
+                if (isset($data['partial'])) {
+                    $url .= '/;PARTIAL=' . $data['partial'];
+                }
+
+                if (isset($data['urlauth'])) {
+                    $url .= '/;URLAUTH=' . $data['urlauth'];
+                }
+            }
+        }
+
+
+        return $url;
+    }
+
+    /**
      * Remove all prefix text of the subject that matches the subj-leader
      * ABNF.
      *
index 851a237..843a350 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>* Support SORT=DISPLAY extension.
+ <notes>* Add Horde_Imap_Client_Utils::createUrl().
+ * Support SORT=DISPLAY extension.
  * Added search and thread (message list) caching.
  * Added PHP socket based POP3 driver.
  * Initial release