From 5a3424909087144ef2950a93e594f85347042167 Mon Sep 17 00:00:00 2001 From: "Piotr F. Mieszkowski" Date: Sun, 10 Apr 2022 19:03:18 +0200 Subject: [PATCH] Fix minor cron.py issues Related to #63: TypeError: memoryview: a bytes-like object is required, not 'str'. - Allow GnuPG.add_key accept either 'str' or 'bytes'. - Import MIMEText from email.mime.text. --- GnuPG/__init__.py | 2 ++ gpg-mailgate-web/cron.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/GnuPG/__init__.py b/GnuPG/__init__.py index 8bcfebd..b6c79aa 100644 --- a/GnuPG/__init__.py +++ b/GnuPG/__init__.py @@ -102,6 +102,8 @@ def confirm_key( content, email ): # adds a key and ensures it has the given email address def add_key( keyhome, content ): + if type(content) == 'str': + content = bytes(content, sys.getdefaultencoding()) p = subprocess.Popen( build_command(keyhome, '--import', '--batch'), stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE ) p.communicate(input=content) p.wait() diff --git a/gpg-mailgate-web/cron.py b/gpg-mailgate-web/cron.py index 98cd8d1..83952c4 100644 --- a/gpg-mailgate-web/cron.py +++ b/gpg-mailgate-web/cron.py @@ -25,7 +25,7 @@ import MySQLdb import smtplib import markdown import syslog -from email.MIMEText import MIMEText +from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart def appendLog(msg):