diff options
author | Matěj Cepl <mcepl@cepl.eu> | 2024-01-18 19:09:58 +0100 |
---|---|---|
committer | Matěj Cepl <mcepl@cepl.eu> | 2024-01-18 19:09:58 +0100 |
commit | cc7362d28bd9c43cb6839809f86e59874f2fe458 (patch) | |
tree | 1053748f5890c769d1e99806bc0c8bcffca6f0fe /interfaces/email | |
parent | 003bd13629d9db2f14156f97b74a4672e9ecdf77 (diff) | |
download | bugseverywhere-cc7362d28bd9c43cb6839809f86e59874f2fe458.tar.gz |
2to3 conversion of the repo.
Diffstat (limited to 'interfaces/email')
-rw-r--r-- | interfaces/email/interactive/send_pgp_mime.py | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/interfaces/email/interactive/send_pgp_mime.py b/interfaces/email/interactive/send_pgp_mime.py index 8febe10..e0ffbd5 100644 --- a/interfaces/email/interactive/send_pgp_mime.py +++ b/interfaces/email/interactive/send_pgp_mime.py @@ -27,7 +27,7 @@ the pgp_* commands. You may need to adjust the sendmail command to point to whichever sendmail-compatible mailer you have on your system. """ -from cStringIO import StringIO +from io import StringIO import os import re #import GnuPGInterface # Maybe should use this instead of subprocess @@ -150,16 +150,16 @@ def header_from_text(text, encoding="us-ascii"): <BLANKLINE> """ text = text.strip() - if type(text) == types.UnicodeType: + if type(text) == str: text = text.encode(encoding) # assume StringType arguments are already encoded p = Parser() return p.parsestr(text, headersonly=True) def guess_encoding(text): - if type(text) == types.StringType: + if type(text) == bytes: encoding = "us-ascii" - elif type(text) == types.UnicodeType: + elif type(text) == str: for encoding in ["us-ascii", "iso-8859-1", "utf-8"]: try: text.encode(encoding) @@ -181,7 +181,7 @@ def encodedMIMEText(body, encoding=None): 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_payload = "%s%s" % (original_payload, new_text) new_encoding = guess_encoding(new_payload) text_part.set_payload(new_payload.encode(new_encoding), new_encoding) @@ -190,7 +190,7 @@ def attach_root(header, root_part): Attach the email.Message root_part to the email.Message header without generating a multi-part message. """ - for k,v in header.items(): + for k,v in list(header.items()): root_part[k] = v return root_part @@ -199,19 +199,19 @@ def execute(args, stdin=None, expect=(0,)): Execute a command (allows us to drive gpg). """ if verboseInvoke == True: - print >> sys.stderr, '$ '+args + print('$ '+args, file=sys.stderr) try: p = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, close_fds=True) - except OSError, e: + except OSError as e: strerror = '%s\nwhile executing %s' % (e.args[1], args) - raise Exception, strerror + raise Exception(strerror) output, error = p.communicate(input=stdin) status = p.wait() if verboseInvoke == True: - print >> sys.stderr, '(status: %d)\n%s%s' % (status, output, error) + print('(status: %d)\n%s%s' % (status, output, error), file=sys.stderr) if status not in expect: strerror = '%s\nwhile executing %s\n%s\n%d' % (args[1], args, error, status) - raise Exception, strerror + raise Exception(strerror) return status, output, error def replace(template, format_char, replacement_text): @@ -245,7 +245,7 @@ def flatten(msg, to_unicode=False): text = fp.getvalue() if to_unicode == True: encoding = msg.get_content_charset() or "utf-8" - text = unicode(text, encoding=encoding) + text = str(text, encoding=encoding) return text def source_email(msg, return_realname=False): @@ -581,7 +581,7 @@ if __name__ == '__main__': else: header = file(options.header_filename, 'r').read() if header == None: - raise Exception, "missing header" + raise Exception("missing header") headermsg = header_from_text(header) body = None if options.body_filename != None: @@ -592,7 +592,7 @@ if __name__ == '__main__': else: body = file(options.body_filename, 'r').read() if body == None: - raise Exception, "missing body" + raise Exception("missing body") m = PGPMimeMessageFactory(body) if options.mode == "sign": @@ -609,6 +609,6 @@ if __name__ == '__main__': message = attach_root(headermsg, bodymsg) if options.output == True: message = flatten(message) - print message + print(message) else: mail(message, sendmail) |