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 54F27431FB6
\r
6 for <notmuch@notmuchmail.org>; Wed, 11 Jan 2012 17:49:46 -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 8bQAP7BWcOpJ for <notmuch@notmuchmail.org>;
\r
16 Wed, 11 Jan 2012 17:49:45 -0800 (PST)
\r
17 Received: from dmz-mailsec-scanner-6.mit.edu (DMZ-MAILSEC-SCANNER-6.MIT.EDU
\r
19 by olra.theworths.org (Postfix) with ESMTP id 8A715429E21
\r
20 for <notmuch@notmuchmail.org>; Wed, 11 Jan 2012 17:49:45 -0800 (PST)
\r
21 X-AuditID: 12074423-b7f9c6d0000008c3-0c-4f0e3c392e7d
\r
22 Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])
\r
23 by dmz-mailsec-scanner-6.mit.edu (Symantec Messaging Gateway) with SMTP
\r
24 id 77.61.02243.93C3E0F4; Wed, 11 Jan 2012 20:49:45 -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 q0C1niE2029646;
\r
27 Wed, 11 Jan 2012 20:49:44 -0500
\r
28 Received: from drake.mit.edu
\r
29 (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com
\r
30 [209.6.116.242]) (authenticated bits=0)
\r
31 (User authenticated as amdragon@ATHENA.MIT.EDU)
\r
32 by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q0C1nge1001512
\r
33 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);
\r
34 Wed, 11 Jan 2012 20:49:44 -0500 (EST)
\r
35 Received: from amthrax by drake.mit.edu with local (Exim 4.77)
\r
36 (envelope-from <amthrax@drake.mit.edu>)
\r
37 id 1Rl9nS-000804-6L; Wed, 11 Jan 2012 20:49:42 -0500
\r
38 From: Austin Clements <amdragon@MIT.EDU>
\r
39 To: notmuch@notmuchmail.org
\r
40 Subject: [RFC PATCH 1/5] mime node: Record depth-first part numbers
\r
41 Date: Wed, 11 Jan 2012 20:49:29 -0500
\r
42 Message-Id: <1326332973-30225-2-git-send-email-amdragon@mit.edu>
\r
43 X-Mailer: git-send-email 1.7.7.3
\r
44 In-Reply-To: <1326332973-30225-1-git-send-email-amdragon@mit.edu>
\r
45 References: <1326332973-30225-1-git-send-email-amdragon@mit.edu>
\r
46 X-Brightmail-Tracker:
\r
47 H4sIAAAAAAAAA+NgFtrMIsWRmVeSWpSXmKPExsUixG6nrmtpw+dv8GuKmMX1mzOZHRg9nq26
\r
48 xRzAGMVlk5Kak1mWWqRvl8CVsfz+RcaCRzIVM7+8YG1gnCHWxcjJISFgItFw7QozhC0mceHe
\r
49 erYuRi4OIYF9jBKP7i9jhXA2MEpM6+qEcu4zSbza8I8ZwpkPlDnylAWkn01AQ2Lb/uWMILaI
\r
50 gLTEzruzgTo4OJgFRCTezWQCCQsLOEssf/AGzGYRUJXoXv4TrJVXwEFi4r+jrBBnKEicW32O
\r
51 HcTmFHCU6D9+jA3EFgKqebHzKfMERv4FjAyrGGVTcqt0cxMzc4pTk3WLkxPz8lKLdM30cjNL
\r
52 9FJTSjcxgsPGRXkH45+DSocYBTgYlXh4d+zl9RdiTSwrrsw9xCjJwaQkyvvdis9fiC8pP6Uy
\r
53 I7E4I76oNCe1+BCjBAezkgivUw1QOW9KYmVValE+TEqag0VJnFdD652fkEB6YklqdmpqQWoR
\r
54 TFaGg0NJgrfEGmioYFFqempFWmZOCUKaiYMTZDgP0PAMkBre4oLE3OLMdIj8KUZFKXFed5CE
\r
55 AEgiozQPrhcW168YxYFeEebNB6niAaYEuO5XQIOZgAZvWccDMrgkESEl1cAoZrNikuNmkYcc
\r
56 BotylPO/qJz8Pe3Nrempl3YZOPwsXnTne6Lcp5nFu211ikz28DKvdz260HvD5byj5WI+tu/y
\r
57 NvVO2aGT6xZ0qazx9/sE3prAnavbXfP4auzsheaG7Q/te1n/aH7ILZ+gSV0vja/3vW3R81RR
\r
58 2KL1dvaZW0XXsidLeS/lmsyoxFKckWioxVxUnAgAle1AL8YCAAA=
\r
59 X-BeenThere: notmuch@notmuchmail.org
\r
60 X-Mailman-Version: 2.1.13
\r
62 List-Id: "Use and development of the notmuch mail system."
\r
63 <notmuch.notmuchmail.org>
\r
64 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
65 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
66 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
67 List-Post: <mailto:notmuch@notmuchmail.org>
\r
68 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
69 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
70 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
71 X-List-Received-Date: Thu, 12 Jan 2012 01:49:46 -0000
\r
73 This makes the part numbers readily accessible to formatters.
\r
74 Hierarchical part numbering would be a more natural and efficient fit
\r
75 for MIME and may be the way to go in the future, but depth-first
\r
76 numbering maintains compatibility with what we currently do.
\r
78 mime-node.c | 33 ++++++++++++++++++++++++++++++++-
\r
79 notmuch-client.h | 11 +++++++++++
\r
80 2 files changed, 43 insertions(+), 1 deletions(-)
\r
82 diff --git a/mime-node.c b/mime-node.c
\r
83 index d26bb44..30b542f 100644
\r
86 @@ -104,6 +104,10 @@ mime_node_open (const void *ctx, notmuch_message_t *message,
\r
87 root->nchildren = 1;
\r
90 + root->part_num = 0;
\r
91 + root->next_child = 0;
\r
92 + root->next_part_num = 1;
\r
95 return NOTMUCH_STATUS_SUCCESS;
\r
97 @@ -133,6 +137,8 @@ _mime_node_create (const mime_node_t *parent, GMimeObject *part)
\r
101 + node->parent = parent;
\r
102 + node->part_num = node->next_part_num = -1;
\r
104 /* Deal with the different types of parts */
\r
105 if (GMIME_IS_PART (part)) {
\r
106 @@ -217,6 +223,7 @@ mime_node_t *
\r
107 mime_node_child (const mime_node_t *parent, int child)
\r
110 + mime_node_t *node;
\r
112 if (!parent || child < 0 || child >= parent->nchildren)
\r
114 @@ -234,7 +241,31 @@ mime_node_child (const mime_node_t *parent, int child)
\r
115 INTERNAL_ERROR ("Unexpected GMimeObject type: %s",
\r
116 g_type_name (G_OBJECT_TYPE (parent->part)));
\r
118 - return _mime_node_create (parent, sub);
\r
119 + node = _mime_node_create (parent, sub);
\r
121 + if (child == parent->next_child && parent->next_part_num != -1) {
\r
122 + /* We're traversing in depth-first order. Record the child's
\r
123 + * depth-first numbering. */
\r
124 + node->part_num = parent->next_part_num;
\r
125 + node->next_part_num = node->part_num + 1;
\r
127 + /* Drop the const qualifier because these are internal fields
\r
128 + * whose mutability doesn't affect the interface. */
\r
129 + ((mime_node_t*)parent)->next_child++;
\r
130 + ((mime_node_t*)parent)->next_part_num = -1;
\r
132 + if (node->nchildren == 0) {
\r
133 + /* We've reached a leaf, so find the parent that has more
\r
134 + * children and set it up to number its next child. */
\r
135 + const mime_node_t *it = node;
\r
136 + while (it && it->next_child == it->nchildren)
\r
139 + ((mime_node_t*)it)->next_part_num = node->part_num + 1;
\r
146 static mime_node_t *
\r
147 diff --git a/notmuch-client.h b/notmuch-client.h
\r
148 index 517c010..8832242 100644
\r
149 --- a/notmuch-client.h
\r
150 +++ b/notmuch-client.h
\r
151 @@ -273,6 +273,13 @@ typedef struct mime_node {
\r
152 /* The number of children of this part. */
\r
155 + /* The parent of this node or NULL if this is the root node. */
\r
156 + const struct mime_node *parent;
\r
158 + /* The depth-first part number of this child if the MIME tree is
\r
159 + * being traversed in depth-first order, or -1 otherwise. */
\r
162 /* True if decryption of this part was attempted. */
\r
163 notmuch_bool_t decrypt_attempted;
\r
164 /* True if decryption of this part's child succeeded. In this
\r
165 @@ -294,6 +301,10 @@ typedef struct mime_node {
\r
166 /* Internal: For successfully decrypted multipart parts, the
\r
167 * decrypted part to substitute for the second child. */
\r
168 GMimeObject *decrypted_child;
\r
170 + /* Internal: The next child for depth-first traversal and the part
\r
171 + * number to assign it (or -1 if unknown). */
\r
172 + int next_child, next_part_num;
\r
175 /* Construct a new MIME node pointing to the root message part of
\r