Category: | E-Mail Programs |
Author/Contact Info | Chris Winters <chris@cwinters.com> |
Description: | Mutt allows you to add a hook for an external address lookup program. A common one is LDAP, and this simple script does the lookup for you. Once this is setup, you can enter part of a person's first or last name, hit ^T and the LDAP search will be performed. Just add the following line to your .muttrc, changing the name of the script to whatever you save it as: set query_command = "~/bin/mutt_ldap.pl '%s'" You'll have to set the proper information for the constants HOST and BASE and, if your LDAP server doesn't allow anonymous binds, also pass the full DN mapping to your user record and password to the bind() method. Also, if you have a nonstandard schema you'll have to modify the LDAP property names. |
#!/usr/bin/perl use strict; use Net::LDAP; use constant HOST => 'ldap.mysite.com'; use constant BASE => 'cn=People, dc=MySite, dc=com'; { print "Searching database... "; my $name = shift || die "Usage: $0 filter\n"; my $ldap = Net::LDAP->new( HOST, onerror => 'die' ) || die "Cannot connect: $@"; $ldap->bind() or die "Cannot bind: $@"; my $msg = $ldap->search( base => BASE, filter => "(|(sn=*$name*)(givenName=*$name* +))" ); my @entries = (); foreach my $entry ( $msg->entries() ) { push @entries, { email => $entry->get_value( 'mail' ), first_name => $entry->get_value( 'givenName' ), last_name => $entry->get_value( 'sn' ) }; } $ldap->unbind(); print scalar @entries, " entries found.\n"; foreach my $entry ( @entries ) { print "$entry->{email}\t$entry->{first_name} $entry->{last_name}\n +"; } } |
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: LDAP address lookup from Mutt
by waxhead (Acolyte) on Dec 24, 2002 at 07:40 UTC | |
by waxhead (Acolyte) on Dec 26, 2002 at 13:33 UTC | |
by Anonymous Monk on Aug 11, 2009 at 22:19 UTC |