aboutsummaryrefslogtreecommitdiffstats
path: root/interfaces/email/interactive/send_pgp_mime.py
diff options
context:
space:
mode:
authorW. Trevor King <wking@drexel.edu>2009-07-23 11:37:45 -0400
committerW. Trevor King <wking@drexel.edu>2009-07-23 11:37:45 -0400
commit988b86a70cfc493f51b71e3e0b7effa439719a13 (patch)
tree7be9ef7243eabed19994264e8c4a6f31f768b9d7 /interfaces/email/interactive/send_pgp_mime.py
parentcff3dd5c32cb67b47d2712cf6a1b51e7b6eead4b (diff)
downloadbugseverywhere-988b86a70cfc493f51b71e3e0b7effa439719a13.tar.gz
Broke encodedMIMEText out of send-pgp-mime.PGPMimeMessageFactory.
It's useful enough even when you're not intending to encrypt something.
Diffstat (limited to 'interfaces/email/interactive/send_pgp_mime.py')
-rw-r--r--interfaces/email/interactive/send_pgp_mime.py41
1 files changed, 21 insertions, 20 deletions
diff --git a/interfaces/email/interactive/send_pgp_mime.py b/interfaces/email/interactive/send_pgp_mime.py
index babd720..09ac0ed 100644
--- a/interfaces/email/interactive/send_pgp_mime.py
+++ b/interfaces/email/interactive/send_pgp_mime.py
@@ -153,6 +153,25 @@ def header_from_text(text, encoding="us-ascii"):
p = Parser()
return p.parsestr(text, headersonly=True)
+def encodedMIMEText(body, encoding=None):
+ if encoding == None:
+ 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)
+ if encoding == "us-ascii":
+ return MIMEText(body)
+ else:
+ return MIMEText(body.encode(encoding), 'plain', encoding)
+
def attach_root(header, root_part):
"""
Attach the email.Message root_part to the email.Message header
@@ -355,26 +374,8 @@ class PGPMimeMessageFactory (object):
"""
def __init__(self, body):
self.body = body
- def encodedMIMEText(self, body, encoding=None):
- if encoding == None:
- 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)
- if encoding == "us-ascii":
- return MIMEText(body)
- else:
- return MIMEText(body.encode(encoding), 'plain', encoding)
def clearBodyPart(self):
- body = self.encodedMIMEText(self.body)
+ body = encodedMIMEText(self.body)
body.add_header('Content-Disposition', 'inline')
return body
def passphrase_arg(self, passphrase=None):
@@ -387,7 +388,7 @@ class PGPMimeMessageFactory (object):
"""
text/plain
"""
- return self.encodedMIMEText(self.body)
+ return encodedMIMEText(self.body)
def sign(self, header, passphrase=None):
"""
multipart/signed