updated the message flattener
authorAndrew Engelbrecht <sudoman@ninthfloor.org>
Thu, 23 Jul 2015 16:04:38 +0000 (12:04 -0400)
committerAndrew Engelbrecht <sudoman@ninthfloor.org>
Mon, 7 Dec 2015 18:28:40 +0000 (13:28 -0500)
it no longer prints nested layers of decrypted text.

edward

diff --git a/edward b/edward
index 091716c093d2c57e2d3f3cb4b9ccb3cd352105dd..b790a2a34406d2ea47c6a8d12467ba16775f1aa0 100755 (executable)
--- a/edward
+++ b/edward
@@ -369,30 +369,36 @@ def prepare_for_reply_pieces (eddymsg_obj, replyinfo_obj):
 
 
 
-def flatten_payloads (eddymsg_obj):
+def flatten_decrypted_payloads (eddymsg_obj, get_signed_part):
 
     flat_string = ""
 
     if eddymsg_obj == None:
         return ""
 
+    # recurse on multi-part mime
     if eddymsg_obj.multipart == True:
         for sub in eddymsg_obj.subparts:
-            flat_string += flatten_payloads (sub)
+            flat_string += flatten_decrypted_payloads (sub)
 
         return flat_string
 
-    # todo: don't include nested decrypted messages.
     for piece in eddymsg_obj.payload_pieces:
         if piece.piece_type == "text":
             flat_string += piece.string
-        elif piece.piece_type == "message":
-            flat_string += flatten_payloads(piece.plainobj)
-        elif ((piece.piece_type == "clearsign") \
-                or (piece.piece_type == "detachedsig")) \
-                and (piece.gpg_data != None):
-                    flat_string += flatten_payloads (piece.gpg_data.plainobj)
 
+        if (get_signed_part):
+            # don't include nested encryption
+            elif (piece.piece_type == "message") \
+                    and (piece.gpg_data != None) \
+                    and (piece.gpg_data.decrypted == False):
+                        flat_string += flatten_decrypted_payloads(piece.gpg_data.plainobj, get_signed_part)
+
+            elif ((piece.piece_type == "clearsign") \
+                    or (piece.piece_type == "detachedsig")) \
+                    and (piece.gpg_data != None):
+                        # FIXME: the key used to sign this message needs to be the one that is used for the encrypted reply.
+                        flat_string += flatten_decrypted_payloads (piece.gpg_data.plainobj, get_signed_part)
 
     return flat_string