search text/plain for keys and encoded messages
authorAndrew Engelbrecht <sudoman@ninthfloor.org>
Sun, 19 Jul 2015 23:49:10 +0000 (19:49 -0400)
committerAndrew Engelbrecht <sudoman@ninthfloor.org>
Mon, 7 Dec 2015 18:16:28 +0000 (13:16 -0500)
also don't scan the outer-most layer for keys because that gives
corrupted files. they are still accessible under the content type of
text/plain, even if the email's not a mime-formatted message.

edward

diff --git a/edward b/edward
index ca6ef082affc034fe44be65fb9bb19df0b9b5122..baf3059e83d4579b92f8784adb94a4527457f251 100755 (executable)
--- a/edward
+++ b/edward
@@ -59,9 +59,7 @@ def main ():
     gpgme_ctx = gpgme.Context()
     gpgme_ctx.armor = True
 
-    add_gpg_keys(email_text, gpgme_ctx)
-
-    plaintext, keys = email_decode_flatten(email_text, gpgme_ctx)
+    plaintext, keys = email_decode_flatten(email_text, gpgme_ctx, False)
     encrypt_to_key = choose_reply_encryption_key(keys)
 
     reply_message = generate_reply(plaintext, email_from, \
@@ -72,7 +70,7 @@ def main ():
     print(reply_message)
 
 
-def email_decode_flatten (email_text, gpgme_ctx):
+def email_decode_flatten (email_text, gpgme_ctx, from_decryption):
 
     body = ""
     keys = []
@@ -109,10 +107,16 @@ def email_decode_flatten (email_text, gpgme_ctx):
             keys += add_gpg_keys(payload, gpgme_ctx)
 
         elif content_type == "text/plain":
-            body += payload + "\n"
+            if from_decryption == True:
+                body += payload + "\n"
+
+            else:
+                plaintext, more_keys = decrypt_text(payload, gpgme_ctx)
+
+                body += plaintext
+                keys += more_keys
 
-        else:
-            body += payload + "\n"
+                keys += add_gpg_keys(payload, gpgme_ctx)
 
     return body, keys
 
@@ -193,7 +197,7 @@ def decrypt_text (gpg_text, gpgme_ctx):
             keys += [gpgme_ctx.get_key(sig.fpr)]
 
         # recursive for nested layers of mime and/or gpg
-        plaintext, more_keys = email_decode_flatten(plaintext, gpgme_ctx)
+        plaintext, more_keys = email_decode_flatten(plaintext, gpgme_ctx, True)
 
         body += plaintext
         keys += more_keys