Added "to_unicode" to send_pgp_mime.flatten()
authorW. Trevor King <wking@drexel.edu>
Sat, 18 Jul 2009 13:21:03 +0000 (09:21 -0400)
committerW. Trevor King <wking@drexel.edu>
Tue, 20 Mar 2012 21:19:16 +0000 (17:19 -0400)
be-handle-mail wants unicode output, since all it's internal
processing is done with unicode.  However, the flatten calls in
send_pgp_mime work with the encoded binary string output, and
execute(sendmail, stdin=flatten(msg, to_unicode=True)) fails
with
  Exception: u
  while executing /usr/sbin/sendmail -t
  sendmail: fatal: wking(1001): No recipient addresses found in message header

interfaces/email/interactive/send_pgp_mime.py

index 38a2437b0c7d5eb421334f85aeef6acf2ebbe433..e0451c9699955dd49daf16f1ab6d703e145975b2 100644 (file)
@@ -155,7 +155,7 @@ def replace(template, format_char, replacement_text):
     str = regexp.sub(replacement_text, str)
     return str
 
-def flatten(msg):
+def flatten(msg, to_unicode=False):
     """
     Produce flat text output from an email Message instance.
     """
@@ -164,8 +164,10 @@ def flatten(msg):
     g = Generator(fp, mangle_from_=False)
     g.flatten(msg)
     text = fp.getvalue()
-    encoding = msg.get_content_charset()
-    return unicode(text, encoding=encoding)
+    if to_unicode == True:
+        encoding = msg.get_content_charset()
+        text = unicode(text, encoding=encoding)
+    return text
 
 def source_email(msg, return_realname=False):
     """