From b1d45029a439eb1e3351bb03f21ca4964d7bcf08 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sun, 20 Jan 2013 09:33:47 -0500 Subject: [PATCH] Decode search results to Unicode and print as Unicode LDAPv3 strings are encoded in UTF-8 [1], so use that encoding to decode them in format_columns(). Adjust format_entry() and the main block to handle the Unicode output from format_columns(). [1]: http://tools.ietf.org/html/rfc2251#section-4.1.2 --- mutt-ldap.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mutt-ldap.py b/mutt-ldap.py index 808f636..3938d5b 100755 --- a/mutt-ldap.py +++ b/mutt-ldap.py @@ -121,11 +121,11 @@ def search(query, connection): yield entry def format_columns(address, data): - yield address - yield data.get('displayName', data['cn'])[-1] + yield unicode(address, 'utf-8') + yield unicode(data.get('displayName', data['cn'])[-1], 'utf-8') optional_column = CONFIG.get('results', 'optional_column') if optional_column in data: - yield data[optional_column][-1] + yield unicode(data[optional_column][-1], 'utf-8') def format_entry(entry): cn,data = entry @@ -133,7 +133,7 @@ def format_entry(entry): 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(format_columns(m, data)) + yield u'\t'.join(format_columns(m, data)) def cache_filename(query): # TODO: is the query filename safe? @@ -197,5 +197,5 @@ if __name__ == '__main__': if connection: connection.unbind() - print('{0} addresses found:'.format(len(addresses))) - print('\n'.join(addresses)) + print(u'{0} addresses found:'.format(len(addresses))) + print(u'\n'.join(addresses)) -- 2.26.2