[cvs] [Wiki] changed: ImapSelect

Wiki Guest wiki at wiki.horde.org
Wed May 18 15:23:24 PDT 2005


guest [199.104.120.59]  Wed, 18 May 2005 15:23:24 -0700

Modified page: http://wiki.horde.org/display.php?page=ImapSelect
New Revision:  2.0

@@ -1 +1,54 @@
+During a migration from one IMAP server to another, the need arose to run both the old and the new IMAP servers in paralell. By default,
+Horde only allows a single primary server to be enabled in servers.php. Of course, we could have allowed our users to simply select
+their server by enabling IMAP server selection, but there is a better way. What follows are instructions on using a MySQL backend to 
+select an IMAP server for authentication, given a username:
 
+* The SQL table
+
+There are many ways to do this of course. In this example, we'll just be using a table with two rows:
+
+---------------------------------------------------------
+|   username        |     server.domain.com   |
+---------------------------------------------------------
+
+Your table can be constructed however you like. It can even be a part of your existing DB. The important point is that you need the
+table to be constructed in such a way as to be able to query a username and have the lookup return a servername. Our example
+uses a table called 'host'. 
+
+* Writing a hook
+
+Here's some sample code for a hook that could be placed into horde/config/hooks.php:
+
+if (!function_exists('_imp_hook_imap')) {
+        function _imp_hook_imap($userName)
+        {
+                global $conf;
+                include_once 'DB.php';
+                $_db = &DB::connect($conf['sql'], true);
+                $query = sprintf('SELECT server FROM host WHERE user=%s', $_db->quote($userName));
+                $result = $_db->getOne($query);
+                if (!is_a($result, 'PEAR_Error')) {
+                        return $result;
+                } else {
+                        return false;
+                }
+        }
+} 
+
+* Placing the hook into the session
+
+The above hook returns a single line containing a server name. It's injected into /horde/imp/lib/Session.php as follows:
+
+        if (!empty($GLOBALS['conf']['hooks']['imap'])) {
+                require_once HORDE_BASE . '/config/hooks.php';
+                if (function_exists('_imp_hook_imap')) {
+                        $_SESSION['imp']['server'] = call_user_func('_imp_hook_imap',  $_SESSION['imp']['user']);
+                        }
+        }
+
+On our setup, this is done right before authentication is attempted (right around line 223). As best I can tell, you're fine so long
+as you don't have $_SESSION['imp']['server']  overwritten by anything else before you get to the call to &Auth::singleton(array('imp', 'imp'));
+
+* Disclaimer 
+
+This code works on our setup so far. It could be wrong, uneccesary, foolish, or otherwise idiotic. In short, YMMV. 


More information about the cvs mailing list