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