[PATCH WIP v2 0/5] emacs: show: redesign unread/read logic
[notmuch-archives.git] / f3 / 9c495edf107d71e6af35242dacfd59b126fe39
1 Return-Path: <jani@nikula.org>\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 6F472429E21\r
6         for <notmuch@notmuchmail.org>; Mon, 23 Jan 2012 10:08:03 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.7\r
10 X-Spam-Level: \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 VYP1+-jnilDr for <notmuch@notmuchmail.org>;\r
16         Mon, 23 Jan 2012 10:08:01 -0800 (PST)\r
17 Received: from mail-ww0-f45.google.com (mail-ww0-f45.google.com\r
18  [74.125.82.45])        (using TLSv1 with cipher RC4-SHA (128/128 bits))        (No client\r
19  certificate requested) by olra.theworths.org (Postfix) with ESMTPS id\r
20  3ADBD421192    for <notmuch@notmuchmail.org>; Mon, 23 Jan 2012 10:08:01 -0800\r
21  (PST)\r
22 Received: by wgbdt12 with SMTP id dt12so2885304wgb.2\r
23         for <notmuch@notmuchmail.org>; Mon, 23 Jan 2012 10:08:00 -0800 (PST)\r
24 Received: by 10.180.108.232 with SMTP id hn8mr15263671wib.16.1327342080016;\r
25         Mon, 23 Jan 2012 10:08:00 -0800 (PST)\r
26 Received: from localhost (dsl-hkibrasgw4-fe50f800-253.dhcp.inet.fi.\r
27         [84.248.80.253])\r
28         by mx.google.com with ESMTPS id di5sm43584515wib.3.2012.01.23.10.07.54\r
29         (version=SSLv3 cipher=OTHER); Mon, 23 Jan 2012 10:07:56 -0800 (PST)\r
30 From: Jani Nikula <jani@nikula.org>\r
31 To: Austin Clements <amdragon@MIT.EDU>, notmuch@notmuchmail.org\r
32 Subject: Re: [PATCH v2 1/3] mime node: Record depth-first part numbers\r
33 In-Reply-To: <1327285873-4713-2-git-send-email-amdragon@mit.edu>\r
34 References: <1326918507-28033-1-git-send-email-amdragon@mit.edu>\r
35         <1327285873-4713-1-git-send-email-amdragon@mit.edu>\r
36         <1327285873-4713-2-git-send-email-amdragon@mit.edu>\r
37 User-Agent: Notmuch/0.11+76~g1de742d (http://notmuchmail.org) Emacs/23.3.1\r
38         (i686-pc-linux-gnu)\r
39 Date: Mon, 23 Jan 2012 20:07:52 +0200\r
40 Message-ID: <87ipk2e1hj.fsf@nikula.org>\r
41 MIME-Version: 1.0\r
42 X-Gm-Message-State:\r
43  ALoCoQmYLxdbNS/OMhh0cUVGm0d8wQnj+s0qZ45GbazNAd2ar2mVfB7XyZxDF41TVjAx10x5Zo/L\r
44 Content-Type: text/plain; charset=us-ascii\r
45 X-BeenThere: notmuch@notmuchmail.org\r
46 X-Mailman-Version: 2.1.13\r
47 Precedence: list\r
48 List-Id: "Use and development of the notmuch mail system."\r
49         <notmuch.notmuchmail.org>\r
50 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
51         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
52 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
53 List-Post: <mailto:notmuch@notmuchmail.org>\r
54 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
55 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
56         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
57 X-List-Received-Date: Mon, 23 Jan 2012 18:08:03 -0000\r
58 \r
59 On Sun, 22 Jan 2012 21:31:11 -0500, Austin Clements <amdragon@MIT.EDU> wrote:\r
60 > This makes the part numbers readily accessible to formatters.\r
61 > Hierarchical part numbering would be a more natural and efficient fit\r
62 > for MIME and may be the way to go in the future, but depth-first\r
63 > numbering maintains compatibility with what we currently do.\r
64 > ---\r
65 >  mime-node.c      |   37 ++++++++++++++++++++++++++++++++++---\r
66 >  notmuch-client.h |   14 +++++++++++++-\r
67 >  2 files changed, 47 insertions(+), 4 deletions(-)\r
68\r
69 > diff --git a/mime-node.c b/mime-node.c\r
70 > index 27077f7..025c537 100644\r
71 > --- a/mime-node.c\r
72 > +++ b/mime-node.c\r
73 > @@ -112,6 +112,10 @@ mime_node_open (const void *ctx, notmuch_message_t *message,\r
74 >      root->nchildren = 1;\r
75 >      root->ctx = mctx;\r
76 >  \r
77 > +    root->part_num = 0;\r
78 > +    root->next_child = 0;\r
79 > +    root->next_part_num = 1;\r
80 > +\r
81 >      *root_out = root;\r
82 >      return NOTMUCH_STATUS_SUCCESS;\r
83 >  \r
84 > @@ -137,7 +141,7 @@ _signature_validity_free (GMimeSignatureValidity **proxy)\r
85 >  #endif\r
86 >  \r
87 >  static mime_node_t *\r
88 > -_mime_node_create (const mime_node_t *parent, GMimeObject *part)\r
89 > +_mime_node_create (mime_node_t *parent, GMimeObject *part)\r
90 >  {\r
91 >      mime_node_t *node = talloc_zero (parent, mime_node_t);\r
92 >      GError *err = NULL;\r
93 > @@ -150,6 +154,8 @@ _mime_node_create (const mime_node_t *parent, GMimeObject *part)\r
94 >       talloc_free (node);\r
95 >       return NULL;\r
96 >      }\r
97 > +    node->parent = parent;\r
98 > +    node->part_num = node->next_part_num = -1;\r
99 >  \r
100 >      /* Deal with the different types of parts */\r
101 >      if (GMIME_IS_PART (part)) {\r
102 > @@ -267,9 +273,10 @@ _mime_node_create (const mime_node_t *parent, GMimeObject *part)\r
103 >  }\r
104 >  \r
105 >  mime_node_t *\r
106 > -mime_node_child (const mime_node_t *parent, int child)\r
107 > +mime_node_child (mime_node_t *parent, int child)\r
108 >  {\r
109 >      GMimeObject *sub;\r
110 > +    mime_node_t *node;\r
111 >  \r
112 >      if (!parent || child < 0 || child >= parent->nchildren)\r
113 >       return NULL;\r
114 > @@ -287,7 +294,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
117 >      }\r
118 > -    return _mime_node_create (parent, sub);\r
119 > +    node = _mime_node_create (parent, sub);\r
120 > +\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
126 > +\r
127 > +     /* Drop the const qualifier because these are internal fields\r
128 > +      * whose mutability doesn't affect the interface. */\r
129 \r
130 Leftover comment from the old version.\r
131 \r
132 Otherwise, the code looks good, with the disclaimer that I don't know\r
133 much about MIME or gmime.\r
134 \r
135 BR,\r
136 Jani.\r
137 \r
138 \r
139 > +     parent->next_child++;\r
140 > +     parent->next_part_num = -1;\r
141 > +\r
142 > +     if (node->nchildren == 0) {\r
143 > +         /* We've reached a leaf, so find the parent that has more\r
144 > +          * children and set it up to number its next child. */\r
145 > +         mime_node_t *it = node;\r
146 > +         while (it && it->next_child == it->nchildren)\r
147 > +             it = it->parent;\r
148 > +         if (it)\r
149 > +             it->next_part_num = node->part_num + 1;\r
150 > +     }\r
151 > +    }\r
152 > +\r
153 > +    return node;\r
154 >  }\r
155 >  \r
156 >  static mime_node_t *\r
157 > diff --git a/notmuch-client.h b/notmuch-client.h\r
158 > index 9c1d383..abfe5d3 100644\r
159 > --- a/notmuch-client.h\r
160 > +++ b/notmuch-client.h\r
161 > @@ -297,6 +297,13 @@ typedef struct mime_node {\r
162 >      /* The number of children of this part. */\r
163 >      int nchildren;\r
164 >  \r
165 > +    /* The parent of this node or NULL if this is the root node. */\r
166 > +    struct mime_node *parent;\r
167 > +\r
168 > +    /* The depth-first part number of this child if the MIME tree is\r
169 > +     * being traversed in depth-first order, or -1 otherwise. */\r
170 > +    int part_num;\r
171 > +\r
172 >      /* True if decryption of this part was attempted. */\r
173 >      notmuch_bool_t decrypt_attempted;\r
174 >      /* True if decryption of this part's child succeeded.  In this\r
175 > @@ -324,6 +331,11 @@ typedef struct mime_node {\r
176 >      /* Internal: For successfully decrypted multipart parts, the\r
177 >       * decrypted part to substitute for the second child. */\r
178 >      GMimeObject *decrypted_child;\r
179 > +\r
180 > +    /* Internal: The next child for depth-first traversal and the part\r
181 > +     * number to assign it (or -1 if unknown). */\r
182 > +    int next_child;\r
183 > +    int next_part_num;\r
184 >  } mime_node_t;\r
185 >  \r
186 >  /* Construct a new MIME node pointing to the root message part of\r
187 > @@ -356,7 +368,7 @@ mime_node_open (const void *ctx, notmuch_message_t *message,\r
188 >   * an error message on stderr).\r
189 >   */\r
190 >  mime_node_t *\r
191 > -mime_node_child (const mime_node_t *parent, int child);\r
192 > +mime_node_child (mime_node_t *parent, int child);\r
193 >  \r
194 >  /* Return the nth child of node in a depth-first traversal.  If n is\r
195 >   * 0, returns node itself.  Returns NULL if there is no such part. */\r
196 > -- \r
197 > 1.7.7.3\r
198\r
199 > _______________________________________________\r
200 > notmuch mailing list\r
201 > notmuch@notmuchmail.org\r
202 > http://notmuchmail.org/mailman/listinfo/notmuch\r