aboutsummaryrefslogtreecommitdiffstats
path: root/interfaces/email/interactive
diff options
context:
space:
mode:
authorW. Trevor King <wking@drexel.edu>2009-09-23 06:30:31 -0400
committerW. Trevor King <wking@drexel.edu>2009-09-23 06:30:31 -0400
commit73bc42e2641a45147e5b4accd63079fa8eb1d09e (patch)
treec3a570a0aac16f813726cdc874d7a2f69fe6a595 /interfaces/email/interactive
parente174881e3e39fbffa75aa0a1f858998827ad204c (diff)
downloadbugseverywhere-73bc42e2641a45147e5b4accd63079fa8eb1d09e.tar.gz
Convert incoming text/* email payloads to unicode in be-handle-mail.
Switched from cStringIO to StringIO in be-handle-mail because: (from http://docs.python.org/library/stringio.html) "Unlike the memory files implemented by the StringIO module, those provided by this [cStringIO] module are not able to accept Unicode strings that cannot be encoded as plain ASCII strings." I'm not sure what all the fuss with sys.__stdin__ had been about in Command.run(), but I took it out and everything still seems to work ;). Also fix Makefail (again!) to install under $HOME by default.
Diffstat (limited to 'interfaces/email/interactive')
-rwxr-xr-xinterfaces/email/interactive/be-handle-mail15
1 files changed, 7 insertions, 8 deletions
diff --git a/interfaces/email/interactive/be-handle-mail b/interfaces/email/interactive/be-handle-mail
index 666ac18..bcb9519 100755
--- a/interfaces/email/interactive/be-handle-mail
+++ b/interfaces/email/interactive/be-handle-mail
@@ -47,7 +47,7 @@ executed, with the email's post-tag subject as the commit message.
"""
import codecs
-import cStringIO as StringIO
+import StringIO as StringIO
import email
from email.mime.multipart import MIMEMultipart
import email.utils
@@ -228,11 +228,8 @@ class Command (object):
self.normalize_args()
# set stdin and catch stdout and stderr
if self.stdin != None:
- new_stdin = StringIO.StringIO(self.stdin)
- orig___stdin = sys.__stdin__
- sys.__stdin__ = new_stdin
orig_stdin = sys.stdin
- sys.stdin = new_stdin
+ sys.stdin = StringIO.StringIO(self.stdin)
new_stdout = codecs.getwriter(ENCODING)(StringIO.StringIO())
new_stderr = codecs.getwriter(ENCODING)(StringIO.StringIO())
orig_stdout = sys.stdout
@@ -256,8 +253,6 @@ class Command (object):
"%s\n%s" % (type(e), unicode(e)))
# restore stdin, stdout, and stderr
if self.stdin != None:
- sys.__stdin__ = new_stdin
- sys.__stdin__ = orig___stdin
sys.stdin = orig_stdin
sys.stdout.flush()
sys.stderr.flush()
@@ -437,10 +432,14 @@ class Message (object):
Traverse the email message returning (body, mime_type) for
each non-mulitpart portion of the message.
"""
+ msg_charset = self.msg.get_content_charset(ENCODING).lower()
for part in self.msg.walk():
if part.is_multipart():
continue
- body,mime_type=(part.get_payload(decode=1),part.get_content_type())
+ body,mime_type=(part.get_payload(decode=True),part.get_content_type())
+ charset = part.get_content_charset(msg_charset).lower()
+ if mime_type.startswith("text/"):
+ body = unicode(body, charset) # convert text types to unicode
yield (body, mime_type)
def _parse_body_pseudoheaders(self, body, required, optional,
dictionary=None):