sourcecode
lachoy
<code>
#!/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";
}
}
</code>
<p>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
<code>^T</code> and the LDAP search will be performed.</p>
<p>Just add the following line to your
<code>.muttrc</code>, changing the name of
the script to whatever you save it as:</p>
<p>
<code>set query_command = "~/bin/mutt_ldap.pl '%s'"</code>
</p>
<p>You'll have to set the proper information for the constants
<code>HOST</code> and <code>BASE</code> and, if your
LDAP server doesn't allow anonymous binds, also pass
the full DN mapping to your user record and password
to the <code>bind()</code> method. Also, if you
have a nonstandard schema you'll have to modify the
LDAP property names.</p>
E-Mail Programs
Chris Winters <chris@cwinters.com>