From: Stephen Gran Date: Sun, 24 May 2009 13:40:49 +0000 (+0100) Subject: Two problems with my first commit: X-Git-Tag: userdir-ldap-0.3.67~11 X-Git-Url: https://git.adam-barratt.org.uk/?a=commitdiff_plain;ds=sidebyside;h=c18ac1149b9051374d362dd6aea52485dc31a997;p=mirror%2Fuserdir-ldap.git Two problems with my first commit: We need to specify the RFC 2047 character set as utf-8, not us-ascii, for the encoding type field in the header We need to only encode the FullName, and then tack on the emailaddr. The examples in the RFC show this behavior, and at least mutt won't decode the header if the email address is also RFC 2047 encoded (which makes some sense - currently email addresses can only really be ascii). --- diff --git a/ud-useradd b/ud-useradd index 62e4f4d..0c6bc04 100755 --- a/ud-useradd +++ b/ud-useradd @@ -237,15 +237,14 @@ if Res != "yes": # Initialize the substitution Map Subst = {} -emailstring = FullName + " " + emailaddr encto = '' try: - encto = emailstring.encode('us-ascii') + encto = FullName.encode('us-ascii') except UnicodeDecodeError: - if email.base64mime.base64_len(emailstring) < email.quoprimime.header_quopri_len(emailstring): - encto = email.base64mime.header_encode(emailstring, 'us-ascii') + if email.base64mime.base64_len(FullName) < email.quoprimime.header_quopri_len(FullName): + encto = email.base64mime.header_encode(FullName, 'utf-8') + " " + emailaddr else: - encto = email.quoprimime.header_encode(emailstring, 'us-ascii') + encto = email.quoprimime.header_encode(FullName, 'utf-8') + " " + emailaddr subjstring = "New Debian Maintainer " + FullName encsubj = '' @@ -253,9 +252,9 @@ try: encsubj = subjstring.encode('us-ascii') except UnicodeDecodeError: if email.base64mime.base64_len(subjstring) < email.quoprimime.header_quopri_len(subjstring): - encsubj = email.base64mime.header_encode(subjstring, 'us-ascii') + encsubj = email.base64mime.header_encode(subjstring, 'utf-8') else: - encsubj = email.quoprimime.header_encode(subjstring, 'us-ascii') + encsubj = email.quoprimime.header_encode(subjstring, 'utf-8') Subst["__HEADER_SUBJ__"] = encsubj Subst["__HEADER_EMAIL"] = encto