From 61120dd4e85422d01eccb67a3324c09916a0ea99 Mon Sep 17 00:00:00 2001 From: revsuine Date: Tue, 12 Nov 2024 19:00:56 +0000 Subject: [PATCH] revert gpgmymail to 40b3ba376024d31386916e1f11438a2f1a905c6f --- gpgmymail | 29 ++--------------------------- 1 file changed, 2 insertions(+), 27 deletions(-) diff --git a/gpgmymail b/gpgmymail index 7062dcf..a3c230f 100755 --- a/gpgmymail +++ b/gpgmymail @@ -40,13 +40,6 @@ import gnupg # constants DEFAULT_ENCODING='utf-8' # default is latin-1 which fails w some unicode chars -CTE_TO_ENCODER_DICT = { - "7bit": email.encoders.encode_7or8bit, - "8bit": email.encoders.encode_7or8bit, - "base64": email.encoders.encode_base64, - "quoted-printable": email.encoders.encode_quopri -} -DEFAULT_ENCODER = email.encoders.encode_7or8bit def is_message_encrypted(message: email.message.Message) -> bool: """Determines whether or not an email message is encrypted. @@ -56,24 +49,6 @@ def is_message_encrypted(message: email.message.Message) -> bool: return message.get_content_subtype() == "encrypted" -def get_encoder_from_msg(msg: email.message.Message) -> typing.Callable: - """ - Return a suitable encoder function from email.encoders based on an input - message. If the input message has no Content-Transfer-Encoding header, - or there is no encoder function corresponding to the CTE header, a default - encoder will be returned. - - :param msg: an unencrypted email Message - :return: function from email.encoders, see - https://docs.python.org/3/library/email.encoders.html - """ - cte = msg.get("Content-Transfer-Encoding") - if cte: - encoder = CTE_TO_ENCODER_DICT.get(cte) - else: - return DEFAULT_ENCODER - return encoder if encoder else DEFAULT_ENCODER - def encrypt( message: email.message.Message, recipients: typing.List[str], @@ -107,13 +82,13 @@ def encrypt( enc = email.mime.application.MIMEApplication( _data=str(encrypted_content).encode(), _subtype="octet-stream", - _encoder=get_encoder_from_msg(message) + _encoder=email.encoders.encode_7or8bit ) control = email.mime.application.MIMEApplication( _data=b'Version: 1\n', _subtype='pgp-encrypted; name="msg.asc"', - _encoder=get_encoder_from_msg(message) + _encoder=email.encoders.encode_7or8bit ) control['Content-Disposition'] = 'inline; filename="msg.asc"'