Index: package.xml
===================================================================
RCS file: /repository/framework/Kolab/package.xml,v
retrieving revision 1.10
diff -u -B -r1.10 package.xml
--- package.xml	9 Mar 2007 13:46:34 -0000	1.10
+++ package.xml	19 Mar 2007 08:34:56 -0000
@@ -40,6 +40,10 @@
    <dir name="Kolab">
     <file name="LDAP.php" role="php" />
     <file name="IMAP.php" role="php" />
+    <dir name="IMAP">
+     <file name="cclient.php" role="php" />
+     <file name="pear.php" role="php" />
+    </dir> <!-- /IMAP -->
    </dir> <!-- /Kolab -->
   </dir> <!-- / -->
  </contents>
Index: Kolab/IMAP.php
===================================================================
RCS file: /repository/framework/Kolab/Kolab/IMAP.php,v
retrieving revision 1.1
diff -u -B -r1.1 IMAP.php
--- Kolab/IMAP.php	9 Mar 2007 13:16:14 -0000	1.1
+++ Kolab/IMAP.php	19 Mar 2007 08:34:56 -0000
@@ -6,14 +6,6 @@
  * $Horde: framework/Kolab/Kolab/IMAP.php,v 1.1 2007/03/09 13:16:14 jan Exp $
  */
 
-/**
- * The Horde_Kolab library requires version >= 1.0.3 of Net_IMAP (i.e. a
- * version that includes support for the ANNOTATEMORE IMAP extension). The
- * latest version of Net_IMAP can be obtained from
- * http://pear.php.net/get/Net_IMAP
- */
-require_once 'Net/IMAP.php';
-
 /** We need the DOM library for xml handling (PHP4/5). */
 require_once 'Horde/DOM.php';
 
@@ -86,6 +78,7 @@
  *
  * @author  Stuart Binge <omicron@mighty.co.za>
  * @author  Gunnar Wrobel <wrobel@pardus.de>
+ * @author  Thomas Jarosch <thomas.jarosch@intra2net.com>
  * @package Horde_Kolab
  */
 class Kolab_IMAP {
@@ -117,8 +110,6 @@
      * The full mime type string of the current Kolab object format we're
      * dealing with.
      *
-     * @deprecated
-     *
      * @var string
      */
     var $_mime_type;
@@ -174,19 +165,19 @@
 
         $this->_object_type = $app_consts['mime_type_suffix'];
         $this->_mime_type = KOLAB_MIME_TYPE_PREFIX . $this->_object_type;
+        $this->_owner = Auth::getAuth();
+        $this->_folder = rawurldecode($share_uid);
 
-        $current_user = Auth::getAuth();
-        $folder = rawurldecode($share_uid);
-
-        $this->_folder = $folder;
-        $this->_imap = new Net_IMAP(Kolab::getServer('imap'), $conf['kolab']['imap']['port']);
+        $this->_imap = Kolab_IMAP_Connection::factory(Kolab::getServer('imap'), 
+                                                      $conf['kolab']['imap']['port']);
 
-        $result = $this->_imap->login($current_user, Auth::getCredential('password'), false, false);
+        $result = $this->_imap->connect($this->_owner, 
+                                        Auth::getCredential('password'));
         if (is_a($result, 'PEAR_Error')) {
             return $result;
         }
 
-        $result = $this->_imap->selectMailbox($this->_folder);
+        $result = $this->_imap->select($this->_folder);
         if (is_a($result, 'PEAR_Error')) {
             return $result;
         }
@@ -217,7 +208,7 @@
             return false;
         }
 
-        $result = $this->_imap->search('HEADER "' . KOLAB_HEADER_TYPE . '" "' . $this->_mime_type . '"');
+        $result = $this->_imap->searchHeaders(KOLAB_HEADER_TYPE, $this->_mime_type);
         if (is_a($result, 'PEAR_Error')) {
             return PEAR::raiseError(sprintf(_("Horde/Kolab: Failed to search for Kolab objects. Error was: %s"), $result->message));
         }
@@ -235,11 +226,11 @@
     function listObjectsInFolder($folder)
     {
         // Connect to the IMAP server
-        $imap = new Net_IMAP(Kolab::getServer('imap'),
-                             $GLOBALS['conf']['kolab']['imap']['port']);
+        $imap = Kolab_IMAP_Connection::factory(Kolab::getServer('imap'),
+                                               $GLOBALS['conf']['kolab']['imap']['port']);
 
         // Login using the current Horde credentials
-        $result = $imap->login(Auth::getAuth(), Auth::getCredential('password'), false, false);
+        $result = $imap->connect(Auth::getAuth(), Auth::getCredential('password'));
         if (is_a($result, 'PEAR_Error')) {
             Horde::logMessage('Unable to authenticate with the Kolab IMAP server', __FILE__, __LINE__, PEAR_LOG_ERR);
             $imap->disconnect();
@@ -247,13 +238,13 @@
         }
 
         // Select mailbox to search in
-        $result = $imap->selectMailbox($folder);
+        $result = $imap->select($folder);
         if (is_a($result, 'PEAR_Error')) {
             $imap->disconnect();
             return false;
         }
 
-        $result = $imap->search('HEADER "' . KOLAB_HEADER_TYPE . '" "' . $this->_mime_type . '"');
+        $result = $imap->searchHeaders(KOLAB_HEADER_TYPE, $this->_mime_type);
         $imap->disconnect();
         if (!isset($result)) {
             $result = array();
@@ -274,6 +265,10 @@
             return false;
         }
 
+        if (empty($uid) || $uid == "") {
+            return PEAR::raiseError("Horde/Kolab: Cannot search for empty uid.");
+        }
+
         $result = $this->_imap->search("SUBJECT \"$uid\"");
         if (is_a($result, 'PEAR_Error')) {
             return PEAR::raiseError(sprintf(_("Horde/Kolab: Failed to search for SUBJECT \"%s\". Error was: %s"), $uid, $result->message));
@@ -311,12 +306,13 @@
             }
         }
 
-        $this->_headers = $this->_imap->getParsedHeaders($uid);
-        if (is_a($this->_headers, 'PEAR_Error')) {
-            return $this->_headers;
+        $header = $this->_imap->getMessageHeader($uid);
+        if (is_a($header, 'PEAR_Error')) {
+            return $header;
         }
+        $this->_headers = MIME_Structure::parseMIMEHeaders($header);
 
-        $message_text = $this->_imap->getMessages($uid);
+        $message_text = $this->_imap->getMessage($uid);
         if (is_a($message_text, 'PEAR_Error')) {
             return $message_text;
         }
@@ -475,7 +471,7 @@
             return $msg_no;
         }
 
-        $result = $this->_imap->copyMessages($new_share, $msg_no);
+        $result = $this->_imap->copyMessage($new_share, $msg_no);
         if (is_a($result, 'PEAR_Error')) {
             return $result;
         }
@@ -572,13 +568,12 @@
         $type = false;
 
         // Connect to the IMAP server
-        $imap = new Net_IMAP(Kolab::getServer('imap'),
-                             $GLOBALS['conf']['kolab']['imap']['port']);
+        $imap = Kolab_IMAP_Connection::factory(Kolab::getServer('imap'),
+                                               $GLOBALS['conf']['kolab']['imap']['port']);
 
         // Login using the current Horde credentials
-        $result = $imap->login(Auth::getAuth(),
-                               Auth::getCredential('password'),
-                               false, false);
+        $result = $imap->connect(Auth::getAuth(),
+                               Auth::getCredential('password'));
         if (is_a($result, 'PEAR_Error')) {
             Horde::logMessage('Unable to authenticate with the Kolab IMAP server', __FILE__, __LINE__, PEAR_LOG_ERR);
             $imap->disconnect();
@@ -614,13 +609,12 @@
         $folders = array();
 
         // Connect to the IMAP server
-        $imap = new Net_IMAP(Kolab::getServer('imap'),
-                             $GLOBALS['conf']['kolab']['imap']['port']);
+        $imap = Kolab_IMAP_Connection::factory(Kolab::getServer('imap'),
+                                               $GLOBALS['conf']['kolab']['imap']['port']);
 
         // Login using the current Horde credentials
-        $result = $imap->login(Auth::getAuth(),
-                               Auth::getCredential('password'),
-                               false, false);
+        $result = $imap->connect(Auth::getAuth(),
+                                 Auth::getCredential('password'));
         if (is_a($result, 'PEAR_Error')) {
             Horde::logMessage('Unable to authenticate with the Kolab IMAP server', __FILE__, __LINE__, PEAR_LOG_ERR);
             $imap->disconnect();
@@ -710,4 +704,93 @@
      * DEPRECATION END
      */
 
-  }
\ No newline at end of file
+}
+
+/**
+ * The Kolab_IMAP_Connection class provides a wrapper around two
+ * different Kolab IMAP connection types.
+ *
+ * $Horde: framework/Kolab/Kolab/IMAP.php,v 1.1 2007/03/09 13:16:14 jan Exp $
+ *
+ * Copyright 2007 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @author  Gunnar Wrobel <wrobel@pardus.de>
+ * @author  Thomas Jarosch <thomas.jarosch@intra2net.com>
+ * @package Horde_Kolab
+ */
+class Kolab_IMAP_Connection {
+
+    /**
+     * IMAP server to connect to
+     *
+     * @var string
+     */
+    var $_server;
+
+    /**
+     * IMAP server port to connect to
+     *
+     * @var int
+     */
+    var $_port;
+
+    /**
+     * IMAP connection
+     *
+     * @var mixed
+     */
+    var $_imap;
+
+    /**
+     * Constructor
+     *
+     * @param string     $server   Server to connect to
+     * @param int        $port     Port to connect to
+     */
+    function Kolab_IMAP_Connection($server, $port)
+    {
+        $this->_server = $server;
+        $this->_port   = $port;
+    }
+
+    /**
+     * Attempts to return a concrete Kolab_IMAP_Connection instance
+     * based on the available PHP functionality.
+     *
+     * @param string     $imap_uid       The message ID
+     * @param int        $object_uid     The object ID
+     *
+     * @return Kolab_IMAP_Connection The newly created concrete
+     * Kolab_IMAP_Connection instance
+     */
+    function &factory($server, $port)
+    {
+        /**
+         * There are Kolab specific PHP functions available that make
+         * the IMAP access more efficient. If these are detected, the
+         * PHP IMAP implementation should be used.
+         */
+        if (function_exists('imap_status_current') 
+            && function_exists('imap_getannotation')) {
+            $driver = 'cclient';
+        } else {
+            $driver = 'pear';
+        }
+
+        @include_once dirname(__FILE__) . '/IMAP/' . $driver . '.php';
+
+        $class = 'Kolab_IMAP_Connection_' . $driver;
+
+        if (class_exists($class)) {
+            $driver = new $class($server, $port);
+        } else {
+            return PEAR::raiseError(sprintf(_("Horde/Kolab/IMAP: Failed to load IMAP driver %s"), $driver));
+        }
+
+        return $driver;
+    }
+
+}
\ No newline at end of file