Re: [PATCH 9/9] add has: query prefix to search for specific properties
[notmuch-archives.git] / 7a / 4173cf2669b8208cd2aa5489f572d6478fd471
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 A601B421192\r
6         for <notmuch@notmuchmail.org>; Mon, 23 Jan 2012 12:29:08 -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 xbPBySCBY-cC for <notmuch@notmuchmail.org>;\r
16         Mon, 23 Jan 2012 12:29:07 -0800 (PST)\r
17 Received: from dmz-mailsec-scanner-4.mit.edu (DMZ-MAILSEC-SCANNER-4.MIT.EDU\r
18         [18.9.25.15])\r
19         by olra.theworths.org (Postfix) with ESMTP id CB05C429E21\r
20         for <notmuch@notmuchmail.org>; Mon, 23 Jan 2012 12:29:07 -0800 (PST)\r
21 X-AuditID: 1209190f-b7f8a6d000000914-a7-4f1dc31258ca\r
22 Received: from mailhub-auth-3.mit.edu ( [18.9.21.43])\r
23         by dmz-mailsec-scanner-4.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id 1F.77.02324.213CD1F4; Mon, 23 Jan 2012 15:29:06 -0500 (EST)\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
26         by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id q0NKT513008195; \r
27         Mon, 23 Jan 2012 15:29:05 -0500\r
28 Received: from drake.mit.edu (26-4-166.dynamic.csail.mit.edu [18.26.4.166])\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 q0NKT42A000597\r
32         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
33         Mon, 23 Jan 2012 15:29:05 -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 1RpQVj-0000MZ-L8; Mon, 23 Jan 2012 15:29:03 -0500\r
37 From: Austin Clements <amdragon@MIT.EDU>\r
38 To: notmuch@notmuchmail.org\r
39 Subject: [PATCH v3 1/2] mime node: Record depth-first part numbers\r
40 Date: Mon, 23 Jan 2012 15:29:00 -0500\r
41 Message-Id: <1327350541-1303-2-git-send-email-amdragon@mit.edu>\r
42 X-Mailer: git-send-email 1.7.7.3\r
43 In-Reply-To: <1327350541-1303-1-git-send-email-amdragon@mit.edu>\r
44 References: <1326918507-28033-1-git-send-email-amdragon@mit.edu>\r
45         <1327350541-1303-1-git-send-email-amdragon@mit.edu>\r
46 X-Brightmail-Tracker:\r
47  H4sIAAAAAAAAA+NgFtrIIsWRmVeSWpSXmKPExsUixCmqrSt0WNbf4M0GWYvrN2cyOzB6PFt1\r
48         izmAMYrLJiU1J7MstUjfLoEro3PJPaaCc0oVO84cYmpg/CDVxcjBISFgIvFiXXEXIyeQKSZx\r
49         4d56ti5GLg4hgX2MEr+urWKGcDYwSpzrXMEK4Rxnkjhz9hNUZj6jxNe/E9lA+tkENCS27V/O\r
50         CGKLCEhL7Lw7mxVkBbOAmsSfLhWQsLCAk8SjqW/YQMIsAqoS1x9FgYR5Bewl/jd9Z4G4QkHi\r
51         3Opz7CA2p4CDxPV3U8FsIYEyid23LzNPYORfwMiwilE2JbdKNzcxM6c4NVm3ODkxLy+1SNdE\r
52         LzezRC81pXQTIzhkJPl3MH47qHSIUYCDUYmHV2KmrL8Qa2JZcWXuIUZJDiYlUV6VfUAhvqT8\r
53         lMqMxOKM+KLSnNTiQ4wSHMxKIrxGj2X8hXhTEiurUovyYVLSHCxK4rxqWu/8hATSE0tSs1NT\r
54         C1KLYLIyHBxKErwlh4CGChalpqdWpGXmlCCkmTg4QYbzAA0vAqnhLS5IzC3OTIfIn2JUlBLn\r
55         zQNJCIAkMkrz4HphMf2KURzoFWHebpAqHmA6gOt+BTSYCWgwR54UyOCSRISUVAOjTeCbnlz+\r
56         Kl3tCH021kf9bL9WPWV9lPft7HX7P4vly25MO/1EiMtAfUGtzqw7seve8Nx2F373/4MZgw7f\r
57         hcmWJxKXRwfx2sbPd0j4YDLZcJu3/tNVO5lEH3Rq7Q/r0G4Ljpr9wMiqJlYnaPFhvuLun6tC\r
58         /itZuF35e2P1+gaxwHTpR80cjH+VWIozEg21mIuKEwFRdTDIxAIAAA==\r
59 X-BeenThere: notmuch@notmuchmail.org\r
60 X-Mailman-Version: 2.1.13\r
61 Precedence: list\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: Mon, 23 Jan 2012 20:29:08 -0000\r
72 \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
77 ---\r
78  mime-node.c      |   36 +++++++++++++++++++++++++++++++++---\r
79  notmuch-client.h |   14 +++++++++++++-\r
80  2 files changed, 46 insertions(+), 4 deletions(-)\r
81 \r
82 diff --git a/mime-node.c b/mime-node.c\r
83 index 27077f7..c073c7e 100644\r
84 --- a/mime-node.c\r
85 +++ b/mime-node.c\r
86 @@ -112,6 +112,10 @@ mime_node_open (const void *ctx, notmuch_message_t *message,\r
87      root->nchildren = 1;\r
88      root->ctx = mctx;\r
89  \r
90 +    root->part_num = 0;\r
91 +    root->next_child = 0;\r
92 +    root->next_part_num = 1;\r
93 +\r
94      *root_out = root;\r
95      return NOTMUCH_STATUS_SUCCESS;\r
96  \r
97 @@ -137,7 +141,7 @@ _signature_validity_free (GMimeSignatureValidity **proxy)\r
98  #endif\r
99  \r
100  static mime_node_t *\r
101 -_mime_node_create (const mime_node_t *parent, GMimeObject *part)\r
102 +_mime_node_create (mime_node_t *parent, GMimeObject *part)\r
103  {\r
104      mime_node_t *node = talloc_zero (parent, mime_node_t);\r
105      GError *err = NULL;\r
106 @@ -150,6 +154,8 @@ _mime_node_create (const mime_node_t *parent, GMimeObject *part)\r
107         talloc_free (node);\r
108         return NULL;\r
109      }\r
110 +    node->parent = parent;\r
111 +    node->part_num = node->next_part_num = -1;\r
112  \r
113      /* Deal with the different types of parts */\r
114      if (GMIME_IS_PART (part)) {\r
115 @@ -267,9 +273,10 @@ _mime_node_create (const mime_node_t *parent, GMimeObject *part)\r
116  }\r
117  \r
118  mime_node_t *\r
119 -mime_node_child (const mime_node_t *parent, int child)\r
120 +mime_node_child (mime_node_t *parent, int child)\r
121  {\r
122      GMimeObject *sub;\r
123 +    mime_node_t *node;\r
124  \r
125      if (!parent || child < 0 || child >= parent->nchildren)\r
126         return NULL;\r
127 @@ -287,7 +294,30 @@ mime_node_child (const mime_node_t *parent, int child)\r
128         INTERNAL_ERROR ("Unexpected GMimeObject type: %s",\r
129                         g_type_name (G_OBJECT_TYPE (parent->part)));\r
130      }\r
131 -    return _mime_node_create (parent, sub);\r
132 +    node = _mime_node_create (parent, sub);\r
133 +\r
134 +    if (child == parent->next_child && parent->next_part_num != -1) {\r
135 +       /* We're traversing in depth-first order.  Record the child's\r
136 +        * depth-first numbering. */\r
137 +       node->part_num = parent->next_part_num;\r
138 +       node->next_part_num = node->part_num + 1;\r
139 +\r
140 +       /* Prepare the parent for its next depth-first child. */\r
141 +       parent->next_child++;\r
142 +       parent->next_part_num = -1;\r
143 +\r
144 +       if (node->nchildren == 0) {\r
145 +           /* We've reached a leaf, so find the parent that has more\r
146 +            * children and set it up to number its next child. */\r
147 +           mime_node_t *it = node;\r
148 +           while (it && it->next_child == it->nchildren)\r
149 +               it = it->parent;\r
150 +           if (it)\r
151 +               it->next_part_num = node->part_num + 1;\r
152 +       }\r
153 +    }\r
154 +\r
155 +    return node;\r
156  }\r
157  \r
158  static mime_node_t *\r
159 diff --git a/notmuch-client.h b/notmuch-client.h\r
160 index 9c1d383..abfe5d3 100644\r
161 --- a/notmuch-client.h\r
162 +++ b/notmuch-client.h\r
163 @@ -297,6 +297,13 @@ typedef struct mime_node {\r
164      /* The number of children of this part. */\r
165      int nchildren;\r
166  \r
167 +    /* The parent of this node or NULL if this is the root node. */\r
168 +    struct mime_node *parent;\r
169 +\r
170 +    /* The depth-first part number of this child if the MIME tree is\r
171 +     * being traversed in depth-first order, or -1 otherwise. */\r
172 +    int part_num;\r
173 +\r
174      /* True if decryption of this part was attempted. */\r
175      notmuch_bool_t decrypt_attempted;\r
176      /* True if decryption of this part's child succeeded.  In this\r
177 @@ -324,6 +331,11 @@ typedef struct mime_node {\r
178      /* Internal: For successfully decrypted multipart parts, the\r
179       * decrypted part to substitute for the second child. */\r
180      GMimeObject *decrypted_child;\r
181 +\r
182 +    /* Internal: The next child for depth-first traversal and the part\r
183 +     * number to assign it (or -1 if unknown). */\r
184 +    int next_child;\r
185 +    int next_part_num;\r
186  } mime_node_t;\r
187  \r
188  /* Construct a new MIME node pointing to the root message part of\r
189 @@ -356,7 +368,7 @@ mime_node_open (const void *ctx, notmuch_message_t *message,\r
190   * an error message on stderr).\r
191   */\r
192  mime_node_t *\r
193 -mime_node_child (const mime_node_t *parent, int child);\r
194 +mime_node_child (mime_node_t *parent, int child);\r
195  \r
196  /* Return the nth child of node in a depth-first traversal.  If n is\r
197   * 0, returns node itself.  Returns NULL if there is no such part. */\r
198 -- \r
199 1.7.7.3\r
200 \r