1 Return-Path: <dmitry.kurochkin@gmail.com>
\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 E0026429E54
\r
6 for <notmuch@notmuchmail.org>; Mon, 23 Jan 2012 15:37:25 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5
\r
12 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
\r
13 FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled
\r
14 Received: from olra.theworths.org ([127.0.0.1])
\r
15 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
16 with ESMTP id 9R2mJitzPYxz for <notmuch@notmuchmail.org>;
\r
17 Mon, 23 Jan 2012 15:37:25 -0800 (PST)
\r
18 Received: from mail-bk0-f53.google.com (mail-bk0-f53.google.com
\r
19 [209.85.214.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))
\r
20 (No client certificate requested)
\r
21 by olra.theworths.org (Postfix) with ESMTPS id 13CCD429E21
\r
22 for <notmuch@notmuchmail.org>; Mon, 23 Jan 2012 15:37:24 -0800 (PST)
\r
23 Received: by bkbzt19 with SMTP id zt19so1820797bkb.26
\r
24 for <notmuch@notmuchmail.org>; Mon, 23 Jan 2012 15:37:23 -0800 (PST)
\r
25 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;
\r
26 h=from:to:cc:subject:in-reply-to:references:user-agent:date
\r
27 :message-id:mime-version:content-type;
\r
28 bh=ooJJXrUSWM99uGB/V3gmVPG0jx3wknCQpXD0+EzoHKg=;
\r
29 b=Xjrk3Up1jBl2TnOhPTMZGXEG0PpHtKnR8LpYvft87ZdUvyM8VynZkjXjCFtgPIXFag
\r
30 Gspq2HpJQaYTRepEeLyT/wDb3aJ7otBIWalkKcUdJWc2fgm8bROo2gvqgvM5ropIs/5/
\r
31 +ZgJp8jWJjJp2p7j7lvyfyG4gPjSrVozxbl8Q=
\r
32 Received: by 10.205.129.132 with SMTP id hi4mr4045653bkc.44.1327361843662;
\r
33 Mon, 23 Jan 2012 15:37:23 -0800 (PST)
\r
34 Received: from localhost ([91.144.186.21])
\r
35 by mx.google.com with ESMTPS id ga13sm31844277bkc.5.2012.01.23.15.37.21
\r
36 (version=TLSv1/SSLv3 cipher=OTHER);
\r
37 Mon, 23 Jan 2012 15:37:22 -0800 (PST)
\r
38 From: Dmitry Kurochkin <dmitry.kurochkin@gmail.com>
\r
39 To: Austin Clements <amdragon@MIT.EDU>, notmuch@notmuchmail.org
\r
40 Subject: Re: [PATCH v5 1/2] mime node: Record depth-first part numbers
\r
41 In-Reply-To: <1327361590-19273-2-git-send-email-amdragon@mit.edu>
\r
42 References: <1326918507-28033-1-git-send-email-amdragon@mit.edu>
\r
43 <1327361590-19273-1-git-send-email-amdragon@mit.edu>
\r
44 <1327361590-19273-2-git-send-email-amdragon@mit.edu>
\r
45 User-Agent: Notmuch/0.11+100~gd650abf (http://notmuchmail.org) Emacs/23.3.1
\r
46 (x86_64-pc-linux-gnu)
\r
47 Date: Tue, 24 Jan 2012 03:36:17 +0400
\r
48 Message-ID: <87ty3mm1ou.fsf@gmail.com>
\r
50 Content-Type: text/plain; charset=us-ascii
\r
51 Cc: tomi.ollila@iki.fi
\r
52 X-BeenThere: notmuch@notmuchmail.org
\r
53 X-Mailman-Version: 2.1.13
\r
55 List-Id: "Use and development of the notmuch mail system."
\r
56 <notmuch.notmuchmail.org>
\r
57 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
58 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
59 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
60 List-Post: <mailto:notmuch@notmuchmail.org>
\r
61 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
62 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
63 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
64 X-List-Received-Date: Mon, 23 Jan 2012 23:37:26 -0000
\r
66 On Mon, 23 Jan 2012 18:33:09 -0500, Austin Clements <amdragon@MIT.EDU> wrote:
\r
67 > This makes the part numbers readily accessible to formatters.
\r
68 > Hierarchical part numbering would be a more natural and efficient fit
\r
69 > for MIME and may be the way to go in the future, but depth-first
\r
70 > numbering maintains compatibility with what we currently do.
\r
78 > mime-node.c | 38 +++++++++++++++++++++++++++++++++++---
\r
79 > notmuch-client.h | 14 +++++++++++++-
\r
80 > 2 files changed, 48 insertions(+), 4 deletions(-)
\r
82 > diff --git a/mime-node.c b/mime-node.c
\r
83 > index 27077f7..d6b4506 100644
\r
86 > @@ -112,6 +112,11 @@ mime_node_open (const void *ctx, notmuch_message_t *message,
\r
87 > root->nchildren = 1;
\r
90 > + root->parent = NULL;
\r
91 > + root->part_num = 0;
\r
92 > + root->next_child = 0;
\r
93 > + root->next_part_num = 1;
\r
96 > return NOTMUCH_STATUS_SUCCESS;
\r
98 > @@ -137,7 +142,7 @@ _signature_validity_free (GMimeSignatureValidity **proxy)
\r
101 > static mime_node_t *
\r
102 > -_mime_node_create (const mime_node_t *parent, GMimeObject *part)
\r
103 > +_mime_node_create (mime_node_t *parent, GMimeObject *part)
\r
105 > mime_node_t *node = talloc_zero (parent, mime_node_t);
\r
106 > GError *err = NULL;
\r
107 > @@ -150,6 +155,9 @@ _mime_node_create (const mime_node_t *parent, GMimeObject *part)
\r
108 > talloc_free (node);
\r
111 > + node->parent = parent;
\r
112 > + node->part_num = node->next_part_num = -1;
\r
113 > + node->next_child = 0;
\r
115 > /* Deal with the different types of parts */
\r
116 > if (GMIME_IS_PART (part)) {
\r
117 > @@ -267,9 +275,10 @@ _mime_node_create (const mime_node_t *parent, GMimeObject *part)
\r
121 > -mime_node_child (const mime_node_t *parent, int child)
\r
122 > +mime_node_child (mime_node_t *parent, int child)
\r
124 > GMimeObject *sub;
\r
125 > + mime_node_t *node;
\r
127 > if (!parent || child < 0 || child >= parent->nchildren)
\r
129 > @@ -287,7 +296,30 @@ mime_node_child (const mime_node_t *parent, int child)
\r
130 > INTERNAL_ERROR ("Unexpected GMimeObject type: %s",
\r
131 > g_type_name (G_OBJECT_TYPE (parent->part)));
\r
133 > - return _mime_node_create (parent, sub);
\r
134 > + node = _mime_node_create (parent, sub);
\r
136 > + if (child == parent->next_child && parent->next_part_num != -1) {
\r
137 > + /* We're traversing in depth-first order. Record the child's
\r
138 > + * depth-first numbering. */
\r
139 > + node->part_num = parent->next_part_num;
\r
140 > + node->next_part_num = node->part_num + 1;
\r
142 > + /* Prepare the parent for its next depth-first child. */
\r
143 > + parent->next_child++;
\r
144 > + parent->next_part_num = -1;
\r
146 > + if (node->nchildren == 0) {
\r
147 > + /* We've reached a leaf, so find the parent that has more
\r
148 > + * children and set it up to number its next child. */
\r
149 > + mime_node_t *iter = node->parent;
\r
150 > + while (iter && iter->next_child == iter->nchildren)
\r
151 > + iter = iter->parent;
\r
153 > + iter->next_part_num = node->part_num + 1;
\r
160 > static mime_node_t *
\r
161 > diff --git a/notmuch-client.h b/notmuch-client.h
\r
162 > index 9c1d383..abfe5d3 100644
\r
163 > --- a/notmuch-client.h
\r
164 > +++ b/notmuch-client.h
\r
165 > @@ -297,6 +297,13 @@ typedef struct mime_node {
\r
166 > /* The number of children of this part. */
\r
169 > + /* The parent of this node or NULL if this is the root node. */
\r
170 > + struct mime_node *parent;
\r
172 > + /* The depth-first part number of this child if the MIME tree is
\r
173 > + * being traversed in depth-first order, or -1 otherwise. */
\r
176 > /* True if decryption of this part was attempted. */
\r
177 > notmuch_bool_t decrypt_attempted;
\r
178 > /* True if decryption of this part's child succeeded. In this
\r
179 > @@ -324,6 +331,11 @@ typedef struct mime_node {
\r
180 > /* Internal: For successfully decrypted multipart parts, the
\r
181 > * decrypted part to substitute for the second child. */
\r
182 > GMimeObject *decrypted_child;
\r
184 > + /* Internal: The next child for depth-first traversal and the part
\r
185 > + * number to assign it (or -1 if unknown). */
\r
186 > + int next_child;
\r
187 > + int next_part_num;
\r
190 > /* Construct a new MIME node pointing to the root message part of
\r
191 > @@ -356,7 +368,7 @@ mime_node_open (const void *ctx, notmuch_message_t *message,
\r
192 > * an error message on stderr).
\r
195 > -mime_node_child (const mime_node_t *parent, int child);
\r
196 > +mime_node_child (mime_node_t *parent, int child);
\r
198 > /* Return the nth child of node in a depth-first traversal. If n is
\r
199 > * 0, returns node itself. Returns NULL if there is no such part. */
\r