Also search on displayName in mutt-ldap.py and ldap-jpeg.py.
authorW. Trevor King <wking@tremily.us>
Wed, 15 Aug 2012 14:13:20 +0000 (10:13 -0400)
committerW. Trevor King <wking@tremily.us>
Wed, 15 Aug 2012 14:13:20 +0000 (10:13 -0400)
Also prefer displayName to cn when formatting names.

posts/LDAP/ldap-jpeg.py
posts/LDAP/mutt-ldap.py

index 2d287973e7f9acfb390a4163ac5db807ac4486f6..15866a432a53c0168d493ac41cd95ccd8b0410d5 100755 (executable)
@@ -83,7 +83,7 @@ def search(query, connection=None):
             post = '*'
         filterstr = '(|%s)' % (
             u' '.join([u'(%s=*%s%s)' % (field, query, post)
-                       for field in ['cn', 'uid', 'mail']]))
+                       for field in ['cn', 'displayName' 'uid', 'mail']]))
         r = connection.search_s(
             CONFIG.get('connection', 'basedn'),
             _ldap.SCOPE_SUBTREE,
@@ -110,7 +110,7 @@ def view_entry_photo(entry):
     cn,data = entry
     if 'jpegPhoto' in data:
         for jpeg in data['jpegPhoto']:
-            name = data['cn'][-1]
+            name = data.get('displayName', data['cn'])[-1]
             fd,filename = _tempfile.mkstemp(
                 prefix= name + '-', suffix='.jpeg')
             try:
index 059b25caddee73b3aaebdb46d66697f763bd3c44..7c51d859d68413c4770c2308489ec585c955e01f 100755 (executable)
@@ -87,7 +87,7 @@ def search(query, connection=None):
             post = '*'
         filterstr = '(|%s)' % (
             u' '.join([u'(%s=*%s%s)' % (field, query, post)
-                       for field in ['cn', 'uid', 'mail']]))
+                       for field in ['cn', 'displayName', 'uid', 'mail']]))
         r = connection.search_s(
             CONFIG.get('connection', 'basedn'),
             ldap.SCOPE_SUBTREE,
@@ -100,8 +100,9 @@ def search(query, connection=None):
 def format_entry(entry):
     cn,data = entry
     if 'mail' in data:
+        name = data.get('displayName', data['cn'])[-1]
         for m in data['mail']:
-            yield email.utils.formataddr((data['cn'][-1], m))
+            yield email.utils.formataddr((name, m))
 
 
 if __name__ == '__main__':