aboutsummaryrefslogtreecommitdiffstats
path: root/interfaces/email/interactive/send_pgp_mime.py
diff options
context:
space:
mode:
authorW. Trevor King <wking@drexel.edu>2009-07-27 14:42:17 -0400
committerW. Trevor King <wking@drexel.edu>2009-07-27 14:42:17 -0400
commitf5fdbda0472ad3b37e098561fcd52df6bf06199f (patch)
treee69e05e00c5df114d136c2cf940d05a0a660c27f /interfaces/email/interactive/send_pgp_mime.py
parentdc69839cbe8ae9b03200a9bb2bd395ffebd6675e (diff)
downloadbugseverywhere-f5fdbda0472ad3b37e098561fcd52df6bf06199f.tar.gz
Cleaned up be-handle-mail's subscriber notification emails (fewer attachments).
Previously, every node in the DiffTree created it's own attachment. Now they're consolidated into a single attachment per bug. higher level nodes are still one attachment per node. Also: * added send_pgp_mime.append_text() * pulled guess_encoding() out of send_pgp_mime.encodedMIMEText(). * renamed data_string -> data_part in libbe.diff, since it needn't be a string.
Diffstat (limited to 'interfaces/email/interactive/send_pgp_mime.py')
-rw-r--r--interfaces/email/interactive/send_pgp_mime.py34
1 files changed, 22 insertions, 12 deletions
diff --git a/interfaces/email/interactive/send_pgp_mime.py b/interfaces/email/interactive/send_pgp_mime.py
index 09ac0ed..55767b3 100644
--- a/interfaces/email/interactive/send_pgp_mime.py
+++ b/interfaces/email/interactive/send_pgp_mime.py
@@ -153,25 +153,35 @@ def header_from_text(text, encoding="us-ascii"):
p = Parser()
return p.parsestr(text, headersonly=True)
+def guess_encoding(text):
+ if type(text) == types.StringType:
+ encoding = "us-ascii"
+ elif type(text) == types.UnicodeType:
+ for encoding in ["us-ascii", "iso-8859-1", "utf-8"]:
+ try:
+ text.encode(encoding)
+ except UnicodeError:
+ pass
+ else:
+ break
+ assert encoding != None
+ return encoding
+
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)
+ encoding = guess_encoding(body)
if encoding == "us-ascii":
return MIMEText(body)
else:
+ # Create the message ('plain' stands for Content-Type: text/plain)
return MIMEText(body.encode(encoding), 'plain', encoding)
+def append_text(text_part, new_text):
+ original_payload = text_part.get_payload(decode=True)
+ new_payload = u"%s%s" % (original_payload, new_text)
+ new_encoding = guess_encoding(new_payload)
+ text_part.set_payload(new_payload.encode(new_encoding), new_encoding)
+
def attach_root(header, root_part):
"""
Attach the email.Message root_part to the email.Message header