1 Return-Path: <amthrax@drake.mit.edu>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id B550C421192
\r
6 for <notmuch@notmuchmail.org>; Mon, 23 Jan 2012 15:33:18 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5
\r
12 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id 5Y3FsERrmEhk for <notmuch@notmuchmail.org>;
\r
16 Mon, 23 Jan 2012 15:33:18 -0800 (PST)
\r
17 Received: from dmz-mailsec-scanner-2.mit.edu (DMZ-MAILSEC-SCANNER-2.MIT.EDU
\r
19 by olra.theworths.org (Postfix) with ESMTP id E15A0429E21
\r
20 for <notmuch@notmuchmail.org>; Mon, 23 Jan 2012 15:33:17 -0800 (PST)
\r
21 X-AuditID: 1209190d-b7fbf6d0000008ba-1d-4f1dee3dd8ae
\r
22 Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])
\r
23 by dmz-mailsec-scanner-2.mit.edu (Symantec Messaging Gateway) with SMTP
\r
24 id 0B.68.02234.D3EED1F4; Mon, 23 Jan 2012 18:33:17 -0500 (EST)
\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])
\r
26 by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id q0NNXHln027010;
\r
27 Mon, 23 Jan 2012 18:33:17 -0500
\r
28 Received: from drake.mit.edu (26-4-180.dynamic.csail.mit.edu [18.26.4.180])
\r
29 (authenticated bits=0)
\r
30 (User authenticated as amdragon@ATHENA.MIT.EDU)
\r
31 by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q0NNXFAD027080
\r
32 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);
\r
33 Mon, 23 Jan 2012 18:33:16 -0500 (EST)
\r
34 Received: from amthrax by drake.mit.edu with local (Exim 4.77)
\r
35 (envelope-from <amthrax@drake.mit.edu>)
\r
36 id 1RpTNz-00053f-7j; Mon, 23 Jan 2012 18:33:15 -0500
\r
37 From: Austin Clements <amdragon@MIT.EDU>
\r
38 To: notmuch@notmuchmail.org
\r
39 Subject: [PATCH v5 1/2] mime node: Record depth-first part numbers
\r
40 Date: Mon, 23 Jan 2012 18:33:09 -0500
\r
41 Message-Id: <1327361590-19273-2-git-send-email-amdragon@mit.edu>
\r
42 X-Mailer: git-send-email 1.7.7.3
\r
43 In-Reply-To: <1327361590-19273-1-git-send-email-amdragon@mit.edu>
\r
44 References: <1326918507-28033-1-git-send-email-amdragon@mit.edu>
\r
45 <1327361590-19273-1-git-send-email-amdragon@mit.edu>
\r
46 X-Brightmail-Tracker:
\r
47 H4sIAAAAAAAAA+NgFjrHIsWRmVeSWpSXmKPExsUixG6nrmv7TtbfYNckeYurW/vZLZqmO1tc
\r
48 vzmT2eLNynmsDiweO2fdZfc4/HUhi8et+6/ZPZ6tusUcwBLFZZOSmpNZllqkb5fAlXHm4R+W
\r
49 gvnKFSdbVrA0MG6U7mLk5JAQMJGYs+ARI4QtJnHh3nq2LkYuDiGBfYwScz7/g3I2MEocvf4A
\r
50 yjnOJLFjdhcLSIuQwHxGiY8TJEFsNgENiW37l4ONEhGQlth5dzZrFyMHB7NAgcTkC8YgYWEB
\r
51 J4k/d3rBSlgEVCW+fvjCBmLzCjhIfGiCsCUEFCTOrT7HDmJzCjhKnL35jRFkjJBAucSeq4YT
\r
52 GPkXMDKsYpRNya3SzU3MzClOTdYtTk7My0st0jXSy80s0UtNKd3ECAo2TkneHYzvDiodYhTg
\r
53 YFTi4ZWYKesvxJpYVlyZe4hRkoNJSZTX9TVQiC8pP6UyI7E4I76oNCe1+BCjBAezkgiv2jmg
\r
54 HG9KYmVValE+TEqag0VJnFdV652fkEB6YklqdmpqQWoRTFaGg0NJgrfoLVCjYFFqempFWmZO
\r
55 CUKaiYMTZDgP0PB0kBre4oLE3OLMdIj8KUZFKXHeYpCEAEgiozQPrheWDF4xigO9IsxbDlLF
\r
56 A0wkcN2vgAYzAQ3myJMCGVySiJCSamDUnWG7Vc7qq5CUw4YSSfsvFszrIhJvfn/rdGrT4i8N
\r
57 P5m4eRN5Ul5ez95t6rBnVrD277vpQbOCjGbMVRWROZTTssi451LWCsGZBRcmX7P0bzxQFhL4
\r
58 Y6sus2rhceFzpwRKNiXV5VzkNtx7fEXFlttvvS1bi7Z8lTo+N6X88EnxvH9PM2RED+sosRRn
\r
59 JBpqMRcVJwIA3sR3XeECAAA=
\r
60 Cc: tomi.ollila@iki.fi
\r
61 X-BeenThere: notmuch@notmuchmail.org
\r
62 X-Mailman-Version: 2.1.13
\r
64 List-Id: "Use and development of the notmuch mail system."
\r
65 <notmuch.notmuchmail.org>
\r
66 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
67 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
68 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
69 List-Post: <mailto:notmuch@notmuchmail.org>
\r
70 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
71 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
72 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
73 X-List-Received-Date: Mon, 23 Jan 2012 23:33:19 -0000
\r
75 This makes the part numbers readily accessible to formatters.
\r
76 Hierarchical part numbering would be a more natural and efficient fit
\r
77 for MIME and may be the way to go in the future, but depth-first
\r
78 numbering maintains compatibility with what we currently do.
\r
80 mime-node.c | 38 +++++++++++++++++++++++++++++++++++---
\r
81 notmuch-client.h | 14 +++++++++++++-
\r
82 2 files changed, 48 insertions(+), 4 deletions(-)
\r
84 diff --git a/mime-node.c b/mime-node.c
\r
85 index 27077f7..d6b4506 100644
\r
88 @@ -112,6 +112,11 @@ mime_node_open (const void *ctx, notmuch_message_t *message,
\r
89 root->nchildren = 1;
\r
92 + root->parent = NULL;
\r
93 + root->part_num = 0;
\r
94 + root->next_child = 0;
\r
95 + root->next_part_num = 1;
\r
98 return NOTMUCH_STATUS_SUCCESS;
\r
100 @@ -137,7 +142,7 @@ _signature_validity_free (GMimeSignatureValidity **proxy)
\r
103 static mime_node_t *
\r
104 -_mime_node_create (const mime_node_t *parent, GMimeObject *part)
\r
105 +_mime_node_create (mime_node_t *parent, GMimeObject *part)
\r
107 mime_node_t *node = talloc_zero (parent, mime_node_t);
\r
108 GError *err = NULL;
\r
109 @@ -150,6 +155,9 @@ _mime_node_create (const mime_node_t *parent, GMimeObject *part)
\r
110 talloc_free (node);
\r
113 + node->parent = parent;
\r
114 + node->part_num = node->next_part_num = -1;
\r
115 + node->next_child = 0;
\r
117 /* Deal with the different types of parts */
\r
118 if (GMIME_IS_PART (part)) {
\r
119 @@ -267,9 +275,10 @@ _mime_node_create (const mime_node_t *parent, GMimeObject *part)
\r
123 -mime_node_child (const mime_node_t *parent, int child)
\r
124 +mime_node_child (mime_node_t *parent, int child)
\r
127 + mime_node_t *node;
\r
129 if (!parent || child < 0 || child >= parent->nchildren)
\r
131 @@ -287,7 +296,30 @@ mime_node_child (const mime_node_t *parent, int child)
\r
132 INTERNAL_ERROR ("Unexpected GMimeObject type: %s",
\r
133 g_type_name (G_OBJECT_TYPE (parent->part)));
\r
135 - return _mime_node_create (parent, sub);
\r
136 + node = _mime_node_create (parent, sub);
\r
138 + if (child == parent->next_child && parent->next_part_num != -1) {
\r
139 + /* We're traversing in depth-first order. Record the child's
\r
140 + * depth-first numbering. */
\r
141 + node->part_num = parent->next_part_num;
\r
142 + node->next_part_num = node->part_num + 1;
\r
144 + /* Prepare the parent for its next depth-first child. */
\r
145 + parent->next_child++;
\r
146 + parent->next_part_num = -1;
\r
148 + if (node->nchildren == 0) {
\r
149 + /* We've reached a leaf, so find the parent that has more
\r
150 + * children and set it up to number its next child. */
\r
151 + mime_node_t *iter = node->parent;
\r
152 + while (iter && iter->next_child == iter->nchildren)
\r
153 + iter = iter->parent;
\r
155 + iter->next_part_num = node->part_num + 1;
\r
162 static mime_node_t *
\r
163 diff --git a/notmuch-client.h b/notmuch-client.h
\r
164 index 9c1d383..abfe5d3 100644
\r
165 --- a/notmuch-client.h
\r
166 +++ b/notmuch-client.h
\r
167 @@ -297,6 +297,13 @@ typedef struct mime_node {
\r
168 /* The number of children of this part. */
\r
171 + /* The parent of this node or NULL if this is the root node. */
\r
172 + struct mime_node *parent;
\r
174 + /* The depth-first part number of this child if the MIME tree is
\r
175 + * being traversed in depth-first order, or -1 otherwise. */
\r
178 /* True if decryption of this part was attempted. */
\r
179 notmuch_bool_t decrypt_attempted;
\r
180 /* True if decryption of this part's child succeeded. In this
\r
181 @@ -324,6 +331,11 @@ typedef struct mime_node {
\r
182 /* Internal: For successfully decrypted multipart parts, the
\r
183 * decrypted part to substitute for the second child. */
\r
184 GMimeObject *decrypted_child;
\r
186 + /* Internal: The next child for depth-first traversal and the part
\r
187 + * number to assign it (or -1 if unknown). */
\r
189 + int next_part_num;
\r
192 /* Construct a new MIME node pointing to the root message part of
\r
193 @@ -356,7 +368,7 @@ mime_node_open (const void *ctx, notmuch_message_t *message,
\r
194 * an error message on stderr).
\r
197 -mime_node_child (const mime_node_t *parent, int child);
\r
198 +mime_node_child (mime_node_t *parent, int child);
\r
200 /* Return the nth child of node in a depth-first traversal. If n is
\r
201 * 0, returns node itself. Returns NULL if there is no such part. */
\r