From f00c0a81c698f3e203e95700c8c1114febbeb93c Mon Sep 17 00:00:00 2001
From: "Jens-U. Mozdzen" <jmozdzen@nde.ag>
Date: Wed, 21 Nov 2012 15:43:05 +0100
Subject: [PATCH 3/3] Revamped the kolab-webmail bundle to work with H5 (some
 polishing still required, but functional)


Signed-off-by: Jens-U. Mozdzen <jmozdzen@nde.ag>
---
 bundles/kolab_webmail/bin/kolab-webmail-install    |    2 +-
 bundles/kolab_webmail/config/conf.d/20-kolab.xml   |   22 +++-
 .../imp/config/backends.d/20-kolab.php             |    3 +-
 .../kolab_webmail/imp/config/conf.d/10-webmail.xml |   12 --
 .../kolab_webmail/imp/config/conf.d/20-kolab.php   |    4 +-
 bundles/kolab_webmail/imp/config/hooks.php         |  148 ++++++++++----------
 .../ingo/config/backends.d/20-kolab.php            |    2 +-
 .../kronolith/config/conf.d/10-webmail.xml         |   12 --
 bundles/kolab_webmail/lib/Bundle.php               |   31 +++--
 9 files changed, 121 insertions(+), 115 deletions(-)

diff --git a/bundles/kolab_webmail/bin/kolab-webmail-install b/bundles/kolab_webmail/bin/kolab-webmail-install
index c61251e..fa3fc77 100755
--- a/bundles/kolab_webmail/bin/kolab-webmail-install
+++ b/bundles/kolab_webmail/bin/kolab-webmail-install
@@ -29,9 +29,9 @@ $cli->writeln($cli->yellow($cli->bold('Installing ' . Horde_Bundle::FULLNAME)));
 $bundle = new Horde_Bundle($cli, $pear_config->getConfFile('system'));
 $bundle->init();
 $bundle->configDb();
+$bundle->configAuth();
 $bundle->migrateDb();
 $bundle->writeAllConfigs();
-$bundle->configAuth();
 
 // Finished.
 $cli->writeln();
diff --git a/bundles/kolab_webmail/config/conf.d/20-kolab.xml b/bundles/kolab_webmail/config/conf.d/20-kolab.xml
index d38dbbd..53f98f0 100644
--- a/bundles/kolab_webmail/config/conf.d/20-kolab.xml
+++ b/bundles/kolab_webmail/config/conf.d/20-kolab.xml
@@ -4,10 +4,28 @@
  <configsection name="auth">
    <configlist name="admins" desc="Which users should be treated as
    administrators (root, super-user) by Horde?">manager</configlist>
+   <configswitch name="driver" desc="What backend should we use for
+   authenticating users to Horde?">kolab</configswitch>
  </configsection>
- <configsection name="share">
+ <configsection name="prefs">
+  <configswitch name="driver" desc="What preferences driver should we
+   use?">KolabImap</configswitch>
+ </configsection>
+ <configsection name="group">
   <configswitch name="driver" desc="What backend should we use for Horde
-   Shares?">Kolab</configswitch>
+   Groups?">Kolab</configswitch>
+ </configsection>
+ <configsection name="share">
+  <configenum name="driver" desc="What backend should we use for Horde
+   Shares?">Kolab</configenum>
+ </configsection>
+ <configsection name="mailer">
+  <configswitch name="type" desc="What method should we use for sending
+   mail?">smtp</configswitch>
+ </configsection>
+ <configsection name="kolab">
+  <configswitch name="enabled" quote="false" desc="Horde/Kolab integration
+    status">true</configswitch>
  </configsection>
 <!--
 //@todo: Fix Kolab driver
diff --git a/bundles/kolab_webmail/imp/config/backends.d/20-kolab.php b/bundles/kolab_webmail/imp/config/backends.d/20-kolab.php
index 6459ea7..be2e2bb 100644
--- a/bundles/kolab_webmail/imp/config/backends.d/20-kolab.php
+++ b/bundles/kolab_webmail/imp/config/backends.d/20-kolab.php
@@ -4,7 +4,8 @@ $servers = array();
 
 $servers['kolab'] = array(
     'name' => 'Kolab Cyrus IMAP Server',
-    'hostspec' => $GLOBALS['injector']->getInstance('Horde_Kolab_Session')->getImapServer(),
+    // 'hostspec' => $GLOBALS['injector']->getInstance('Horde_Kolab_Session')->getImapServer(),
+    'hostspec' => $GLOBALS['conf']['kolab']['imap']['server'],
     'hordeauth' => 'full',
     'protocol' => 'imap',
     'port' => $GLOBALS['conf']['kolab']['imap']['port'],
diff --git a/bundles/kolab_webmail/imp/config/conf.d/10-webmail.xml b/bundles/kolab_webmail/imp/config/conf.d/10-webmail.xml
deleted file mode 100644
index b666603..0000000
--- a/bundles/kolab_webmail/imp/config/conf.d/10-webmail.xml
+++ /dev/null
@@ -1,12 +0,0 @@
-<?xml version="1.0"?>
-<!-- $Id$ -->
-<configuration>
- <configsection name="menu">
-  <configmultienum name="apps" desc="Select any applications that should be
-  linked in IMP's menu" required="false">turba,ingo,kronolith,nag,mnemo
-   <values>
-    <configspecial application="horde" name="apps" />
-   </values>
-  </configmultienum>
- </configsection>
-</configuration>
diff --git a/bundles/kolab_webmail/imp/config/conf.d/20-kolab.php b/bundles/kolab_webmail/imp/config/conf.d/20-kolab.php
index ba3bbcd..df8e435 100644
--- a/bundles/kolab_webmail/imp/config/conf.d/20-kolab.php
+++ b/bundles/kolab_webmail/imp/config/conf.d/20-kolab.php
@@ -1,5 +1,5 @@
 <?php
 
 $conf['hooks']['mbox_redirect'] = true;
-$conf['hooks']['mbox_icon'] = true;
-$conf['hooks']['display_folder'] = true;
+// $conf['hooks']['mbox_icon'] = true;
+// $conf['hooks']['display_folder'] = true;
diff --git a/bundles/kolab_webmail/imp/config/hooks.php b/bundles/kolab_webmail/imp/config/hooks.php
index 436f190..b285361 100644
--- a/bundles/kolab_webmail/imp/config/hooks.php
+++ b/bundles/kolab_webmail/imp/config/hooks.php
@@ -82,78 +82,78 @@ class IMP_Hooks
    }
 
 
-    /**
-     * Allow a custom folder icon to be specified for "standard" mailboxes
-     * ("Standard" means all folders except the INBOX, sent-mail folders and
-     * trash folders.)
-     *
-     * @return array  A list of mailboxes, with the name as keys and the
-     *                values an array with 'icon' and 'alt' entries.
-     *                If a mailbox name doesn't appear in the list, the
-     *                default mailbox icon is displayed.
-     */
-   public function mbox_icons()
-   {
-       $types = $GLOBALS['injector']->getInstance('Horde_Kolab_Storage')
-           ->getList()->listFolderTypes();
-
-       $icons = array();
-       foreach ($types as $folder => $type) {
-           $t = preg_replace('/\.default$/', '', $type);
-           $f = Horde_String::convertCharset($folder, 'UTF-8', 'UTF7-IMAP');
-           switch ($t) {
-           case 'event':
-               $icons[$f] = array(
-                   'alt' => _("Calendar"),
-                   'icon' => Horde_Themes::img('kronolith.png', 'kronolith')
-               );
-               break;
-
-           case 'task':
-               $icons[$f] = array(
-                   'alt' => _("Tasks"),
-                   'icon' => Horde_Themes::img('nag.png', 'nag')
-               );
-               break;
-
-           case 'note':
-               $icons[$f] = array(
-                   'alt' => _("Notes"),
-                   'icon' => Horde_Themes::img('mnemo.png', 'mnemo')
-               );
-               break;
-
-           case 'contact':
-               $icons[$f] = array(
-                   'alt' => _("Contacts"),
-                   'icon' => Horde_Themes::img('turba.png', 'turba')
-               );
-               break;
-
-           case 'h-prefs':
-               $icons[$f] = array(
-                   'alt' => _("Preferences"),
-                   'icon' => Horde_Themes::img('prefs.png', 'horde')
-               );
-               break;
-           }
-       }
-
-       return $icons;
-   }
-
-    /**
-     * Hide specified IMAP mailboxes in folder listings.
-     *
-     * @param string $mailbox  The mailbox name (UTF7-IMAP).
-     *
-     * @return boolean  If false, do not display the mailbox.
-     */
-   public function display_folder($mailbox)
-   {
-       $types = $GLOBALS['injector']->getInstance('Horde_Kolab_Storage')
-           ->getList()->listFolderTypes();
-       $f = Horde_String::convertCharset($mailbox, 'UTF7-IMAP', 'UTF-8');
-       return empty($types[$f]) || ($types[$f] == 'mail');
-   }
+//     /**
+//      * Allow a custom folder icon to be specified for "standard" mailboxes
+//      * ("Standard" means all folders except the INBOX, sent-mail folders and
+//      * trash folders.)
+//      *
+//      * @return array  A list of mailboxes, with the name as keys and the
+//      *                values an array with 'icon' and 'alt' entries.
+//      *                If a mailbox name doesn't appear in the list, the
+//      *                default mailbox icon is displayed.
+//      */
+//    public function mbox_icons()
+//    {
+//        $types = $GLOBALS['injector']->getInstance('Horde_Kolab_Storage')
+//            ->getList()->listFolderTypes();
+// 
+//        $icons = array();
+//        foreach ($types as $folder => $type) {
+//            $t = preg_replace('/\.default$/', '', $type);
+//            $f = Horde_String::convertCharset($folder, 'UTF-8', 'UTF7-IMAP');
+//            switch ($t) {
+//            case 'event':
+//                $icons[$f] = array(
+//                    'alt' => _("Calendar"),
+//                    'icon' => Horde_Themes::img('kronolith.png', 'kronolith')
+//                );
+//                break;
+// 
+//            case 'task':
+//                $icons[$f] = array(
+//                    'alt' => _("Tasks"),
+//                    'icon' => Horde_Themes::img('nag.png', 'nag')
+//                );
+//                break;
+// 
+//            case 'note':
+//                $icons[$f] = array(
+//                    'alt' => _("Notes"),
+//                    'icon' => Horde_Themes::img('mnemo.png', 'mnemo')
+//                );
+//                break;
+// 
+//            case 'contact':
+//                $icons[$f] = array(
+//                    'alt' => _("Contacts"),
+//                    'icon' => Horde_Themes::img('turba.png', 'turba')
+//                );
+//                break;
+// 
+//            case 'h-prefs':
+//                $icons[$f] = array(
+//                    'alt' => _("Preferences"),
+//                    'icon' => Horde_Themes::img('prefs.png', 'horde')
+//                );
+//                break;
+//            }
+//        }
+// 
+//        return $icons;
+//    }
+// 
+//     /**
+//      * Hide specified IMAP mailboxes in folder listings.
+//      *
+//      * @param string $mailbox  The mailbox name (UTF7-IMAP).
+//      *
+//      * @return boolean  If false, do not display the mailbox.
+//      */
+//    public function display_folder($mailbox)
+//    {
+//        $types = $GLOBALS['injector']->getInstance('Horde_Kolab_Storage')
+//            ->getList()->listFolderTypes();
+//        $f = Horde_String::convertCharset($mailbox, 'UTF7-IMAP', 'UTF-8');
+//        return empty($types[$f]) || ($types[$f] == 'mail');
+//    }
 }
diff --git a/bundles/kolab_webmail/ingo/config/backends.d/20-kolab.php b/bundles/kolab_webmail/ingo/config/backends.d/20-kolab.php
index 8a83621..7df1d42 100644
--- a/bundles/kolab_webmail/ingo/config/backends.d/20-kolab.php
+++ b/bundles/kolab_webmail/ingo/config/backends.d/20-kolab.php
@@ -7,7 +7,7 @@ $backends['kolab'] = array(
     'transport' => 'timsieved',
     'hordeauth' => 'full',
     'params' => array(
-        'hostspec' => $GLOBALS['injector']->getInstance('Horde_Kolab_Session')->getImapServer(),
+        'hostspec' => $GLOBALS['conf']['kolab']['imap']['server'],
         'logintype' => 'PLAIN',
         'usetls' => true,
         'port' => $GLOBALS['conf']['kolab']['imap']['sieveport'],
diff --git a/bundles/kolab_webmail/kronolith/config/conf.d/10-webmail.xml b/bundles/kolab_webmail/kronolith/config/conf.d/10-webmail.xml
deleted file mode 100644
index d98c4e8..0000000
--- a/bundles/kolab_webmail/kronolith/config/conf.d/10-webmail.xml
+++ /dev/null
@@ -1,12 +0,0 @@
-<?xml version="1.0"?>
-<!-- $Id$ -->
-<configuration>
- <configsection name="menu">
-  <configmultienum name="apps" desc="Select any applications that should be
-  linked in Kronolith's menu" required="false">horde,imp,turba,ingo,mnemo
-   <values>
-    <configspecial application="horde" name="apps" />
-   </values>
-  </configmultienum>
- </configsection>
-</configuration>
diff --git a/bundles/kolab_webmail/lib/Bundle.php b/bundles/kolab_webmail/lib/Bundle.php
index bf7c8d5..11f0dd0 100644
--- a/bundles/kolab_webmail/lib/Bundle.php
+++ b/bundles/kolab_webmail/lib/Bundle.php
@@ -19,7 +19,7 @@ class Horde_Bundle extends Horde_Core_Bundle
     /**
      * The bundle version.
      */
-    const VERSION = '4.0-RC1';
+    const VERSION = '5.0-RC1';
 
     /**
      * The bundle descriptive name.
@@ -39,28 +39,39 @@ class Horde_Bundle extends Horde_Core_Bundle
     protected function _configAuth(Horde_Variables $vars)
     {
         $vars->auth__driver = 'kolab';
-        $host = $this->_cli->prompt('Provide the host name of your Kolab server:');
+        $kolabhost = $this->_cli->prompt('Provide the host name of your Kolab server:');
+        $smtphost = $this->_cli->prompt('Provide the host name of your SMTP server (may be your Kolab server name):');
+        $ldaphost = $this->_cli->prompt('Provide the host name of your LDAP server (may be your Kolab server name):');
         $maildomain = $this->_cli->prompt('Provide the primary mail domain of your Kolab server:');
         $basedn = $this->_cli->prompt('Provide the base DN of your Kolab server:');
+        $phpdn = $this->_cli->prompt('Provide the PHP DN of your Kolab LDAP nobody user, relative to base DN (may be "cn=nobody,cn=internal,"):');
         $phppw = $this->_cli->prompt('Provide the PHP pw of your Kolab LDAP nobody user:');
         $vars->problems__email = 'postmaster@' . $maildomain;
         $vars->problems__maildomain = $maildomain;
         $vars->kolab__enabled = 'true';
-        $vars->kolab__ldap__server = 'ldap://' . $host . ':389';
-        $vars->kolab__ldap__hostname = $host;
+        $vars->kolab__ldap__server = 'ldap://' . $ldaphost . ':389';
+        $vars->kolab__ldap__hostname = $ldaphost;
         $vars->kolab__ldap__port = '389';
         $vars->kolab__ldap__basedn = $basedn;
-        $vars->kolab__ldap__phpdn = 'cn=nobody,cn=internal,' . $basedn;
+        $vars->kolab__ldap__phpdn = $phpdn . $basedn;
         $vars->kolab__ldap__phppw = $phppw;
-        $vars->kolab__imap__server = $host;
-        $vars->kolab__imap__port = '993';
+        $vars->kolab__imap__server = $kolabhost;
+        $vars->kolab__imap__port = '143';
         $vars->kolab__imap__sieveport = '2000';
         $vars->kolab__imap__maildomain = $maildomain;
+        $vars->kolab__freebusy__server = 'https://' . $kolabhost . '/freebusy';
         $vars->mailer__type = 'smtp';
-        $vars->mailer__params__auth = 'true';
-        $vars->mailer__params__port = 587;
-        $vars->mailer__params__host = $host;
+        $vars->mailer__params__auth = 'false';
+        $vars->mailer__params__port = 25;
+        $vars->mailer__params__host = $smtphost;
         $vars->prefs__driver = 'KolabImap';
+
+	$vars->ldap__hostspec = $vars->kolab__ldap__server;
+	$vars->ldap__tls = 'false';
+	$vars->ldap__version = 3;
+	$vars->ldap__binddn = $vars->kolab__ldap__phpdn;
+	$vars->ldap__bindpw = $vars->kolab__ldap__phppw;
+
         return 'manager';
     }
 }
-- 
1.7.7