2 # 2005-02-24: Fixed for AD/Exchange 2003 & Unicode characters,
3 # anders@bsdconsulting.no If you find this script useful, let me know. :-)
5 # 2000/2001: Original version obtained from Andreas Plesner Jacobsen at
6 # World Online Denmark. Worked for me with Exchange versions prior to Exchange
9 # Use it with mutt by putting in your .muttrc:
10 # set query_command = "/home/user/bin/mutt-ldap.pl '%s'"
12 # Then you can search for your users by name directly from mutt. Press ^t
13 # after having typed parts of the name. Remember to edit configuration
17 use Encode qw/encode decode/;
18 use vars qw { $ldapserver $domain $username $password $basedn };
20 # --- configuration ---
21 $ldapserver = "domaincontroller.yourdomain.com";
22 $domain = "YOURDOMAIN";
24 $password = "mypassword";
25 $basedn = "ou=companyxy,dc=companyxy,dc=tld";
26 # --- end configuration ---
29 my $search=encode("UTF-8", join(" ", @ARGV));
31 if (!$search=~/[\.\*\w\s]+/) {
32 print("Invalid search parameters\n");
38 my $ldap = Net::LDAP->new($ldapserver) or die "$@";
40 $ldap->bind("$domain\\$username", password=>$password);
42 my $mesg = $ldap->search (base => $basedn,
43 filter => "(|(cn=*$search*) (rdn=*$search*) (uid=*$search*) (mail=*$search*))",
44 attrs => ['mail','cn']);
46 $mesg->code && die $mesg->error;
48 print(scalar($mesg->all_entries), " entries found\n");
50 foreach my $entry ($mesg->all_entries) {
51 if ($entry->get_value('mail')) {
52 print($entry->get_value('mail'),"\t",
53 decode("UTF-8", $entry->get_value('cn')),"\tFrom Exchange LDAP database\n");