Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Mutt LDAP DavMail lookup
#!/usr/bin/perl
# Based on http://www.perlmonks.org/?node_id=65152
use strict;
use Net::INET6Glue::INET_is_INET6;
use Net::LDAP;
use constant HOST => 'ip6-localhost:1389';
use constant BASE => 'ou=people';
{
print "Searching database... ";
my $name = shift || die "Usage: $0 filter\n";
my $ldap = Net::LDAP->new( HOST, onerror => 'die' )
|| die "Cannot connect: $@";
$ldap->bind('username', password => 'password') or die "Cannot bind: $@";
my $msg = $ldap->search( base => BASE,
filter => "(|(sn=*$name*)(givenName=*$name*)(cn=*$name*))");
my @entries = ();
foreach my $entry ( $msg->entries() ) {
push @entries,
{ email => $entry->get_value( 'mail' ),
first_name => $entry->get_value( 'cn' ),
last_name => $entry->get_value( 'uid' ) };
}
$ldap->unbind();
print scalar @entries, " entries found.\n";
foreach my $entry ( @entries ) {
print "$entry->{email}\t$entry->{first_name}\t$entry->{last_name}\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.