Hi all,
first I would like to thank you for this beautiful webmail program.
I tried it two days ago and decided to replace my squirrelmail
installation with it.
The only thing which didn't work as supposed for me was the
LDAP directory search. In my LDAP directory a lot off user have
multiple mail attributes. So if I look for one, the LDAP search
returns all addresses. These are stored as an array in
$result[$n][$server['mail_field'] but only the first one is used
when generating the $contacts array.
Let's say I am looking for every address with contains 'example'
and I have a user John Doe who has the following email addresses:
john(a)doe.com
john(a)example.com
john(a)example.net
The LDAP search will find the user, but only the first email
address john(a)doe.com will be displayed.
I changed the ldapsearchform.inc on two places:
- when generating the $contacts array, not only the first element
of the $result[$n][$server['mail_field']] is used but all the
elements in this array
- all email addresses, which were not searched for are deleted
from $contacts before returning it if the search was on the mail
attribute
I hope you can integrate this patch as it doesn't change the
functionality of the search, if every user in the directory has
only one mail attribute.
Best regards,
Drazen Baic
Index: ldapsearchform.inc
===================================================================
--- ldapsearchform.inc (revision 261)
+++ ldapsearchform.inc (working copy)
@@ -221,9 +221,12 @@
{
for ($n = 0; $n < $result['count']; $n++)
{
- $contacts[$n]['name'] = $result[$n][$server['name_field']]
[0];
- $contacts[$n]['email'] = $result[$n][$server['mail_field']]
[0];
- $contacts[$n]['row_id'] = $n + 1;
+ for ($m = 0; $m < count($result[$n][$server
['mail_field']])-1; $m++)
+ {
+ $contacts[$n+$m]['name'] = $result[$n][$server
['name_field']][0];
+ $contacts[$n+$m]['email'] = $result[$n][$server
['mail_field']][$m];
+ $contacts[$n+$m]['row_id'] = $n + $m + 1;
+ }
}
}
}
@@ -242,6 +245,23 @@
if ($contacts[$i]['email'] == $contacts[$n]['email'] && $i !=
$n)
unset($contacts[$n]);
+ // If an user entry had multiple email addresses the ldap search
returns
+ // an array with all the addresses, not only the one found. This
looks
+ // confusing for the user so it's better to delete these entries.
+ if ($search_field == $server['mail_field'])
+ {
+ $tempcontacts;
+ $counter = 0;
+ foreach ($contacts as $temp)
+ {
+ if (ereg($search_value, $temp['email']))
+ {
+ $tempcontacts[$counter] = $temp;
+ $counter++;
+ }
+ }
+ $contacts = $tempcontacts;
+ }
return $contacts;
}