simple performance optimization
authorAndrew Engelbrecht <sudoman@ninthfloor.org>
Tue, 21 Jul 2015 22:55:19 +0000 (18:55 -0400)
committerAndrew Engelbrecht <sudoman@ninthfloor.org>
Mon, 7 Dec 2015 18:28:38 +0000 (13:28 -0500)
by not trying to re-scan and re-split gpg data

edward

diff --git a/edward b/edward
index 49027a1483f4c0f8e8f1c0a9bbac3fc1f309e104..2e671a79f5bffeae255d8aa68b1323b2bce7e1e6 100755 (executable)
--- a/edward
+++ b/edward
@@ -155,25 +155,12 @@ def parse_mime(msg_struct):
     return eddy_obj
 
 
-def split_payloads (eddy_obj):
-
-    if eddy_obj.multipart == True:
-        eddy_obj.subparts = list(map(split_payloads, eddy_obj.subparts))
-
-    else:
-        for (match_type, pattern) in match_types:
-
-            new_pieces_list = []
-            for payload_piece in eddy_obj.payload_pieces:
-                new_pieces_list += scan_and_split(payload_piece,
-                    match_type, pattern)
-            eddy_obj.payload_pieces = new_pieces_list
-
-    return eddy_obj
-
-
 def scan_and_split (payload_piece, match_type, pattern):
 
+    # don't try to re-split pieces containing gpg data
+    if payload_piece.piece_type != "text":
+        return [payload_piece]
+
     flags = re.DOTALL | re.MULTILINE
     matches = re.search("(?P<beginning>.*?)(?P<match>" + pattern +
                         ")(?P<rest>.*)", payload_piece.string, flags=flags)
@@ -236,11 +223,30 @@ def do_to_eddys_pieces (function_to_do, eddy_obj, data):
         for sub in eddy_obj.subparts:
             result_list += do_to_eddys_pieces(function_to_do, sub, data)
     else:
-        result_list = [function_to_do(eddy_obj.payload_pieces, data)]
+        result_list = [function_to_do(eddy_obj, data)]
 
     return result_list
 
 
+def split_payloads (eddy_obj):
+
+    for match_type in match_types:
+        do_to_eddys_pieces(split_payload_pieces, eddy_obj, match_type)
+
+    return eddy_obj
+
+
+def split_payload_pieces (eddy_obj, match_type):
+
+    (match_name, pattern) = match_type
+
+    new_pieces_list = []
+    for piece in eddy_obj.payload_pieces:
+        new_pieces_list += scan_and_split(piece, match_name, pattern)
+
+    eddy_obj.payload_pieces = new_pieces_list
+
+
 def decrypt_payloads (eddy_obj, gpgme_ctx):
 
     do_to_eddys_pieces(decrypt_payload_pieces, eddy_obj, gpgme_ctx)
@@ -248,9 +254,9 @@ def decrypt_payloads (eddy_obj, gpgme_ctx):
     return eddy_obj
 
 
-def decrypt_payload_pieces (payload_pieces, gpgme_ctx):
+def decrypt_payload_pieces (eddy_obj, gpgme_ctx):
 
-    for piece in payload_pieces:
+    for piece in eddy_obj.payload_pieces:
 
         if piece.piece_type == "text":
             # don't transform the plaintext.
@@ -275,10 +281,10 @@ def flatten_eddy (eddy_obj):
     return string
 
 
-def flatten_payload_pieces (payload_pieces, _ignore):
+def flatten_payload_pieces (eddy_obj, _ignore):
 
     string = ""
-    for piece in payload_pieces:
+    for piece in eddy_obj.payload_pieces:
         if piece.piece_type == "text":
             string += piece.string
         elif piece.piece_type == "message":