created higher order function used by flatten_eddy
authorAndrew Engelbrecht <sudoman@ninthfloor.org>
Tue, 21 Jul 2015 22:09:21 +0000 (18:09 -0400)
committerAndrew Engelbrecht <sudoman@ninthfloor.org>
Mon, 7 Dec 2015 18:28:38 +0000 (13:28 -0500)
it will also be used by the decryption function.

edward

diff --git a/edward b/edward
index 8f373a4ef1e3f577822c2cfd96ef51384ec9caec..c7adf7138cb8b670d31273557664d3e8dd8f9f73 100755 (executable)
--- a/edward
+++ b/edward
@@ -137,7 +137,8 @@ def parse_mime(msg_struct):
         payloads = msg_struct.get_payload()
 
         eddy_obj.multipart = True
-        eddy_obj.subparts = map(parse_mime, payloads)
+        eddy_obj.subparts = list(map(parse_mime, payloads))
+
     else:
         eddy_obj = get_subpart_data(msg_struct)
 
@@ -147,7 +148,7 @@ def parse_mime(msg_struct):
 def split_payloads (eddy_obj):
 
     if eddy_obj.multipart == True:
-        eddy_obj.subparts = map(split_payloads, eddy_obj.subparts)
+        eddy_obj.subparts = list(map(split_payloads, eddy_obj.subparts))
 
     else:
         for (match_type, pattern) in match_types:
@@ -222,17 +223,26 @@ def get_subpart_data (part):
     return obj
 
 
-def flatten_eddy (eddy_obj):
+def do_to_eddys_pieces (function_to_do, eddy_obj, data):
 
     if eddy_obj.multipart == True:
-        string = "\n".join(map(flatten_eddy, eddy_obj.subparts))
+        result_list = []
+        for sub in eddy_obj.subparts:
+            result_list += do_to_eddys_pieces(function_to_do, sub, data)
     else:
-        string = flatten_payload_piece(eddy_obj.payload_pieces)
+        result_list = [function_to_do(eddy_obj.payload_pieces, data)]
+
+    return result_list
+
+
+def flatten_eddy (eddy_obj):
+
+    string = "\n".join(do_to_eddys_pieces(flatten_payload_pieces, eddy_obj, None))
 
     return string
 
 
-def flatten_payload_piece (payload_pieces):
+def flatten_payload_pieces (payload_pieces, _ignore):
 
     string = ""
     for piece in payload_pieces: