[PATCH 7/9] CLI: add properties to dump output
[notmuch-archives.git] / 6c / f5ae44459a550fe686ad94efec196c8b38ee7e
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 3D737431FC0\r
6         for <notmuch@notmuchmail.org>; Wed, 18 Jan 2012 12:28:38 -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 Czrf-cucW5qD for <notmuch@notmuchmail.org>;\r
16         Wed, 18 Jan 2012 12:28:37 -0800 (PST)\r
17 Received: from dmz-mailsec-scanner-1.mit.edu (DMZ-MAILSEC-SCANNER-1.MIT.EDU\r
18         [18.9.25.12])\r
19         by olra.theworths.org (Postfix) with ESMTP id 8AA7E431FAE\r
20         for <notmuch@notmuchmail.org>; Wed, 18 Jan 2012 12:28:37 -0800 (PST)\r
21 X-AuditID: 1209190c-b7fad6d000000920-a1-4f172b75e492\r
22 Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\r
23         by dmz-mailsec-scanner-1.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id 2B.19.02336.57B271F4; Wed, 18 Jan 2012 15:28:37 -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 q0IKSavb030561; \r
27         Wed, 18 Jan 2012 15:28:36 -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 q0IKSZWb015660\r
32         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
33         Wed, 18 Jan 2012 15:28:35 -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 1Rnc7X-0007Q9-Am; Wed, 18 Jan 2012 15:28:35 -0500\r
37 From: Austin Clements <amdragon@MIT.EDU>\r
38 To: notmuch@notmuchmail.org\r
39 Subject: [PATCH 1/3] mime node: Record depth-first part numbers\r
40 Date: Wed, 18 Jan 2012 15:28:25 -0500\r
41 Message-Id: <1326918507-28033-2-git-send-email-amdragon@mit.edu>\r
42 X-Mailer: git-send-email 1.7.7.3\r
43 In-Reply-To: <1326918507-28033-1-git-send-email-amdragon@mit.edu>\r
44 References: <1326918507-28033-1-git-send-email-amdragon@mit.edu>\r
45 X-Brightmail-Tracker:\r
46  H4sIAAAAAAAAA+NgFrrJIsWRmVeSWpSXmKPExsUixG6nrluqLe5vcOUkh0Vr92cmi6tb+9kt\r
47         mqY7W+zZ52Vx/eZMZgdWj7Pd7awed09zeeycdZfd49b91+wez1bdYg5gjeKySUnNySxLLdK3\r
48         S+DKaGqcx1bwSKZiy4TJjA2MM8S6GDk5JARMJJ4tucoMYYtJXLi3nq2LkYtDSGAfo8ScPbfZ\r
49         IZwNjBLPlm9igXCOM0ncOPCKCcKZzyhx8GMvG0g/m4CGxLb9yxlBbBEBaYmdd2ezgtjMArUS\r
50         r/5eAasRFrCXONo9CyzOIqAq8XDlBHYQm1fAQeLKtyZ2iDsUJM6tPgdmcwo4Srz5+xVsphBQ\r
51         zdqfexknMPIvYGRYxSibklulm5uYmVOcmqxbnJyYl5dapGuol5tZopeaUrqJERSCnJI8Oxjf\r
52         HFQ6xCjAwajEwxshIu4vxJpYVlyZe4hRkoNJSZS3ShMoxJeUn1KZkVicEV9UmpNafIhRgoNZ\r
53         SYT3Cx9QjjclsbIqtSgfJiXNwaIkzqui9c5PSCA9sSQ1OzW1ILUIJivDwaEkwbtGC6hRsCg1\r
54         PbUiLTOnBCHNxMEJMpwHaPgSkBre4oLE3OLMdIj8KUZFKXFeHmCUCwmAJDJK8+B6YSniFaM4\r
55         0CvCvMtB2nmA6QWu+xXQYCagwR5NYiCDSxIRUlINjD2nt36J3smYZNSUGvHz1ANz/wUbWitv\r
56         cNn6iK5l+LCD1zFtXYdIzNFqm1aOaZ91fB9l5oY3FhtuaTXoy16gnf+S91/jVReVo0U9bXa2\r
57         y581mTzrSfve+H3hHTWW1OfpR+uijih7/queHuYYpLZcZLtwD7feO/Wta6YqX/PPiPibd/et\r
58         8a2pSizFGYmGWsxFxYkAUyageuwCAAA=\r
59 Cc: dkg@fifthhorseman.net\r
60 X-BeenThere: notmuch@notmuchmail.org\r
61 X-Mailman-Version: 2.1.13\r
62 Precedence: list\r
63 List-Id: "Use and development of the notmuch mail system."\r
64         <notmuch.notmuchmail.org>\r
65 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
66         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
67 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
68 List-Post: <mailto:notmuch@notmuchmail.org>\r
69 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
70 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
71         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
72 X-List-Received-Date: Wed, 18 Jan 2012 20:28:38 -0000\r
73 \r
74 This makes the part numbers readily accessible to formatters.\r
75 Hierarchical part numbering would be a more natural and efficient fit\r
76 for MIME and may be the way to go in the future, but depth-first\r
77 numbering maintains compatibility with what we currently do.\r
78 ---\r
79  mime-node.c      |   33 ++++++++++++++++++++++++++++++++-\r
80  notmuch-client.h |   11 +++++++++++\r
81  2 files changed, 43 insertions(+), 1 deletions(-)\r
82 \r
83 diff --git a/mime-node.c b/mime-node.c\r
84 index d26bb44..30b542f 100644\r
85 --- a/mime-node.c\r
86 +++ b/mime-node.c\r
87 @@ -104,6 +104,10 @@ mime_node_open (const void *ctx, notmuch_message_t *message,\r
88      root->nchildren = 1;\r
89      root->ctx = mctx;\r
90  \r
91 +    root->part_num = 0;\r
92 +    root->next_child = 0;\r
93 +    root->next_part_num = 1;\r
94 +\r
95      *root_out = root;\r
96      return NOTMUCH_STATUS_SUCCESS;\r
97  \r
98 @@ -133,6 +137,8 @@ _mime_node_create (const mime_node_t *parent, GMimeObject *part)\r
99         talloc_free (node);\r
100         return NULL;\r
101      }\r
102 +    node->parent = parent;\r
103 +    node->part_num = node->next_part_num = -1;\r
104  \r
105      /* Deal with the different types of parts */\r
106      if (GMIME_IS_PART (part)) {\r
107 @@ -217,6 +223,7 @@ mime_node_t *\r
108  mime_node_child (const mime_node_t *parent, int child)\r
109  {\r
110      GMimeObject *sub;\r
111 +    mime_node_t *node;\r
112  \r
113      if (!parent || child < 0 || child >= parent->nchildren)\r
114         return NULL;\r
115 @@ -234,7 +241,31 @@ mime_node_child (const mime_node_t *parent, int child)\r
116         INTERNAL_ERROR ("Unexpected GMimeObject type: %s",\r
117                         g_type_name (G_OBJECT_TYPE (parent->part)));\r
118      }\r
119 -    return _mime_node_create (parent, sub);\r
120 +    node = _mime_node_create (parent, sub);\r
121 +\r
122 +    if (child == parent->next_child && parent->next_part_num != -1) {\r
123 +       /* We're traversing in depth-first order.  Record the child's\r
124 +        * depth-first numbering. */\r
125 +       node->part_num = parent->next_part_num;\r
126 +       node->next_part_num = node->part_num + 1;\r
127 +\r
128 +       /* Drop the const qualifier because these are internal fields\r
129 +        * whose mutability doesn't affect the interface. */\r
130 +       ((mime_node_t*)parent)->next_child++;\r
131 +       ((mime_node_t*)parent)->next_part_num = -1;\r
132 +\r
133 +       if (node->nchildren == 0) {\r
134 +           /* We've reached a leaf, so find the parent that has more\r
135 +            * children and set it up to number its next child. */\r
136 +           const mime_node_t *it = node;\r
137 +           while (it && it->next_child == it->nchildren)\r
138 +               it = it->parent;\r
139 +           if (it)\r
140 +               ((mime_node_t*)it)->next_part_num = node->part_num + 1;\r
141 +       }\r
142 +    }\r
143 +\r
144 +    return node;\r
145  }\r
146  \r
147  static mime_node_t *\r
148 diff --git a/notmuch-client.h b/notmuch-client.h\r
149 index 62ede28..b3dcb6b 100644\r
150 --- a/notmuch-client.h\r
151 +++ b/notmuch-client.h\r
152 @@ -281,6 +281,13 @@ typedef struct mime_node {\r
153      /* The number of children of this part. */\r
154      int nchildren;\r
155  \r
156 +    /* The parent of this node or NULL if this is the root node. */\r
157 +    const struct mime_node *parent;\r
158 +\r
159 +    /* The depth-first part number of this child if the MIME tree is\r
160 +     * being traversed in depth-first order, or -1 otherwise. */\r
161 +    int part_num;\r
162 +\r
163      /* True if decryption of this part was attempted. */\r
164      notmuch_bool_t decrypt_attempted;\r
165      /* True if decryption of this part's child succeeded.  In this\r
166 @@ -302,6 +309,10 @@ typedef struct mime_node {\r
167      /* Internal: For successfully decrypted multipart parts, the\r
168       * decrypted part to substitute for the second child. */\r
169      GMimeObject *decrypted_child;\r
170 +\r
171 +    /* Internal: The next child for depth-first traversal and the part\r
172 +     * number to assign it (or -1 if unknown). */\r
173 +    int next_child, next_part_num;\r
174  } mime_node_t;\r
175  \r
176  /* Construct a new MIME node pointing to the root message part of\r
177 -- \r
178 1.7.7.3\r
179 \r