first attempt to implement decoding as 7or8bit (non-working)

This commit is contained in:
revsuine 2024-11-13 17:22:21 +00:00
parent 61120dd4e8
commit ed57c8f0d4
Signed by: revsuine
GPG key ID: 3F257B68F5BC9339

View file

@ -49,6 +49,23 @@ def is_message_encrypted(message: email.message.Message) -> bool:
return message.get_content_subtype() == "encrypted" return message.get_content_subtype() == "encrypted"
def decode_email(message: email.message.Message) -> email.message.Message:
"""Turn a quoted-printable or base64 encoded email into a 7or8bit encoded
email
:param message: email.message.Message to be decoded
:return: decoded email.message.Message"""
payload = []
for part in message.walk():
if not part.is_multipart():
payload.append(part.get_payload(decode=True))
message["Content-Transfer-Encoding"] = "7bit"
message.set_payload(payload)
return message
def encrypt( def encrypt(
message: email.message.Message, message: email.message.Message,
recipients: typing.List[str], recipients: typing.List[str],
@ -67,10 +84,14 @@ def encrypt(
:return: The encrypted email as a string""" :return: The encrypted email as a string"""
# exclusion criteria:
# some mail clients like Thunderbird don't like twice-encrypted emails, # some mail clients like Thunderbird don't like twice-encrypted emails,
# so we return the message as-is if it's already encrypted # so we return the message as-is if it's already encrypted
if is_message_encrypted(message) and not unconditionally_encrypt: if is_message_encrypted(message) and not unconditionally_encrypt:
return message.as_string() return message.as_string()
# make necessary changes to message
message = decode_email(message)
gpg = gnupg.GPG() gpg = gnupg.GPG()
gpg.encoding = encoding gpg.encoding = encoding