\documentclass{article}
\usepackage{ulem}
\usepackage{graphicx}
\usepackage{hyperref}
\pagestyle{headings}
\begin{document}
\part{Dynamically selecting an IMAP server for authentication}
\textbf{This information is valid for Horde 4 only. See <a href="https://wiki.horde.org/ImapSelectH3">ImapSelectH3</a> for Horde 3 or <a href="https://wiki.horde.org/ImapSelect">ImapSelect</a> for Horde 5 and later.}

\section{An IMAP server selector hook function in Horde 4 \texttt{imp/config/hooks.php}}
<pre><code class="language-php">
class IMP\_Hooks
\{

public function preauthenticate(\$userId, \$credentials)
\{
    //Horde::logMessage('authM: '.\$credentials['authMethod'].' id='.\$userId, 'ERROR');
    //return true;

    /* when no userId given */
    if (empty(\$userId)) return true;

    /* list of ALL remote users */
    \$remote\_users = array('username@remoteserver.hu' => 'remote-imap-servers-key');

    /* local user */
    if (!array\_key\_exists(\$userId, \$remote\_users)) return true;

    /* remote user */
    return array('credentials' => array('server' => \$remote\_users[\$userId],
                                        'transparent' => true,
                                        'password' => \$GLOBALS['registry']->getAuthCredential('password')
                                  )
    );
\}

\}
</code></pre>
Set server list to 'hidden' in Imp prefs, and all backend's hordeauth to full.

\end{document}
