From c9ba57a7c8214f7b2b2028e7c11717959d1e6c8c Mon Sep 17 00:00:00 2001 From: Wade Berrier Date: Sat, 19 Jan 2013 18:34:51 -0700 Subject: [PATCH] Add support for an optional display column Again, according to http://www.mutt.org/doc/manual/manual-4.html#ss4.5 --- mutt-ldap.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/mutt-ldap.py b/mutt-ldap.py index 7029b60..7a41c03 100755 --- a/mutt-ldap.py +++ b/mutt-ldap.py @@ -56,6 +56,8 @@ 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.add_section('results') +CONFIG.set('results', 'optional_column', '') # mutt can display one optional column CONFIG.read(os.path.expanduser('~/.mutt-ldap.rc')) def connect(): @@ -103,14 +105,20 @@ def search(query, connection=None): connection.unbind() return r +def format_columns(address, data): + yield address + yield data.get('displayName', data['cn'])[-1] + optional_column = CONFIG.get('results', 'optional_column') + if optional_column in data: + yield data[optional_column][-1] + def format_entry(entry): cn,data = entry if 'mail' in data: - name = data.get('displayName', data['cn'])[-1] for m in data['mail']: # http://www.mutt.org/doc/manual/manual-4.html#ss4.5 # Describes the format mutt expects: address\tname - yield "\t".join([m, name]) + yield "\t".join(format_columns(m, data)) if __name__ == '__main__': -- 2.26.2