From 0307793666fc9f1db82579e4529b1c185083e13b Mon Sep 17 00:00:00 2001 From: Son NK <> Date: Wed, 28 Oct 2020 17:07:53 +0100 Subject: [PATCH] use pgpy as fallback for gpg --- email_handler.py | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/email_handler.py b/email_handler.py index b454cf59..8b37ef39 100644 --- a/email_handler.py +++ b/email_handler.py @@ -420,27 +420,16 @@ def prepare_pgp_message(orig_msg: Message, pgp_fingerprint: str, public_key: str second.add_header("Content-Disposition", 'inline; filename="encrypted.asc"') # encrypt original message - # ABTest between pgpy and python-gnupg - x = random.randint(0, 9) - if x >= 5: - LOG.d("encrypt using python-gnupg") - try: - encrypted_data = pgp_utils.encrypt_file( - BytesIO(orig_msg.as_bytes()), pgp_fingerprint - ) - second.set_payload(encrypted_data) - except PGPException: - LOG.exception("Cannot encrypt using python-gnupg, use pgpy") - encrypted_data = pgp_utils.encrypt_file_with_pgpy( - orig_msg.as_bytes(), public_key - ) - second.set_payload(str(encrypted_data)) - else: - LOG.d("encrypt using pgpy") - encrypted_data = pgp_utils.encrypt_file_with_pgpy( - orig_msg.as_bytes(), public_key + # use pgpy as fallback + try: + encrypted_data = pgp_utils.encrypt_file( + BytesIO(orig_msg.as_bytes()), pgp_fingerprint ) - second.set_payload(str(encrypted_data)) + second.set_payload(encrypted_data) + except PGPException: + LOG.exception("Cannot encrypt using python-gnupg, use pgpy") + encrypted = pgp_utils.encrypt_file_with_pgpy(orig_msg.as_bytes(), public_key) + second.set_payload(str(encrypted)) msg.attach(second)