On Thu, 16 Aug 2012, Michael M Slusarz wrote:
Quoting Andrew Morgan <[email protected]>:
On Wed, 15 Aug 2012, Michael M Slusarz wrote:
Quoting Andrew Morgan <[email protected]>:
However, what I really need to do is lookup the realm on the fly. Is
there some session parameter I can use as a key to lookup the $servers
entry?
In IMP 5+, you can do this:
$servers = IMP_Imap::loadServerConfig([$server]);
where $server = the server entry you want to load from
backends[.local].php
If $server is omitted, all of the server entries will be returned.
Okay, that is getting me closer! How can I determine which server the user
is authenticated to? That must be stored in a session object somewhere, so
that IMP knows which server to connect to later on...
There's no way of retrieving the original server key (i.e. the array key from
backends.php). You can instead query the stored IMAP object to determine
which server it is using.
e.g.:
$imap = $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create();
$value = $imap->ob->get($key);
where $key is the Horde_Imap_Client_Base configuration option. See:
http://dev.horde.org/api/framework/Imap_Client/Imap_Client/Horde_Imap_Client.html#factory
for the list of parameters. 'hostspec' and/or 'port' should probably be
sufficient to uniquely identify the backend server.
Okay! That put me on the right track. Here is my final solution in
horde/config/hooks.php:
public function authusername($userId, $toHorde)
{
if ($toHorde) {
// Put the domain on from backends.local.php
$imap =
$GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create();
$hostspec = $imap->ob->getParam('hostspec');
$servers = IMP_Imap::loadServerConfig();
foreach ($servers as $server) {
if ($server['hostspec'] == $hostspec) {
$userId = $userId . '@' . $server['realm'];
break;
}
}
return $userId;
} else {
// strip the domain off
$userId = substr($userId, 0, strpos($userId, '@'));
return $userId;
}
}
Note: it was $imap->ob->getParam($key) instead of $imap->ob->get($key).
I defined a 'realm' parameter on the server entry in backends.local.php to
more directly control the value that would be appended to the userId.
Thanks for all the help!
Andy
--
imp mailing list
Frequently Asked Questions: http://wiki.horde.org/FAQ
To unsubscribe, mail: [email protected]