Re: [PATCH v4 13/16] add indexopts to notmuch python bindings.
[notmuch-archives.git] / bb / 69e4d277ce05b3aaa1af47c4c3d716d71a8c4d
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 E0294429E54\r
6         for <notmuch@notmuchmail.org>; Mon, 23 Jan 2012 15:26:42 -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 xFj4X29jWeWX for <notmuch@notmuchmail.org>;\r
16         Mon, 23 Jan 2012 15:26:42 -0800 (PST)\r
17 Received: from dmz-mailsec-scanner-3.mit.edu (DMZ-MAILSEC-SCANNER-3.MIT.EDU\r
18         [18.9.25.14])\r
19         by olra.theworths.org (Postfix) with ESMTP id 43077429E21\r
20         for <notmuch@notmuchmail.org>; Mon, 23 Jan 2012 15:26:42 -0800 (PST)\r
21 X-AuditID: 1209190e-b7f7c6d0000008c3-6f-4f1decb2e8d3\r
22 Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\r
23         by dmz-mailsec-scanner-3.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id C8.0E.02243.2BCED1F4; Mon, 23 Jan 2012 18:26:42 -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 q0NNQfif026076; \r
27         Mon, 23 Jan 2012 18:26:41 -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 q0NNQc3a024572\r
32         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
33         Mon, 23 Jan 2012 18:26:39 -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 1RpTHY-0004qM-BO; Mon, 23 Jan 2012 18:26:36 -0500\r
37 From: Austin Clements <amdragon@MIT.EDU>\r
38 To: notmuch@notmuchmail.org\r
39 Subject: [PATCH v4 1/3] mime node: Record depth-first part numbers\r
40 Date: Mon, 23 Jan 2012 18:26:21 -0500\r
41 Message-Id: <1327361183-18485-2-git-send-email-amdragon@mit.edu>\r
42 X-Mailer: git-send-email 1.7.7.3\r
43 In-Reply-To: <1327361183-18485-1-git-send-email-amdragon@mit.edu>\r
44 References: <1326918507-28033-1-git-send-email-amdragon@mit.edu>\r
45         <1327361183-18485-1-git-send-email-amdragon@mit.edu>\r
46 X-Brightmail-Tracker:\r
47  H4sIAAAAAAAAA+NgFjrLIsWRmVeSWpSXmKPExsUixG6nrrvpjay/wZuvLBZXt/azWzRNd7a4\r
48         fnMms8WblfNYHVg8ds66y+5x+OtCFo9b91+zezxbdYs5gCWKyyYlNSezLLVI3y6BK2P2mT3M\r
49         BT3KFSd2tbM2MC6W7mLk5JAQMJF42X+UGcIWk7hwbz1bFyMXh5DAPkaJVdPXQDkbGCUaO58y\r
50         gVQJCRxnkujtSoJIzGeU+PbyIytIgk1AQ2Lb/uWMILaIgLTEzruzgeIcHMwCBRKTLxiDmMIC\r
51         ThKXF3qCVLAIqEo8nvwQrIJXwEHizaVkiBsUJM6tPscOYnMKOEr8aexghdhaLtF26zjLBEb+\r
52         BYwMqxhlU3KrdHMTM3OKU5N1i5MT8/JSi3SN9XIzS/RSU0o3MYJCjVOSbwfj14NKhxgFOBiV\r
53         eHgPTJP1F2JNLCuuzD3EKMnBpCTK6/oaKMSXlJ9SmZFYnBFfVJqTWnyIUYKDWUmEV+0cUI43\r
54         JbGyKrUoHyYlzcGiJM6rpvXOT0ggPbEkNTs1tSC1CCYrw8GhJMHLBYwpIcGi1PTUirTMnBKE\r
55         NBMHJ8hwHqDhDCA1vMUFibnFmekQ+VOMilLivMdALhIASWSU5sH1wlLBK0ZxoFeEeS+BVPEA\r
56         0whc9yugwUxAgznypEAGlyQipKQaGC0fGUlnO7qcE1mkeynsf+uaT0EeC1w52ze7XVbr/q3s\r
57         ETklVDq6yCvBVt1+gqi4xgQJ00+XHAX4z0nv5zypMMlLXMXL8qrWbDWjMANZzRU/lPgZEw/J\r
58         7/Sw7hX6mDJBbNGX250tddO6U+4U1b5aN8v5hKTL0X9MbZcemTiHtG87nO864UOnEktxRqKh\r
59         FnNRcSIAZMQizeACAAA=\r
60 Cc: tomi.ollila@iki.fi\r
61 X-BeenThere: notmuch@notmuchmail.org\r
62 X-Mailman-Version: 2.1.13\r
63 Precedence: list\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:26:43 -0000\r
74 \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
79 ---\r
80  mime-node.c      |   37 ++++++++++++++++++++++++++++++++++---\r
81  notmuch-client.h |   14 +++++++++++++-\r
82  2 files changed, 47 insertions(+), 4 deletions(-)\r
83 \r
84 diff --git a/mime-node.c b/mime-node.c\r
85 index 27077f7..025c537 100644\r
86 --- a/mime-node.c\r
87 +++ b/mime-node.c\r
88 @@ -112,6 +112,10 @@ mime_node_open (const void *ctx, notmuch_message_t *message,\r
89      root->nchildren = 1;\r
90      root->ctx = mctx;\r
91  \r
92 +    root->part_num = 0;\r
93 +    root->next_child = 0;\r
94 +    root->next_part_num = 1;\r
95 +\r
96      *root_out = root;\r
97      return NOTMUCH_STATUS_SUCCESS;\r
98  \r
99 @@ -137,7 +141,7 @@ _signature_validity_free (GMimeSignatureValidity **proxy)\r
100  #endif\r
101  \r
102  static mime_node_t *\r
103 -_mime_node_create (const mime_node_t *parent, GMimeObject *part)\r
104 +_mime_node_create (mime_node_t *parent, GMimeObject *part)\r
105  {\r
106      mime_node_t *node = talloc_zero (parent, mime_node_t);\r
107      GError *err = NULL;\r
108 @@ -150,6 +154,8 @@ _mime_node_create (const mime_node_t *parent, GMimeObject *part)\r
109         talloc_free (node);\r
110         return NULL;\r
111      }\r
112 +    node->parent = parent;\r
113 +    node->part_num = node->next_part_num = -1;\r
114  \r
115      /* Deal with the different types of parts */\r
116      if (GMIME_IS_PART (part)) {\r
117 @@ -267,9 +273,10 @@ _mime_node_create (const mime_node_t *parent, GMimeObject *part)\r
118  }\r
119  \r
120  mime_node_t *\r
121 -mime_node_child (const mime_node_t *parent, int child)\r
122 +mime_node_child (mime_node_t *parent, int child)\r
123  {\r
124      GMimeObject *sub;\r
125 +    mime_node_t *node;\r
126  \r
127      if (!parent || child < 0 || child >= parent->nchildren)\r
128         return NULL;\r
129 @@ -287,7 +294,31 @@ 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
132      }\r
133 -    return _mime_node_create (parent, sub);\r
134 +    node = _mime_node_create (parent, sub);\r
135 +\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
141 +\r
142 +       /* Drop the const qualifier because these are internal fields\r
143 +        * whose mutability doesn't affect the interface. */\r
144 +       parent->next_child++;\r
145 +       parent->next_part_num = -1;\r
146 +\r
147 +       if (node->nchildren == 0) {\r
148 +           /* We've reached a leaf, so find the parent that has more\r
149 +            * children and set it up to number its next child. */\r
150 +           mime_node_t *it = node;\r
151 +           while (it && it->next_child == it->nchildren)\r
152 +               it = it->parent;\r
153 +           if (it)\r
154 +               it->next_part_num = node->part_num + 1;\r
155 +       }\r
156 +    }\r
157 +\r
158 +    return node;\r
159  }\r
160  \r
161  static mime_node_t *\r
162 diff --git a/notmuch-client.h b/notmuch-client.h\r
163 index 9c1d383..abfe5d3 100644\r
164 --- a/notmuch-client.h\r
165 +++ b/notmuch-client.h\r
166 @@ -297,6 +297,13 @@ typedef struct mime_node {\r
167      /* The number of children of this part. */\r
168      int nchildren;\r
169  \r
170 +    /* The parent of this node or NULL if this is the root node. */\r
171 +    struct mime_node *parent;\r
172 +\r
173 +    /* The depth-first part number of this child if the MIME tree is\r
174 +     * being traversed in depth-first order, or -1 otherwise. */\r
175 +    int part_num;\r
176 +\r
177      /* True if decryption of this part was attempted. */\r
178      notmuch_bool_t decrypt_attempted;\r
179      /* True if decryption of this part's child succeeded.  In this\r
180 @@ -324,6 +331,11 @@ typedef struct mime_node {\r
181      /* Internal: For successfully decrypted multipart parts, the\r
182       * decrypted part to substitute for the second child. */\r
183      GMimeObject *decrypted_child;\r
184 +\r
185 +    /* Internal: The next child for depth-first traversal and the part\r
186 +     * number to assign it (or -1 if unknown). */\r
187 +    int next_child;\r
188 +    int next_part_num;\r
189  } mime_node_t;\r
190  \r
191  /* Construct a new MIME node pointing to the root message part of\r
192 @@ -356,7 +368,7 @@ mime_node_open (const void *ctx, notmuch_message_t *message,\r
193   * an error message on stderr).\r
194   */\r
195  mime_node_t *\r
196 -mime_node_child (const mime_node_t *parent, int child);\r
197 +mime_node_child (mime_node_t *parent, int child);\r
198  \r
199  /* Return the nth child of node in a depth-first traversal.  If n is\r
200   * 0, returns node itself.  Returns NULL if there is no such part. */\r
201 -- \r
202 1.7.7.3\r
203 \r