Add query filter section (in order to pare down results)
authorWade Berrier <wberrier@gmail.com>
Sat, 19 Jan 2013 21:05:59 +0000 (14:05 -0700)
committerWade Berrier <wberrier@gmail.com>
Sat, 19 Jan 2013 21:05:59 +0000 (14:05 -0700)
mutt-ldap.py

index 92607edb54900db99d546ee189f74e4519530d65..94e44b9d894952664e32246df5f46ffb2bc87d8a 100755 (executable)
@@ -54,6 +54,8 @@ CONFIG.add_section('auth')
 CONFIG.set('auth', 'user', '')
 CONFIG.set('auth', 'password', '')
 CONFIG.set('auth', 'gssapi', 'no')
+CONFIG.add_section('query')
+CONFIG.set('query', 'filter', '') # only match entries according to this filter
 CONFIG.read(os.path.expanduser('~/.mutt-ldap.rc'))
 
 def connect():
@@ -89,6 +91,9 @@ def search(query, connection=None):
         filterstr = u'(|{})'.format(
             u' '.join([u'({}=*{}{})'.format(field, query, post)
                        for field in ['cn', 'displayName', 'uid', 'mail']]))
+        query_filter = CONFIG.get('query', 'filter')
+        if query_filter:
+            filterstr = u'(&({}){})'.format(query_filter, filterstr)
         r = connection.search_s(
             CONFIG.get('connection', 'basedn'),
             ldap.SCOPE_SUBTREE,