aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorW. Trevor King <wking@drexel.edu>2009-07-18 09:04:25 -0400
committerW. Trevor King <wking@drexel.edu>2009-07-18 09:04:25 -0400
commit6c0b67973dd95dfdc0ddfb29edfb793773f7115c (patch)
treed3412dcfb2a40b323e59d1b9f11176b47162bec7
parent906f1ecc5199e0c99d344bb0589958043609ca3f (diff)
downloadbugseverywhere-6c0b67973dd95dfdc0ddfb29edfb793773f7115c.tar.gz
send_pgp_mime.py attempts to avoid UTF-8 for MIMEText messages.
This keeps the transfer-encoding out of base64 if possible. Also added a "help" example to interafaces/email/interactive/examples.
-rw-r--r--interfaces/email/interactive/examples/help9
-rw-r--r--interfaces/email/interactive/send_pgp_mime.py20
2 files changed, 24 insertions, 5 deletions
diff --git a/interfaces/email/interactive/examples/help b/interfaces/email/interactive/examples/help
new file mode 100644
index 0000000..14e887c
--- /dev/null
+++ b/interfaces/email/interactive/examples/help
@@ -0,0 +1,9 @@
+From jdoe@example.com Fri Apr 18 11:18:58 2008
+Message-ID: <abcd@example.com>
+Date: Fri, 18 Apr 2008 12:00:00 +0000
+From: John Doe <jdoe@example.com>
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+Subject: [be-bug] help
+
+Dummy content
diff --git a/interfaces/email/interactive/send_pgp_mime.py b/interfaces/email/interactive/send_pgp_mime.py
index f66c626..38a2437 100644
--- a/interfaces/email/interactive/send_pgp_mime.py
+++ b/interfaces/email/interactive/send_pgp_mime.py
@@ -80,7 +80,6 @@ have been warned.
verboseInvoke = False
PGP_SIGN_AS = None
PASSPHRASE = None
-DEFAULT_BODY_ENCODING = "UTF-8"
# The following commands are adapted from my .mutt/pgp configuration
#
@@ -346,11 +345,22 @@ class Mail (object):
return target_emails(self.headermsg)
def encodedMIMEText(self, body, encoding=None):
if encoding == None:
- encoding = DEFAULT_BODY_ENCODING
- if type(body) == types.StringType:
- encoding = "US-ASCII"
+ if type(body) == types.StringType:
+ encoding = "US-ASCII"
+ elif type(body) == types.UnicodeType:
+ for encoding in ["US-ASCII", "ISO-8859-1", "UTF-8"]:
+ try:
+ body.encode(encoding)
+ except UnicodeError:
+ pass
+ else:
+ break
+ assert encoding != None
# Create the message ('plain' stands for Content-Type: text/plain)
- return MIMEText(body.encode(encoding), 'plain', encoding)
+ if encoding == "US-ASCII":
+ return MIMEText(body)
+ else:
+ return MIMEText(body.encode(encoding), 'plain', encoding)
def clearBodyPart(self):
body = self.encodedMIMEText(self.body)
body.add_header('Content-Disposition', 'inline')