[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Script for Mutt to query db.debian.org



On Wed, Jul 19, 2000 at 05:09:42PM -0400, Ben Collins wrote:
> Here's a little script I wrote for mutt to query the developer database.
> To use it, install this script in your PATH, and add this line to
> ~/.muttrc:
> 
> 	set query_command = "debian-ldap-query '%s'"
> 
> You will need to install the libnet-ldap-perl package for this to work.
> Then from within mutt hit "Q" and type in something like "ben" and you get
> a nice list.

Here's an updated script that adds:

- Searches the ircnick aswell
- Lists the IRC Nick if found

Also note that you can use the query in place of tab address (alias)
completion by hitting ^T.

Ben

-- 
 -----------=======-=-======-=========-----------=====------------=-=------
/  Ben Collins  --  ...on that fantastic voyage...  --  Debian GNU/Linux   \
`  bcollins@debian.org  --  bcollins@openldap.org  --  bcollins@linux.com  '
 `---=========------=======-------------=-=-----=-===-======-------=--=---'
#!/usr/bin/perl

$|=1;

use Net::LDAP;

my $server = "db.debian.org";
my $base = "ou=users, dc=debian, dc=org";
my $port = 389;

die print "Usage: $0 <name> [<name> ...]\n" if ! $ARGV[0];

my @results;

my $ldap = Net::LDAP->new($server, port => $port) or
	die "Could not contact LDAP server $server:$port";
$ldap->bind or die "Could not bind";

foreach my $search (@ARGV) {
    my $mesg = $ldap->search (
	base => "$base",
	filter => "(|(cn=*$search*)(sn=*$search*)(ircnick=*$search*))"
	) || die "Failed search";
    foreach my $entry ($mesg->entries) {
	my @uid = $entry->get('uid');
	next if !defined(@uid) || $uid[0] eq '';
	my @fname = $entry->get('cn');
	my @lname = $entry->get('sn');
	my @nick = $entry->get('ircnick');
	push @results, "<$uid[0]\@debian.org>\t$fname[0] $lname[0]\t($nick[0])\n";
    }
}

$ldap->unbind;

print "LDAP query: found ", scalar(@results), "\n", @results;
exit 1 if ! @results;

Reply to: