Skip to content

Instantly share code, notes, and snippets.

@hegge
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hegge/70204bead964de3985dc to your computer and use it in GitHub Desktop.
Save hegge/70204bead964de3985dc to your computer and use it in GitHub Desktop.
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