Clean up preferred server list handling
authorMichael M Slusarz <slusarz@curecanti.org>
Fri, 18 Dec 2009 21:19:33 +0000 (14:19 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Fri, 18 Dec 2009 23:37:45 +0000 (16:37 -0700)
imp/config/servers.php.dist
imp/lib/Auth.php

index 8ca89fd..d0ffbac 100644 (file)
  *            ADDED to the list of available namespaces returned by the
  *            server. (IMAP only)
  *
- * preferred: (string) Only useful if you want to use the same servers.php
+ * preferred: (string | array) Useful if you want to use the same servers.php
  *            file for different machines. If the hostname of the IMP machine
  *            is identical to one of those in the preferred list, then that
  *            entry will be selected by default on the login screen. Otherwise
index aee362b..4425b49 100644 (file)
 class IMP_Auth
 {
     /**
-     * The preferred server based on the value from the login form.
-     *
-     * @var string
-     */
-    static public $prefServer = null;
-
-    /**
      * Authenticate to the mail server.
      *
      * @param array $credentials  An array of login credentials. If empty,
@@ -268,23 +261,16 @@ class IMP_Auth
      */
     static public function isPreferredServer($server, $key = null)
     {
-        if (!is_null(self::$prefServer)) {
-            return ($key == self::$prefServer);
+        if (empty($server['preferred'])) {
+            return false;
         }
 
-        if (!empty($server['preferred'])) {
-            if (is_array($server['preferred'])) {
-                if (in_array($_SERVER['SERVER_NAME'], $server['preferred']) ||
-                    in_array($_SERVER['HTTP_HOST'], $server['preferred'])) {
-                    return true;
-                }
-            } elseif (($server['preferred'] == $_SERVER['SERVER_NAME']) ||
-                      ($server['preferred'] == $_SERVER['HTTP_HOST'])) {
-                return true;
-            }
-        }
+        $preferred = is_array($server['preferred'])
+            ? $server['preferred']
+            : array($server['preferred']);
 
-        return false;
+        return in_array($_SERVER['SERVER_NAME'], $preferred) ||
+               in_array($_SERVER['HTTP_HOST'], $preferred);
     }
 
     /**