Changes between Initial Version and Version 1 of QueryCommand/MuttLdapSearch


Ignore:
Timestamp:
Feb 18, 2012 5:10:11 AM (6 years ago)
Author:
rado
Comment:

migrate wiki.mutt.org

Legend:

Unmodified
Added
Removed
Modified
  • QueryCommand/MuttLdapSearch

    v1 v1  
     1{{{
     2#!/bin/sh
     3# Requires: echo, expr, grep, ldapsearch, sed, test
     4# Set your PATH accordingly.
     5#
     6
     7max=100
     8timeout=60
     9sort=givenName
     10base='ou=Contacts,dc=example,dc=com'
     11filter="(&(objectClass=mozillaAbPersonAlpha)(|(cn=*$@*)(displayName=*$@*)(givenName=*$@*)(sn=*$@*)(mail=*$@*)(mozillaSecondEmail=*$@*)))"
     12
     13status=`ldapsearch -z $max -x -s one -l $timeout -b "$base" "$filter" 1.1 2>&1 | \\
     14
     15grep -E '^(# )?(numResponses|numEntries|result|ldapsearch): '`
     16count="`echo $status | grep numResponses: | sed -e 's/.*numResponses: \([0-9.+-]*\).*/\1/'`"
     17count="`expr ${count:-1} - 1`"
     18result="`echo $status | grep result: | sed -e 's/.*result: \([0-9.+-]*\) \([^ ]*\).*/\1/'`"
     19result="`expr ${result:--7} + 0`"
     20rmesg="`echo $status | grep ldapsearch:`"
     21test -z "$rmesg" && \\
     22
     23rmesg="rcode=$result `echo $status | grep result: | \\
     24
     25sed -e 's/.*result: \([0-9.+-]*\) \([^#:]*\) [#]*[ ]*[A-Za-z]*[:]*.*/\2/'`"
     26
     27if test "${result:-1}" -ne 0 -a "${result:-1}" -ne 4
     28then
     29  echo "ERROR: $rmesg"
     30  exit 2
     31fi
     32
     33if test ${count:-0} -eq 0
     34then
     35  echo "Searching database ... $max entries ... $count matching."
     36  exit 1
     37fi
     38
     39(
     40ldapsearch -S $sort -LLL -z $max -x -s one -l $timeout -b "$base" -a search "$filter" \\
     41
     42mail displayName mozillaSecondEmail givenName initials surname ; \\
     43
     44echo dn: DONE \\
     45
     46) 2>/dev/null | while read ATTR VAL
     47do
     48  if test -z "$ATTR"; then continue; fi
     49  attr="`echo $ATTR | sed -e 's/:$//'`"
     50  case "$attr" in
     51    dn)
     52        if test -z "$dn"
     53        then
     54          echo "Searching database ... $max entries ... $count matching:"
     55        else
     56          echo -n "$mail        $displayName"
     57          if test -n "$sn"
     58          then
     59            echo -n "   "
     60            ( ( test -n "$initials" && echo -n $initials ) \\
     61
     62            || (test -n "$givenName" && echo -n $givenName) )
     63            echo -n " $sn"
     64          fi
     65          test -n "$mozillaSecondEmail" && echo -n " <$mozillaSecondEmail>"
     66          echo
     67        fi
     68        dn="$VAL"
     69        eval unset $VARS VARS
     70        ;;
     71    *)
     72        test -n "$attr" -a -n "$VAL" && setvar $attr "$VAL" \\
     73
     74        && VARS="$VARS $attr"
     75        ;;
     76  esac
     77done
     78
     79exit ${result:-0}
     80}}}