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 68870429E25
\r
6 for <notmuch@notmuchmail.org>; Wed, 11 Jan 2012 17:49:48 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\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 If54rhDurTQW for <notmuch@notmuchmail.org>;
\r
16 Wed, 11 Jan 2012 17:49:47 -0800 (PST)
\r
17 Received: from dmz-mailsec-scanner-7.mit.edu (DMZ-MAILSEC-SCANNER-7.MIT.EDU
\r
19 by olra.theworths.org (Postfix) with ESMTP id B49A9431FB6
\r
20 for <notmuch@notmuchmail.org>; Wed, 11 Jan 2012 17:49:46 -0800 (PST)
\r
21 X-AuditID: 12074424-b7fae6d000000906-f1-4f0e3c398ff9
\r
22 Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])
\r
23 by dmz-mailsec-scanner-7.mit.edu (Symantec Messaging Gateway) with SMTP
\r
24 id 80.E3.02310.93C3E0F4; Wed, 11 Jan 2012 20:49:45 -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 q0C1nj6m029648;
\r
27 Wed, 11 Jan 2012 20:49:45 -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 q0C1ngH3001516
\r
33 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);
\r
34 Wed, 11 Jan 2012 20:49:44 -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 1Rl9nS-00080F-My; Wed, 11 Jan 2012 20:49:42 -0500
\r
38 From: Austin Clements <amdragon@MIT.EDU>
\r
39 To: notmuch@notmuchmail.org
\r
40 Subject: [RFC PATCH 5/5] show: Simplify new text formatter code
\r
41 Date: Wed, 11 Jan 2012 20:49:33 -0500
\r
42 Message-Id: <1326332973-30225-6-git-send-email-amdragon@mit.edu>
\r
43 X-Mailer: git-send-email 1.7.7.3
\r
44 In-Reply-To: <1326332973-30225-1-git-send-email-amdragon@mit.edu>
\r
45 References: <1326332973-30225-1-git-send-email-amdragon@mit.edu>
\r
46 X-Brightmail-Tracker:
\r
47 H4sIAAAAAAAAA+NgFtrIIsWRmVeSWpSXmKPExsUixG6nrmtpw+dv8GuVpMX1mzOZHRg9nq26
\r
48 xRzAGMVlk5Kak1mWWqRvl8CV8X9xI3vBGY+KpVuSGxiXW3cxcnJICJhI/HiyhRXCFpO4cG89
\r
49 WxcjF4eQwD5GiamrbjFBOBsYJVa9m8wO4dxnkmj/s5oZwpnPKDH77iFGkH42AQ2JbfuXg9ki
\r
50 AtISO+/OBprLwcEsICLxbiYTSFhYwF7i2KNzYGEWAVWJvle1IGFeAQeJEz3XWCCuUJA4t/oc
\r
51 O4jNKeAo0X/8GBuILQRU82LnU+YJjPwLGBlWMcqm5Fbp5iZm5hSnJusWJyfm5aUW6Zrr5WaW
\r
52 6KWmlG5iBIeMi8oOxuZDSocYBTgYlXh4d+zl9RdiTSwrrsw9xCjJwaQkyvvdis9fiC8pP6Uy
\r
53 I7E4I76oNCe1+BCjBAezkgivUw1QOW9KYmVValE+TEqag0VJnFdD652fkEB6YklqdmpqQWoR
\r
54 TFaGg0NJgrfEGmioYFFqempFWmZOCUKaiYMTZDgP0PAMkBre4oLE3OLMdIj8KUZFKXFed5CE
\r
55 AEgiozQPrhcW068YxYFeEebNB6niAaYDuO5XQIOZgAZvWccDMrgkESEl1cBYdup0keXWmXMT
\r
56 Oxrm+1R4lktd+Jaw9FZg8IpKQ/uNT/z+zezw/l+dXq8WezNh2TEHqaP8TJMZZ6cY9l1uEDe+
\r
57 nbPl4GHhk2qSO14uOfeO7+CDhTu0OL41nD5+5k9JUf7KmP8nebfsVHFkTYqpmMk4jcXi0MKP
\r
58 2Wemv73185f1tHM6+k9UGtYzKbEUZyQaajEXFScCAI+/5ZrEAgAA
\r
59 X-BeenThere: notmuch@notmuchmail.org
\r
60 X-Mailman-Version: 2.1.13
\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: Thu, 12 Jan 2012 01:49:48 -0000
\r
73 This makes the text formatter take advantage of the new code
\r
74 structure. The previously duplicated header logic is now unified,
\r
75 several things that we used to compute repeatedly across different
\r
76 callbacks are now computed once, and the code is generally simplified.
\r
78 Unifying the header logic causes this to format some dates slightly
\r
79 differently, so the two affected test cases are updated.
\r
81 notmuch-show.c | 84 ++++++++++++----------------------------------------
\r
83 test/thread-naming | 16 +++++-----
\r
84 3 files changed, 28 insertions(+), 74 deletions(-)
\r
86 diff --git a/notmuch-show.c b/notmuch-show.c
\r
87 index 3241965..1689222 100644
\r
88 --- a/notmuch-show.c
\r
89 +++ b/notmuch-show.c
\r
90 @@ -175,67 +175,42 @@ format_part_text (const void *ctx, mime_node_t *node,
\r
91 GMimeObject *meta = node->envelope_part ?
\r
92 GMIME_OBJECT (node->envelope_part) : node->part;
\r
93 GMimeContentType *content_type = g_mime_object_get_content_type (meta);
\r
94 + GMimeContentDisposition *disposition =
\r
95 + g_mime_object_get_content_disposition (meta);
\r
96 + notmuch_bool_t attachment = disposition &&
\r
97 + strcmp (disposition->disposition, GMIME_DISPOSITION_ATTACHMENT) == 0;
\r
98 + notmuch_bool_t leaf = GMIME_IS_PART (node->part);
\r
101 if (node->envelope_file) {
\r
102 notmuch_message_t *message = node->envelope_file;
\r
103 - const char *headers[] = {
\r
104 - "Subject", "From", "To", "Cc", "Bcc", "Date"
\r
106 - const char *name, *value;
\r
109 - printf ("\fmessage{ ");
\r
110 - printf ("id:%s depth:%d match:%d filename:%s\n",
\r
111 + printf ("\fmessage{ id:%s depth:%d match:%d filename:%s\n",
\r
112 notmuch_message_get_message_id (message),
\r
114 notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_MATCH),
\r
115 notmuch_message_get_filename (message));
\r
117 - printf ("\fheader{\n");
\r
119 - printf ("%s\n", _get_one_line_summary (ctx, message));
\r
121 - for (i = 0; i < ARRAY_SIZE (headers); i++) {
\r
122 - name = headers[i];
\r
123 - value = notmuch_message_get_header (message, name);
\r
124 - if (value && strlen (value))
\r
125 - printf ("%s: %s\n", name, value);
\r
127 - printf ("\fheader}\n");
\r
129 - GMimeContentDisposition *disposition = g_mime_object_get_content_disposition (meta);
\r
130 const char *cid = g_mime_object_get_content_id (meta);
\r
131 + const char *filename = leaf ?
\r
132 + g_mime_part_get_filename (GMIME_PART (node->part)) : NULL;
\r
134 - if (disposition &&
\r
135 - strcmp (disposition->disposition, GMIME_DISPOSITION_ATTACHMENT) == 0)
\r
137 - printf ("\fattachment{ ID: %d", node->part_num);
\r
141 - printf ("\fpart{ ID: %d", node->part_num);
\r
144 - if (GMIME_IS_PART (node->part))
\r
146 - const char *filename = g_mime_part_get_filename (GMIME_PART (node->part));
\r
148 - printf (", Filename: %s", filename);
\r
151 + printf ("\f%s{ ID: %d", attachment ? "attachment" : "part", node->part_num);
\r
153 + printf (", Filename: %s", filename);
\r
155 printf (", Content-id: %s", cid);
\r
157 printf (", Content-type: %s\n", g_mime_content_type_to_string (content_type));
\r
160 - if (node->envelope_part) {
\r
161 + if (GMIME_IS_MESSAGE (node->part)) {
\r
162 GMimeMessage *message = GMIME_MESSAGE (node->part);
\r
163 InternetAddressList *recipients;
\r
164 const char *recipients_string;
\r
166 printf ("\fheader{\n");
\r
167 + if (node->envelope_file)
\r
168 + printf ("%s\n", _get_one_line_summary (ctx, node->envelope_file));
\r
169 printf ("Subject: %s\n", g_mime_message_get_subject (message));
\r
170 printf ("From: %s\n", g_mime_message_get_sender (message));
\r
171 recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_TO);
\r
172 @@ -248,9 +223,11 @@ format_part_text (const void *ctx, mime_node_t *node,
\r
173 printf ("Cc: %s\n", recipients_string);
\r
174 printf ("Date: %s\n", g_mime_message_get_date_as_string (message));
\r
175 printf ("\fheader}\n");
\r
177 + printf ("\fbody{\n");
\r
180 - if (!node->envelope_file) {
\r
182 if (g_mime_content_type_is_type (content_type, "text", "*") &&
\r
183 !g_mime_content_type_is_type (content_type, "text", "html"))
\r
185 @@ -258,24 +235,12 @@ format_part_text (const void *ctx, mime_node_t *node,
\r
186 g_mime_stream_file_set_owner (GMIME_STREAM_FILE (stream_stdout), FALSE);
\r
187 show_text_part_content (node->part, stream_stdout);
\r
188 g_object_unref(stream_stdout);
\r
190 - else if (g_mime_content_type_is_type (content_type, "multipart", "*") ||
\r
191 - g_mime_content_type_is_type (content_type, "message", "rfc822"))
\r
193 - /* Do nothing for multipart since its content will be printed
\r
194 - * when recursing. */
\r
199 printf ("Non-text part: %s\n",
\r
200 g_mime_content_type_to_string (content_type));
\r
204 - if (GMIME_IS_MESSAGE (node->part)) {
\r
205 - printf ("\fbody{\n");
\r
208 for (i = 0; i < node->nchildren; i++)
\r
209 format_part_text (ctx, mime_node_child (node, i), indent, params);
\r
211 @@ -286,18 +251,7 @@ format_part_text (const void *ctx, mime_node_t *node,
\r
212 if (node->envelope_file) {
\r
213 printf ("\fmessage}\n");
\r
215 - GMimeContentDisposition *disposition;
\r
217 - disposition = g_mime_object_get_content_disposition (meta);
\r
218 - if (disposition &&
\r
219 - strcmp (disposition->disposition, GMIME_DISPOSITION_ATTACHMENT) == 0)
\r
221 - printf ("\fattachment}\n");
\r
225 - printf ("\fpart}\n");
\r
227 + printf ("\f%s}\n", attachment ? "attachment" : "part");
\r
231 diff --git a/test/crypto b/test/crypto
\r
232 index 0af4aa8..6723ef8 100755
\r
235 @@ -157,7 +157,7 @@ Notmuch Test Suite <test_suite@notmuchmail.org> (2000-01-01) (encrypted inbox)
\r
236 Subject: test encrypted message 001
\r
237 From: Notmuch Test Suite <test_suite@notmuchmail.org>
\r
238 To: test_suite@notmuchmail.org
\r
239 -Date: 01 Jan 2000 12:00:00 -0000
\r
240 +Date: Sat, 01 Jan 2000 12:00:00 +0000
\r
246 part{ ID: 1, Content-type: multipart/encrypted
\r
247 diff --git a/test/thread-naming b/test/thread-naming
\r
248 index 41b97d9..b7c96f2 100755
\r
249 --- a/test/thread-naming
\r
250 +++ b/test/thread-naming
\r
251 @@ -71,7 +71,7 @@ Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-05) (unread)
\r
252 Subject: thread-naming: Initial thread subject
\r
253 From: Notmuch Test Suite <test_suite@notmuchmail.org>
\r
254 To: Notmuch Test Suite <test_suite@notmuchmail.org>
\r
255 -Date: Fri, 05 Jan 2001 15:43:56 -0000
\r
256 +Date: Fri, 05 Jan 2001 15:43:56 +0000
\r
262 part{ ID: 1, Content-type: text/plain
\r
263 @@ -85,7 +85,7 @@ Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-06) (inbox unread)
\r
264 Subject: thread-naming: Older changed subject
\r
265 From: Notmuch Test Suite <test_suite@notmuchmail.org>
\r
266 To: Notmuch Test Suite <test_suite@notmuchmail.org>
\r
267 -Date: Sat, 06 Jan 2001 15:43:56 -0000
\r
268 +Date: Sat, 06 Jan 2001 15:43:56 +0000
\r
274 part{ ID: 1, Content-type: text/plain
\r
275 @@ -99,7 +99,7 @@ Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-07) (inbox unread)
\r
276 Subject: thread-naming: Newer changed subject
\r
277 From: Notmuch Test Suite <test_suite@notmuchmail.org>
\r
278 To: Notmuch Test Suite <test_suite@notmuchmail.org>
\r
279 -Date: Sun, 07 Jan 2001 15:43:56 -0000
\r
280 +Date: Sun, 07 Jan 2001 15:43:56 +0000
\r
286 part{ ID: 1, Content-type: text/plain
\r
287 @@ -113,7 +113,7 @@ Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-08) (unread)
\r
288 Subject: thread-naming: Final thread subject
\r
289 From: Notmuch Test Suite <test_suite@notmuchmail.org>
\r
290 To: Notmuch Test Suite <test_suite@notmuchmail.org>
\r
291 -Date: Mon, 08 Jan 2001 15:43:56 -0000
\r
292 +Date: Mon, 08 Jan 2001 15:43:56 +0000
\r
298 part{ ID: 1, Content-type: text/plain
\r
299 @@ -127,7 +127,7 @@ Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-09) (inbox unread)
\r
300 Subject: Re: thread-naming: Initial thread subject
\r
301 From: Notmuch Test Suite <test_suite@notmuchmail.org>
\r
302 To: Notmuch Test Suite <test_suite@notmuchmail.org>
\r
303 -Date: Tue, 09 Jan 2001 15:43:45 -0000
\r
304 +Date: Tue, 09 Jan 2001 15:43:45 +0000
\r
310 part{ ID: 1, Content-type: text/plain
\r
311 @@ -141,7 +141,7 @@ Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-10) (inbox unread)
\r
312 Subject: Aw: thread-naming: Initial thread subject
\r
313 From: Notmuch Test Suite <test_suite@notmuchmail.org>
\r
314 To: Notmuch Test Suite <test_suite@notmuchmail.org>
\r
315 -Date: Wed, 10 Jan 2001 15:43:45 -0000
\r
316 +Date: Wed, 10 Jan 2001 15:43:45 +0000
\r
322 part{ ID: 1, Content-type: text/plain
\r
323 @@ -155,7 +155,7 @@ Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-11) (inbox unread)
\r
324 Subject: Vs: thread-naming: Initial thread subject
\r
325 From: Notmuch Test Suite <test_suite@notmuchmail.org>
\r
326 To: Notmuch Test Suite <test_suite@notmuchmail.org>
\r
327 -Date: Thu, 11 Jan 2001 15:43:45 -0000
\r
328 +Date: Thu, 11 Jan 2001 15:43:45 +0000
\r
334 part{ ID: 1, Content-type: text/plain
\r
335 @@ -169,7 +169,7 @@ Notmuch Test Suite <test_suite@notmuchmail.org> (2001-01-12) (inbox unread)
\r
336 Subject: Sv: thread-naming: Initial thread subject
\r
337 From: Notmuch Test Suite <test_suite@notmuchmail.org>
\r
338 To: Notmuch Test Suite <test_suite@notmuchmail.org>
\r
339 -Date: Fri, 12 Jan 2001 15:43:45 -0000
\r
340 +Date: Fri, 12 Jan 2001 15:43:45 +0000
\r
346 part{ ID: 1, Content-type: text/plain
\r