[PATCH 3/4] Utility function to seek in MIME trees in depth-first order.
authorAustin Clements <amdragon@MIT.EDU>
Mon, 28 Nov 2011 02:21:10 +0000 (21:21 +1900)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:40:26 +0000 (09:40 -0800)
0e/9e0204a2be019a253cb3ee8ddb449f3dc4e2d1 [new file with mode: 0644]

diff --git a/0e/9e0204a2be019a253cb3ee8ddb449f3dc4e2d1 b/0e/9e0204a2be019a253cb3ee8ddb449f3dc4e2d1
new file mode 100644 (file)
index 0000000..e951b6a
--- /dev/null
@@ -0,0 +1,134 @@
+Return-Path: <amthrax@drake.mit.edu>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 1BDB7429E39\r
+       for <notmuch@notmuchmail.org>; Sun, 27 Nov 2011 18:21:48 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id RjVSnE9CHj+P for <notmuch@notmuchmail.org>;\r
+       Sun, 27 Nov 2011 18:21:47 -0800 (PST)\r
+Received: from dmz-mailsec-scanner-1.mit.edu (DMZ-MAILSEC-SCANNER-1.MIT.EDU\r
+       [18.9.25.12])\r
+       by olra.theworths.org (Postfix) with ESMTP id 8E968429E3B\r
+       for <notmuch@notmuchmail.org>; Sun, 27 Nov 2011 18:21:36 -0800 (PST)\r
+X-AuditID: 1209190c-b7f806d0000008d6-82-4ed2f0301236\r
+Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\r
+       by dmz-mailsec-scanner-1.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id 37.57.02262.030F2DE4; Sun, 27 Nov 2011 21:21:36 -0500 (EST)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+       by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id pAS2LZ1M017091; \r
+       Sun, 27 Nov 2011 21:21:35 -0500\r
+Received: from drake.mit.edu\r
+       (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com\r
+       [209.6.116.242]) (authenticated bits=0)\r
+       (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+       by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id pAS2LXru020659\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Sun, 27 Nov 2011 21:21:34 -0500 (EST)\r
+Received: from amthrax by drake.mit.edu with local (Exim 4.76)\r
+       (envelope-from <amthrax@drake.mit.edu>)\r
+       id 1RUqqb-0003vX-Ll; Sun, 27 Nov 2011 21:21:33 -0500\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 3/4] Utility function to seek in MIME trees in depth-first\r
+       order.\r
+Date: Sun, 27 Nov 2011 21:21:10 -0500\r
+Message-Id: <1322446871-14986-4-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.7.5.4\r
+In-Reply-To: <1322446871-14986-1-git-send-email-amdragon@mit.edu>\r
+References: <1322446871-14986-1-git-send-email-amdragon@mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFrrFIsWRmVeSWpSXmKPExsUixG6nrmvw4ZKfwe+D3Bat3Z+ZLK5u7We3\r
+       2LPPy+L6zZnMDiweZ7vbWT3unuby2DnrLrvHs1W3mANYorhsUlJzMstSi/TtErgy9nf/ZCyY\r
+       zFtx+n4vawPjWq4uRk4OCQETiQ1b+pggbDGJC/fWs3UxcnEICexjlJi/9yYThLOBUaL7+UZm\r
+       kCohgftMErceBELY8xklbmzlA7HZBDQktu1fzghiiwhIS+y8O5sVxGYWqJPo3HiGHcQWFgiU\r
+       +D7nFdg2FgFViSsv9rOB2LwCDhKdH++wQVyhIPHryCqwXk4BR4m5TVug9jpIrFt2lHUCI/8C\r
+       RoZVjLIpuVW6uYmZOcWpybrFyYl5ealFuoZ6uZkleqkppZsYQcHGKcmzg/HNQaVDjAIcjEo8\r
+       vBsvX/ITYk0sK67MPcQoycGkJMr74h1QiC8pP6UyI7E4I76oNCe1+BCjBAezkghvz1GgHG9K\r
+       YmVValE+TEqag0VJnPfgDgc/IYH0xJLU7NTUgtQimKwMB4eSBG/Se6BGwaLU9NSKtMycEoQ0\r
+       EwcnyHAeoOEhIDW8xQWJucWZ6RD5U4y6HAuuXD/NKMSSl5+XKiXOmwNSJABSlFGaBzcHliRe\r
+       MYoDvSXMGw5SxQNMMHCTXgEtYQJawjHzAsiSkkSElFQD4yrFuXqNr7o4SzdcbZ+t8CzyR+2m\r
+       7Z1B3SwvNaTkRdzVp/wTf9fSrOyxdtoCu2kFU1ukpSKfhn+MWKV0miW67Bl/UHHHweUuypMq\r
+       ZG7PTGV+JH5w6ycBlTfJRYExRX+tJuXJxs1lsn1xQb/r2Hpu5+s5jJEM9hEZFR/ral+3hy39\r
+       qVpd4npfiaU4I9FQi7moOBEAiyill+0CAAA=\r
+Cc: dkg@fifthhorseman.net\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Mon, 28 Nov 2011 02:21:48 -0000\r
+\r
+This function matches how we number parts for the --part argument to\r
+show.  It will allow us to jump directly to the desired part, rather\r
+than traversing the entire tree and carefully tracking whether or not\r
+we're "in the zone".\r
+---\r
+ mime-node.c      |   25 +++++++++++++++++++++++++\r
+ notmuch-client.h |    5 +++++\r
+ 2 files changed, 30 insertions(+), 0 deletions(-)\r
+\r
+diff --git a/mime-node.c b/mime-node.c\r
+index 942738b..40fff75 100644\r
+--- a/mime-node.c\r
++++ b/mime-node.c\r
+@@ -232,3 +232,28 @@ mime_node_child (const mime_node_t *parent, int child)\r
+                       g_type_name (G_OBJECT_TYPE (parent->part)));\r
+     }\r
+ }\r
++\r
++static mime_node_t *\r
++_mime_node_seek_dfs_walk (mime_node_t *node, int *n)\r
++{\r
++    mime_node_t *ret = NULL;\r
++    int i;\r
++\r
++    if (*n <= 0)\r
++      return node;\r
++\r
++    *n = *n - 1;\r
++    for (i = 0; i < node->children && !ret; i++) {\r
++      mime_node_t *child = mime_node_child (node, i);\r
++      ret = _mime_node_seek_dfs_walk (child, n);\r
++      if (!ret)\r
++          talloc_free (child);\r
++    }\r
++    return ret;\r
++}\r
++\r
++mime_node_t *\r
++mime_node_seek_dfs (mime_node_t *node, int n)\r
++{\r
++    return _mime_node_seek_dfs_walk (node, &n);\r
++}\r
+diff --git a/notmuch-client.h b/notmuch-client.h\r
+index 58bd21c..8b1454f 100644\r
+--- a/notmuch-client.h\r
++++ b/notmuch-client.h\r
+@@ -318,4 +318,9 @@ mime_node_open (const void *ctx, notmuch_message_t *message,\r
+ mime_node_t *\r
+ mime_node_child (const mime_node_t *parent, int child);\r
\r
++/* Return the nth child of node in a depth-first traversal.  If n is\r
++ * 0, returns node itself.  Returns NULL if there is no such part. */\r
++mime_node_t *\r
++mime_node_seek_dfs (mime_node_t *node, int n);\r
++\r
+ #endif\r
+-- \r
+1.7.5.4\r
+\r