From: Wade Berrier Date: Sun, 20 Jan 2013 01:34:51 +0000 (-0700) Subject: Add support for an optional display column X-Git-Tag: v0.1~27^2~4 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=c9ba57a7c8214f7b2b2028e7c11717959d1e6c8c;p=mutt-ldap.git Add support for an optional display column Again, according to http://www.mutt.org/doc/manual/manual-4.html#ss4.5 --- 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__':