created a function for choosing the encryption key
authorAndrew Engelbrecht <andrew@localhost.localdomain>
Sat, 18 Jul 2015 21:28:08 +0000 (17:28 -0400)
committerAndrew Engelbrecht <sudoman@ninthfloor.org>
Mon, 7 Dec 2015 17:46:48 +0000 (12:46 -0500)
this is somewhat more intelligent and can be improved upon later.

edward-bot

index 76c375870e21c43db0dbf2004ab305bfd5c15070..ce55408225038e0d7a5143755a1f8a9af938515e 100755 (executable)
@@ -45,12 +45,13 @@ def main ():
     plaintext, keys = email_decode_flatten (email_text)
     email_from, email_subject = email_from_subject(email_text)
 
+    reply_encrypt_to_key = choose_reply_encryption_key(keys)
+
     print("From: " + email_from)
     print("Subject: " + email_subject)
     print(plaintext)
 
-    for key in keys:
-        print(key.subkeys[0].fpr)
+    print(reply_encrypt_to_key.subkeys[0].fpr)
 
 
 def email_decode_flatten (email_text):
@@ -206,6 +207,17 @@ def decrypt_chunk (gpg_chunk):
     return (plaintext, sigs)
 
 
+def choose_reply_encryption_key (keys):
+
+    reply_key = None
+    for key in keys:
+        if (key.can_encrypt == True):
+            reply_key = key
+            break
+
+    return key
+
+
 def handle_args ():
     if __name__ == "__main__":