Hal DeVore <[EMAIL PROTECTED]> wrote:
>On the to-do list for exmh is addition of LDAP as an "address
>book" using OpenLDAP or something similar. As was rightly
>pointed out such things really should go in to the underlying nmh
>code so they are accessible "from the command line".
I have implemented this by a crude but effective perl script, which
takes:
To: username[,username,...]
or
To: firstname lastname
and converts it to a mail address (attached).
>So. The question is: how could such a thing be "hooked in" to
>nmh? I'm not as familiar with nmh as I should be. Should this
>go in to the ali command? Is there a more "general" mechanism
>already in nmh for address lookup? Can a new "look up ldap
>entry" command be created and easily "hooked" into post and/or
>send and/or whom?
The more elegant solution would seem to be to tie it in to the
aliases code, so you got something like:
if it's an alias, use real address
if it's a local address, deliver locally
if it's not found, look up the directory/directories
I'm not sure which order the last two should be in, actually. And you
certainly want to have multiple directory support, at least until there
is a worldwide directory hiearchy (like DNS).
I'd be happy to help on this project.
regards,
Nate
#!/usr/local/bin/perl -w
use Net::LDAPapi;
use Config;
while(<STDIN>) {
if (/(To): (.*)/i || /(Cc): (.*)/i || /(Bcc): (.*)/i) {
$is = $1;
$toAddr = $2;
if ($toAddr =~ /,/) {
for $cn (split(/\s*,\s*/,$toAddr)) {
if ($cn !~ /\s/) {
push(@filter,"(uid=$cn)");
} else {
push(@filter,"(cn=*$cn*)");
}
}
} else {
if ($toAddr !~ /\s/) {
@filter = ("(uid=$toAddr)");
} else {
@filter = ("(cn=*$toAddr*)");
}
}
} else { die "Unable to parse $_\n"; }
}
if ($Config{'osname'} eq "dec_osf") {
for $filt (@filter) {
open(SEARCH,"ldapsearch \"$filt\" mail|");
while(<SEARCH>) {
if (/^mail=(.*)/) {
push(@addr,$1);
}
}
}
print "$is: ",join(",",@addr), "\n";
exit;
}
######################################################################
# Connect and bind to LDAP service ###################################
######################################################################
$ldap_server = "dirgod.cc.monash.edu.au";
$BASEDN = "o=Monash University, c=AU";
if (($ld = ldap_open($ldap_server,LDAP_PORT)) eq "") {
die "ldap_init failed";
}
if ((ldap_simple_bind_s($ld,"","")) != LDAP_SUCCESS) {
ldap_perror($ld,"ldap_simple_bind_s");
die "Failed to bind as anonymous";
}
##### Set the maximum number of entries to return ####################
$sizelimit = 25;
ldap_set_option($ld,LDAP_OPT_SIZELIMIT,$sizelimit);
@returnAttrs = ("mail");
if (ldap_search_s($ld,$BASEDN,LDAP_SCOPE_SUBTREE, $filter,
\@returnAttrs, 0, $result) != LDAP_SUCCESS) {
$err = ldap_get_lderrno($ld,$errdn,$extramsg);
print &ldap_err2string($err),"\n";
print "DN $errdn\n" if defined $errdn;
print "Extra message: $extramsg\n" if defined $extramsg;
ldap_unbind($ld);
die "Search for >$filter< in $BASEDN failed\n";
}
%searchRecord = %{ldap_get_all_entries($ld,$result)};
$cnt = 0;
for $matchingDN (sort keys %searchRecord) {
print "To: ", $searchRecord{$matchingDN}{mail}[0], "\n";
$cnt++;
}
if (!$cnt) { print "To: $filter\n"; }