[imp] From: and Fullname

Patrick Timmons ptimmons@courriel.polymtl.ca
Wed, 11 Oct 2000 10:28:54 -0400


Hi. 

This is how I do it (see below for php3 code):

I changed mailbox.php3 to "call" ldap2db.php3 (see code at the end) like this:

--------8<--------
  /* only proceed on a valid login */
  $imp->authenticate();

  /* indicates invalid login or expired login so skip all the crap below */
  if (isset($imp->stream) && (!$imp->stream)) exit;
+
+ /* Modif poly */
+ require './ldap2db.php3';
+ /* fin Modif poly */
+
  if (!isset($plural)) $plural = false;

  $delnum = 0;
--------8<---------

In ldap2db.php3, change MY.LDAP.SERVER.NAME by the fully qualified name of your server, 
DN-THAT-CAN-READ-EVERYTHING by a dn that has read access to everything including the userpassword 
(cn=directory manager,o=polymtl.ca in my case), PASSWORD for that dn's userpassword and MYLDAPROOT 
by the root of your LDAP tree (o=polymtl.ca in my case).

P.Timmons

Lorenzo Cavassa wrote:
> 
> Hi,
> 
> i like IMP but i would like to know if and how it's  possible to modify
> it to get the From-Address:, the Fullname and the Language entries from
> an LDAP directory and not from an SQL database.
> 
> Thank you!
> 
> Lorenzo
> 
> --
> IMP mailing list: http://horde.org/imp/
> Frequently Asked Questions: http://horde.org/faq/
> To unsubscribe, mail: imp-unsubscribe@lists.horde.org

-- 
Patrick Timmons, service informatique

============
<?php

/* ldap2db.php3

fonction pour transferer le nom complet et l'adresse email de ldap a la base de donnees mysql de imp.
*/

if (isset($actionID) && ($actionID == IMP_LOGIN) ) {
   $init_fait=0;
   $ds=ldap_connect("MY.LDAP.SERVER.NAME");
   if ($ds) {
      $r=ldap_bind($ds,"DN-THAT-CAN-READ-EVERYTHING","PASSWORD");
      if ($r) {
         $errrep=error_reporting();
         error_reporting(0);
         $sr=ldap_search($ds,"MYLDAPROOT","uid=$imapuser",array("uid","cn","mail","mailhost","userpassword"));
         $errrep=error_reporting($errrep);
         if ($sr) {
            $entries=ldap_get_entries($ds,$sr);
            if ($entries["count"]==1) {
               for ($i=0; $i<$entries[0]["uid"]["count"]; $i++) {
                  if (   strtolower($entries[0]["uid"][$i])==strtolower($imapuser)
                      && strtolower($entries[0]["mailhost"][0])==strtolower($tmp_server)
                      && $entries[0]["userpassword"][0]==$pass) {
                     $init_fait=1;
                     imp_set_from($entries[0]["mail"][0],$imapuser,$tmp_server);
                     imp_set_fullname(addslashes($entries[0]["cn"][0]),$imapuser,$tmp_server);
                  }
               }
            }
         }
      }
      ldap_unbind($ds);
   }

/*   if (!$init_fait) {
      imp_set_from("$user@$server",$user,$server);
   } */
}

/* fin de ldap2db.php3 */

?>
=====================