[horde] feeding LDAP user address to default identity

Chris Flav chris.flav at yahoo.ca
Thu Nov 25 18:34:54 UTC 2010


Well nobody has answered this, however I have since solved my problem.  It was 
under Horde, not IMP (as Horde auth is being done by IMP in my case)

in horde/config/prefs.php, I locked the pref and added hook = true

// user preferred email address for From: line
// If you lock this preference, you must specify a value or a hook for it in
// horde/config/hooks.php.
$_prefs['from_addr'] = array(
    'value' => '',
    'locked' => true,
    'shared' => true,
    'type' => 'text',
    'hook' => true,
    'desc' =>  _("Your From: address:")
);

and in hooks.php


 if (!function_exists('_prefs_hook_from_addr')) {
     function _prefs_hook_from_addr($user = null)
     {
        global $_SERVER;
        $SERVER="localhost";
        $ROOTDN="cn=horde,dc=example,dc=com";
        $ROOTPW="xxxxxx";
        $BASEDN="dc=example,dc=com";
        $ds = ldap_connect($SERVER);
        ldap_bind($ds,$ROOTDN, $ROOTPW);
         $searchResult = @ldap_search($ds, $BASEDN, 'uid=' . $user);
         $information = @ldap_get_entries($ds, $searchResult);
         $name = $information[0]['maillocaladdress'][0];
         ldap_close($ds);
         return (empty($name) ? $user : $name);
     }
}



This seems to work.

C. Flav



----- Original Message ----
From: Chris Flav <chris.flav at yahoo.ca>
To: horde at lists.horde.org
Sent: Wed, November 24, 2010 6:10:44 PM
Subject: [horde] feeding LDAP user address to default identity

Hello,

I am upgrading a old server that currently has a mechanism to retreive the 
user's email address from a LDAP server using the following function;

in conf.php there is;

// If this is set to a function name, that function will be used
// to get the user's email address to use when sending mail.  See
// the 'imp_expand_fromaddress' function below for an example.
$conf['hooks']['from'] = 'imp_expand_fromaddress';


and lower down there is a function;

/* This is another example how to get the from address from an ldap server. */
if (!function_exists('imp_expand_fromaddress')) {
     function imp_expand_fromaddress($imp) {
        global $_SERVER;
        $SERVER="localhost";
        $ROOTDN="uid=root,dc=example,dc=com";
        $ROOTPW=$_SERVER['PW'];
        $BASEDN="dc=example,dc=com";
        $ds = ldap_connect($SERVER);
        ldap_bind($ds,$ROOTDN, $ROOTPW);
         $searchResult = @ldap_search($ds, $BASEDN, 'uid=' . $imp['user']);
         $information = @ldap_get_entries($ds, $searchResult);
         $name = $information[0]['maillocaladdress'][0];
         ldap_close($ds);
         return (empty($name) ? $imp['user'] : $name);
     }
}


this retreives the first email address configured on a LDAP dn.  I don't find 
this hook anywhere in the latest version of IMP, is there anyone that could give 

me a hint where I could add this to duplicate this functionality? 


Thanks,

C. Flav


-- 
Horde mailing list - Join the hunt: http://horde.org/bounties/#horde
Frequently Asked Questions: http://horde.org/faq/
To unsubscribe, mail: horde-unsubscribe at lists.horde.org





More information about the horde mailing list