Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 64 / 4bbce39131d5939e7d2cab2aef635f7ea0f20b
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 349FB421188\r
6         for <notmuch@notmuchmail.org>; Sun, 22 Jan 2012 18:31:23 -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 K9ScELI83XqL for <notmuch@notmuchmail.org>;\r
16         Sun, 22 Jan 2012 18:31:21 -0800 (PST)\r
17 Received: from dmz-mailsec-scanner-8.mit.edu (DMZ-MAILSEC-SCANNER-8.MIT.EDU\r
18         [18.7.68.37])\r
19         by olra.theworths.org (Postfix) with ESMTP id 9FA05429E54\r
20         for <notmuch@notmuchmail.org>; Sun, 22 Jan 2012 18:31:21 -0800 (PST)\r
21 X-AuditID: 12074425-b7f4a6d0000008e0-ae-4f1cc67981db\r
22 Received: from mailhub-auth-3.mit.edu ( [18.9.21.43])\r
23         by dmz-mailsec-scanner-8.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id 21.94.02272.976CC1F4; Sun, 22 Jan 2012 21:31:21 -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 q0N2VKhI017748; \r
27         Sun, 22 Jan 2012 21:31:20 -0500\r
28 Received: from drake.mit.edu\r
29         (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com\r
30         [209.6.116.242]) (authenticated bits=0)\r
31         (User authenticated as amdragon@ATHENA.MIT.EDU)\r
32         by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q0N2VJBl001238\r
33         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
34         Sun, 22 Jan 2012 21:31:19 -0500 (EST)\r
35 Received: from amthrax by drake.mit.edu with local (Exim 4.77)\r
36         (envelope-from <amthrax@drake.mit.edu>)\r
37         id 1Rp9gk-0001J3-UJ; Sun, 22 Jan 2012 21:31:19 -0500\r
38 From: Austin Clements <amdragon@MIT.EDU>\r
39 To: notmuch@notmuchmail.org\r
40 Subject: [PATCH v2 1/3] mime node: Record depth-first part numbers\r
41 Date: Sun, 22 Jan 2012 21:31:11 -0500\r
42 Message-Id: <1327285873-4713-2-git-send-email-amdragon@mit.edu>\r
43 X-Mailer: git-send-email 1.7.7.3\r
44 In-Reply-To: <1327285873-4713-1-git-send-email-amdragon@mit.edu>\r
45 References: <1326918507-28033-1-git-send-email-amdragon@mit.edu>\r
46         <1327285873-4713-1-git-send-email-amdragon@mit.edu>\r
47 X-Brightmail-Tracker:\r
48  H4sIAAAAAAAAA+NgFtrAIsWRmVeSWpSXmKPExsUixCmqrVt5TMbfYO5sDovrN2cyOzB6PFt1\r
49         izmAMYrLJiU1J7MstUjfLoErY/aZPcwFPcoVJ3a1szYwLpbuYuTkkBAwkbh4dQkbhC0mceHe\r
50         ejBbSGAfo8TiH7FdjFxA9gZGifb5r5kgnPtMEst+XYSqms8o8XeZLojNJqAhsW3/ckYQW0RA\r
51         WmLn3dmsXYwcHMwCahJ/ulRAwsICThJ3J30GK2ERUJU4vWQOG0gJr4C9xNvtOhA3KEicW32O\r
52         HcTmFHCQ2H3pBCPEpjKJ+1cnME5g5F/AyLCKUTYlt0o3NzEzpzg1Wbc4OTEvL7VI10IvN7NE\r
53         LzWldBMjKGDYXVR3ME44pHSIUYCDUYmHN2KpjL8Qa2JZcWXuIUZJDiYlUV6zo0AhvqT8lMqM\r
54         xOKM+KLSnNTiQ4wSHMxKIrzOn6X9hXhTEiurUovyYVLSHCxK4ryaWu/8hATSE0tSs1NTC1KL\r
55         YLIyHBxKErxVIEMFi1LTUyvSMnNKENJMHJwgw3mAhq8AqeEtLkjMLc5Mh8ifYlSUEuedCZIQ\r
56         AElklObB9cIi+hWjONArwrwrQap4gMkArvsV0GAmoMEceVIgg0sSEVJSDYx8WX/8Vtas1/nz\r
57         6/KbRzZf7+i3y80Oi5SPbFI+4sY/N2ld4SleIauKpZWM73Nq382/Zhmy4J1Nlbgo31JpFWmb\r
58         i7wlapUrPU97le3iz33svf6m8WXOJ4t/GPz0WFofVcS65EvxVYurbN6mBy80rl5wiHFbVr1O\r
59         Sd1VT7FV7h1mW58zVJnzrVBiKc5INNRiLipOBAChm5QQwwIAAA==\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: Mon, 23 Jan 2012 02:31:23 -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      |   37 ++++++++++++++++++++++++++++++++++---\r
80  notmuch-client.h |   14 +++++++++++++-\r
81  2 files changed, 47 insertions(+), 4 deletions(-)\r
82 \r
83 diff --git a/mime-node.c b/mime-node.c\r
84 index 27077f7..025c537 100644\r
85 --- a/mime-node.c\r
86 +++ b/mime-node.c\r
87 @@ -112,6 +112,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 @@ -137,7 +141,7 @@ _signature_validity_free (GMimeSignatureValidity **proxy)\r
99  #endif\r
100  \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
104  {\r
105      mime_node_t *node = talloc_zero (parent, mime_node_t);\r
106      GError *err = NULL;\r
107 @@ -150,6 +154,8 @@ _mime_node_create (const mime_node_t *parent, GMimeObject *part)\r
108         talloc_free (node);\r
109         return NULL;\r
110      }\r
111 +    node->parent = parent;\r
112 +    node->part_num = node->next_part_num = -1;\r
113  \r
114      /* Deal with the different types of parts */\r
115      if (GMIME_IS_PART (part)) {\r
116 @@ -267,9 +273,10 @@ _mime_node_create (const mime_node_t *parent, GMimeObject *part)\r
117  }\r
118  \r
119  mime_node_t *\r
120 -mime_node_child (const mime_node_t *parent, int child)\r
121 +mime_node_child (mime_node_t *parent, int child)\r
122  {\r
123      GMimeObject *sub;\r
124 +    mime_node_t *node;\r
125  \r
126      if (!parent || child < 0 || child >= parent->nchildren)\r
127         return NULL;\r
128 @@ -287,7 +294,31 @@ mime_node_child (const mime_node_t *parent, int child)\r
129         INTERNAL_ERROR ("Unexpected GMimeObject type: %s",\r
130                         g_type_name (G_OBJECT_TYPE (parent->part)));\r
131      }\r
132 -    return _mime_node_create (parent, sub);\r
133 +    node = _mime_node_create (parent, sub);\r
134 +\r
135 +    if (child == parent->next_child && parent->next_part_num != -1) {\r
136 +       /* We're traversing in depth-first order.  Record the child's\r
137 +        * depth-first numbering. */\r
138 +       node->part_num = parent->next_part_num;\r
139 +       node->next_part_num = node->part_num + 1;\r
140 +\r
141 +       /* Drop the const qualifier because these are internal fields\r
142 +        * whose mutability doesn't affect the interface. */\r
143 +       parent->next_child++;\r
144 +       parent->next_part_num = -1;\r
145 +\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 *it = node;\r
150 +           while (it && it->next_child == it->nchildren)\r
151 +               it = it->parent;\r
152 +           if (it)\r
153 +               it->next_part_num = node->part_num + 1;\r
154 +       }\r
155 +    }\r
156 +\r
157 +    return node;\r
158  }\r
159  \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
167      int nchildren;\r
168  \r
169 +    /* The parent of this node or NULL if this is the root node. */\r
170 +    struct mime_node *parent;\r
171 +\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
174 +    int part_num;\r
175 +\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
183 +\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
188  } mime_node_t;\r
189  \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
193   */\r
194  mime_node_t *\r
195 -mime_node_child (const mime_node_t *parent, int child);\r
196 +mime_node_child (mime_node_t *parent, int child);\r
197  \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
200 -- \r
201 1.7.7.3\r
202 \r