41f199
#!/bin/sh
41f199
#
41f199
#  Last modified: 30 October 2000
41f199
#
41f199
41f199
FLAGS=
41f199
41f199
# Create two temporary files.
41f199
umask 077
41f199
TMPFILE=`mktemp /tmp/mutt.ldap.XXXXXX`
41f199
RESULTS=`mktemp /tmp/mutt.ldap.XXXXXX`
41f199
41f199
if [ -n "$LDAPSERVER" ]; then
41f199
	FLAGS="$FLAGS -h $LDAPSERVER"
41f199
fi
41f199
if [ -n "$LDAPBASEDN" ]; then
41f199
	FLAGS="$FLAGS -b $LDAPBASEDN"
41f199
fi
41f199
41f199
# Search.
41f199
ldapsearch $FLAGS '(&(objectclass=inetorgperson)(|(cn='"$1"'*)(givenname='"$1"'*)(surname='"$1"'*)(mail='"$1"'*)))' mail cn roomNumber 2> /dev/null >> $TMPFILE
41f199
ldapsearch -x $FLAGS '(&(objectclass=inetorgperson)(|(cn='"$1"'*)(givenname='"$1"'*)(surname='"$1"'*)(mail='"$1"'*)))' mail cn roomNumber 2> /dev/null >> $TMPFILE
41f199
41f199
# Parse.
41f199
cat $TMPFILE | awk '
41f199
	/^mail:/ {MAIL=substr($0,6)}
41f199
	/^cn:/ {NAME=substr($0,4)}
41f199
	/^roomNumber:/ {ROOM=substr($0,12)}
41f199
	/^$/ { MAIL=gensub("^ *| *$","","g",MAIL) }
41f199
	/^$/ { NAME=gensub("^ *| *$","","g",NAME) }
41f199
	/^$/ { ROOM=gensub("^ *| *$","","g",ROOM) }
41f199
	/^$/ { if(length(NAME) > 0) print MAIL "\t" NAME "\t" ROOM}
41f199
	/^$/ { NAME = "" }
41f199
' > $RESULTS
41f199
41f199
# Sort and present results.
41f199
sort -u $RESULTS > $TMPFILE
41f199
echo Querying ${LDAPSERVER}.... `cat $TMPFILE | wc -l` entries found.
41f199
cat $TMPFILE
41f199
41f199
# Clean up.
41f199
rm -f $TMPFILE $RESULTS