<<< Date Index >>>     <<< Thread Index >>>

Re: Mutt + LDAP + multiple email addresses



On Sat, Mar 08, 2008 at 11:14:41PM -0500, Roland Hill wrote:
> Hi List,
> 
> I am using mutt to query my LDAP server using the mutt_ldap_query.pl
> program.
> 
> As is it works fine, except, as designed, it will only retrieve the first
> email address.
> 
> Has anyone modified it to retrieve more than one email address for an
> entry?
> 
> I'm no programmer so I don't really know where to start.

Hi Roland,

I'm using the attached script.  When I query an email with ^t, if there
is a single email, it fills in the field.  If there are multiple, I get
window like the folder choice window where I can choose which
name/address pair I wanted.

Search is according to the line specified in "filter = ".  You might
need to adjust this for your LDAP schema.  I'm using this to search MS
AD's global catalog and it works well.

Ross
#! /usr/bin/perl -Tw
# 2005-02-24: Fixed for AD/Exchange 2003 & Unicode characters,
# anders@xxxxxxxxxxxxxxxx If you find this script useful, let me know. :-)
#
# 2000/2001: Original version obtained from Andreas Plesner Jacobsen at
# World Online Denmark. Worked for me with Exchange versions prior to Exchange
# 2000.
#
# Use it with mutt by putting in your .muttrc:
# set query_command = "/home/user/bin/mutt-ldap.pl '%s'"
#
# Then you can search for your users by name directly from mutt. Press ^t
# after having typed parts of the name. Remember to edit configuration
# variables below.

use strict;
use Encode qw/encode decode/;
use vars qw { $ldapserver $domain $username $password $basedn };

# --- configuration ---
$ldapserver = "blah";
$domain = "blah";
$username = "blah";
$password = 'blah';
$basedn = "blah";
# --- end configuration ---

#my $search=shift;
my $search=encode("UTF-8", join(" ", @ARGV));

if (!$search=~/[\.\*\w\s]+/) {
        print("Invalid search parameters\n");
        exit 1;
}

use Net::LDAP;

my $ldap = Net::LDAP->new($ldapserver) or die "$@";

$ldap->bind("$domain\\$username", password=>$password);

print ("$basedn\n");
my $mesg = $ldap->search (base => $basedn,
                          filter => "(|(dispName=*$search*) (cn=*$search*) 
(rdn=*$search*) (uid=*$search*) (mail=*$search*))",
                          attrs => ['mail','cn']);

$mesg->code && die $mesg->error;

if(scalar($mesg->all_entries) == 0) {
        print ("nothing!\n");
}

foreach my $entry ($mesg->all_entries) {
        if ($entry->get_value('mail')) {
                print($entry->get_value('mail'),"\t",
                      decode("UTF-8", $entry->get_value('cn')),"\tFrom Exchange 
LDAP database\n");
                }
        }
#$ldap->unbind;

Attachment: signature.asc
Description: Digital signature