[PATCH v4 3/4] Utility function to seek in MIME trees in depth-first order.
authorAustin Clements <amdragon@MIT.EDU>
Sat, 24 Dec 2011 03:45:47 +0000 (22:45 +1900)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:41:14 +0000 (09:41 -0800)
32/d08f4dbc1305b3864f666654add7156f70f295 [new file with mode: 0644]

diff --git a/32/d08f4dbc1305b3864f666654add7156f70f295 b/32/d08f4dbc1305b3864f666654add7156f70f295
new file mode 100644 (file)
index 0000000..8d994f9
--- /dev/null
@@ -0,0 +1,135 @@
+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 0110D429E3F\r
+       for <notmuch@notmuchmail.org>; Fri, 23 Dec 2011 19:46:07 -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 tI3wPvrh2uxG for <notmuch@notmuchmail.org>;\r
+       Fri, 23 Dec 2011 19:46:06 -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 63668429E30\r
+       for <notmuch@notmuchmail.org>; Fri, 23 Dec 2011 19:46:06 -0800 (PST)\r
+X-AuditID: 1209190c-b7fad6d000000920-43-4ef54afd2be6\r
+Received: from mailhub-auth-1.mit.edu ( [18.9.21.35])\r
+       by dmz-mailsec-scanner-1.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id AF.2C.02336.DFA45FE4; Fri, 23 Dec 2011 22:46:05 -0500 (EST)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+       by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id pBO3k5Zf003762; \r
+       Fri, 23 Dec 2011 22:46:05 -0500\r
+Received: from drake.mit.edu (c-76-21-105-205.hsd1.ca.comcast.net\r
+       [76.21.105.205]) (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 pBO3k3Uf017818\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Fri, 23 Dec 2011 22:46:05 -0500 (EST)\r
+Received: from amthrax by drake.mit.edu with local (Exim 4.77)\r
+       (envelope-from <amthrax@drake.mit.edu>)\r
+       id 1ReIYd-0007IO-HM; Fri, 23 Dec 2011 22:46:03 -0500\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v4 3/4] Utility function to seek in MIME trees in depth-first\r
+       order.\r
+Date: Fri, 23 Dec 2011 22:45:47 -0500\r
+Message-Id: <1324698348-27620-4-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.7.7.3\r
+In-Reply-To: <1324698348-27620-1-git-send-email-amdragon@mit.edu>\r
+References: <1323460468-4030-1-git-send-email-amdragon@mit.edu>\r
+       <1324698348-27620-1-git-send-email-amdragon@mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFtrLIsWRmVeSWpSXmKPExsUixCmqrPvP66ufwT5+i+s3ZzI7MHo8W3WL\r
+       OYAxissmJTUnsyy1SN8ugStj/sHVrAXXeCsmH5nL1MB4n6uLkZNDQsBE4v79NjYIW0ziwr31\r
+       QDYXh5DAPkaJN303GSGcDYwSD6eeYIJwzjFJ7D90Fiozn1FiydnnLCD9bAIaEtv2L2cEsUUE\r
+       pCV23p3N2sXIwcEsoCbxp0sFJCwsECLxYtcEsBIWAVWJ5l8LwFp5BRwk5rbOZoY4Q0Hi3Opz\r
+       7CA2p4CjxNat7xlBxggJlEk0nwmawMi/gJFhFaNsSm6Vbm5iZk5xarJucXJiXl5qka6hXm5m\r
+       iV5qSukmRnDISPLsYHxzUOkQowAHoxIPb+PSL35CrIllxZW5hxglOZiURHmvun31E+JLyk+p\r
+       zEgszogvKs1JLT7EKMHBrCTCq5kEVM6bklhZlVqUD5OS5mBREudV0XrnJySQnliSmp2aWpBa\r
+       BJOV4eBQkuB94gk0VLAoNT21Ii0zpwQhzcTBCTKcB2g4NzDGhHiLCxJzizPTIfKnGHU5Fq/a\r
+       cJZRiCUvPy9VSpz3HcggAZCijNI8uDmwWH/FKA70ljBvD8goHmCagJv0CmgJE9CSGCOQD4pL\r
+       EhFSUg2MHkGChX/lShM9d7z/W5Y1wyxxorFl4vmZsxmDE/ZFbApffZ/PSE3s1Px12vVGHPse\r
+       1Euc/Tr9++NtRa9e6fd3Pr3zfvZNnsnOq/c0l15f+ljr15fnv24bqxTc+fYhRPOIVO+tPTlv\r
+       AvU7FyTqxJ9dcNvqlF750udS0W8rRTgrWF57tnww9X3FocRSnJFoqMVcVJwIAGsxrEXQAgAA\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: Sat, 24 Dec 2011 03:46:07 -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      |   27 +++++++++++++++++++++++++++\r
+ notmuch-client.h |    5 +++++\r
+ 2 files changed, 32 insertions(+), 0 deletions(-)\r
+\r
+diff --git a/mime-node.c b/mime-node.c\r
+index fd8e754..1d32823 100644\r
+--- a/mime-node.c\r
++++ b/mime-node.c\r
+@@ -236,3 +236,30 @@ mime_node_child (const mime_node_t *parent, int child)\r
+     }\r
+     return _mime_node_create (parent, sub);\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 -= 1;\r
++    for (i = 0; i < node->nchildren && !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
++    if (n < 0)\r
++      return NULL;\r
++    return _mime_node_seek_dfs_walk (node, &n);\r
++}\r
+diff --git a/notmuch-client.h b/notmuch-client.h\r
+index e23b51c..2f36519 100644\r
+--- a/notmuch-client.h\r
++++ b/notmuch-client.h\r
+@@ -324,5 +324,10 @@ 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
+ #include "command-line-arguments.h"\r
+ #endif\r
+-- \r
+1.7.7.3\r
+\r