1 Return-Path: <dmitry.kurochkin@gmail.com>
\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 4C780429E54
\r
6 for <notmuch@notmuchmail.org>; Mon, 23 Jan 2012 17:33:45 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5
\r
12 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
\r
13 FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled
\r
14 Received: from olra.theworths.org ([127.0.0.1])
\r
15 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
16 with ESMTP id f70La6sAEDmk for <notmuch@notmuchmail.org>;
\r
17 Mon, 23 Jan 2012 17:33:44 -0800 (PST)
\r
18 Received: from mail-bk0-f53.google.com (mail-bk0-f53.google.com
\r
19 [209.85.214.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))
\r
20 (No client certificate requested)
\r
21 by olra.theworths.org (Postfix) with ESMTPS id D0BFE429E21
\r
22 for <notmuch@notmuchmail.org>; Mon, 23 Jan 2012 17:33:43 -0800 (PST)
\r
23 Received: by bkbzt19 with SMTP id zt19so1887462bkb.26
\r
24 for <notmuch@notmuchmail.org>; Mon, 23 Jan 2012 17:33:40 -0800 (PST)
\r
25 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;
\r
26 h=from:to:subject:in-reply-to:references:user-agent:date:message-id
\r
27 :mime-version:content-type;
\r
28 bh=IesD17Hs1dHa9Qz6sRY0gVntzjFxoRzOiRWFHkl/fG8=;
\r
29 b=OC6G6mdnPFxNAnchT4rGR0j3ginzDzkKNjODlnLSbo5dTwBxJHRQQlC7AkVkVnNvy7
\r
30 HyEaTl6UNV4awE4Tv9oEO8gThoHnRI99Nsn9P3Dkr3ywZfoQWGR4OUKMwslWD4g0fbxZ
\r
31 Cn76CIzk/ErI7DAFqWpc0PJmfvvMAxz2F35QI=
\r
32 Received: by 10.204.152.201 with SMTP id h9mr4171823bkw.105.1327368820742;
\r
33 Mon, 23 Jan 2012 17:33:40 -0800 (PST)
\r
34 Received: from localhost ([91.144.186.21])
\r
35 by mx.google.com with ESMTPS id cz3sm26899808bkb.3.2012.01.23.17.33.39
\r
36 (version=TLSv1/SSLv3 cipher=OTHER);
\r
37 Mon, 23 Jan 2012 17:33:39 -0800 (PST)
\r
38 From: Dmitry Kurochkin <dmitry.kurochkin@gmail.com>
\r
39 To: Austin Clements <amdragon@MIT.EDU>, notmuch@notmuchmail.org
\r
40 Subject: Re: [RFC PATCH 4/5] show: Convert text format to the new
\r
41 self-recursive style
\r
42 In-Reply-To: <1326332973-30225-5-git-send-email-amdragon@mit.edu>
\r
43 References: <1326332973-30225-1-git-send-email-amdragon@mit.edu>
\r
44 <1326332973-30225-5-git-send-email-amdragon@mit.edu>
\r
45 User-Agent: Notmuch/0.11+100~gd650abf (http://notmuchmail.org) Emacs/23.3.1
\r
46 (x86_64-pc-linux-gnu)
\r
47 Date: Tue, 24 Jan 2012 05:32:35 +0400
\r
48 Message-ID: <87obttnavg.fsf@gmail.com>
\r
50 Content-Type: text/plain; charset=us-ascii
\r
51 X-BeenThere: notmuch@notmuchmail.org
\r
52 X-Mailman-Version: 2.1.13
\r
54 List-Id: "Use and development of the notmuch mail system."
\r
55 <notmuch.notmuchmail.org>
\r
56 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
57 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
58 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
59 List-Post: <mailto:notmuch@notmuchmail.org>
\r
60 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
61 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
62 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
63 X-List-Received-Date: Tue, 24 Jan 2012 01:33:45 -0000
\r
65 On Wed, 11 Jan 2012 20:49:32 -0500, Austin Clements <amdragon@MIT.EDU> wrote:
\r
66 > This is all code movement and a smidgen of glue. This moves the
\r
67 > existing text formatter code into one self-recursive function, but
\r
68 > doesn't change any of the logic. The next patch will actually take
\r
69 > advantage of what the new structure has to offer.
\r
71 The patch looks good to me.
\r
77 > notmuch-show.c | 267 +++++++++++++++++++++++++++++---------------------------
\r
78 > 1 files changed, 140 insertions(+), 127 deletions(-)
\r
80 > diff --git a/notmuch-show.c b/notmuch-show.c
\r
81 > index ad54d69..3241965 100644
\r
82 > --- a/notmuch-show.c
\r
83 > +++ b/notmuch-show.c
\r
84 > @@ -21,40 +21,17 @@
\r
85 > #include "notmuch-client.h"
\r
88 > -format_message_text (unused (const void *ctx),
\r
89 > - notmuch_message_t *message,
\r
92 > -format_headers_text (const void *ctx,
\r
93 > - notmuch_message_t *message);
\r
96 > format_headers_message_part_text (GMimeMessage *message);
\r
99 > -format_part_start_text (GMimeObject *part,
\r
100 > - int *part_count);
\r
103 > -format_part_content_text (GMimeObject *part);
\r
106 > -format_part_end_text (GMimeObject *part);
\r
107 > +format_part_text (const void *ctx, mime_node_t *node,
\r
108 > + int indent, notmuch_show_params_t *params);
\r
110 > static const notmuch_show_format_t format_text = {
\r
112 > - "\fmessage{ ", format_message_text,
\r
113 > - "\fheader{\n", format_headers_text, format_headers_message_part_text, "\fheader}\n",
\r
115 > - format_part_start_text,
\r
118 > - format_part_content_text,
\r
119 > - format_part_end_text,
\r
122 > - "\fmessage}\n", "",
\r
124 > + .message_set_start = "",
\r
125 > + .part = format_part_text,
\r
126 > + .message_set_sep = "",
\r
127 > + .message_set_end = ""
\r
131 > @@ -140,6 +117,9 @@ static const notmuch_show_format_t format_raw = {
\r
136 > +show_text_part_content (GMimeObject *part, GMimeStream *stream_out);
\r
138 > static const char *
\r
139 > _get_tags_as_string (const void *ctx, notmuch_message_t *message)
\r
141 > @@ -187,13 +167,138 @@ _get_one_line_summary (const void *ctx, notmuch_message_t *message)
\r
145 > -format_message_text (unused (const void *ctx), notmuch_message_t *message, int indent)
\r
146 > +format_part_text (const void *ctx, mime_node_t *node,
\r
147 > + int indent, notmuch_show_params_t *params)
\r
149 > - printf ("id:%s depth:%d match:%d filename:%s\n",
\r
150 > - notmuch_message_get_message_id (message),
\r
152 > - notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_MATCH),
\r
153 > - notmuch_message_get_filename (message));
\r
154 > + /* The disposition and content-type metadata are associated with
\r
155 > + * the envelope for message parts */
\r
156 > + GMimeObject *meta = node->envelope_part ?
\r
157 > + GMIME_OBJECT (node->envelope_part) : node->part;
\r
158 > + GMimeContentType *content_type = g_mime_object_get_content_type (meta);
\r
161 > + if (node->envelope_file) {
\r
162 > + notmuch_message_t *message = node->envelope_file;
\r
163 > + const char *headers[] = {
\r
164 > + "Subject", "From", "To", "Cc", "Bcc", "Date"
\r
166 > + const char *name, *value;
\r
167 > + unsigned int i;
\r
169 > + printf ("\fmessage{ ");
\r
170 > + printf ("id:%s depth:%d match:%d filename:%s\n",
\r
171 > + notmuch_message_get_message_id (message),
\r
173 > + notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_MATCH),
\r
174 > + notmuch_message_get_filename (message));
\r
176 > + printf ("\fheader{\n");
\r
178 > + printf ("%s\n", _get_one_line_summary (ctx, message));
\r
180 > + for (i = 0; i < ARRAY_SIZE (headers); i++) {
\r
181 > + name = headers[i];
\r
182 > + value = notmuch_message_get_header (message, name);
\r
183 > + if (value && strlen (value))
\r
184 > + printf ("%s: %s\n", name, value);
\r
186 > + printf ("\fheader}\n");
\r
188 > + GMimeContentDisposition *disposition = g_mime_object_get_content_disposition (meta);
\r
189 > + const char *cid = g_mime_object_get_content_id (meta);
\r
191 > + if (disposition &&
\r
192 > + strcmp (disposition->disposition, GMIME_DISPOSITION_ATTACHMENT) == 0)
\r
194 > + printf ("\fattachment{ ID: %d", node->part_num);
\r
198 > + printf ("\fpart{ ID: %d", node->part_num);
\r
201 > + if (GMIME_IS_PART (node->part))
\r
203 > + const char *filename = g_mime_part_get_filename (GMIME_PART (node->part));
\r
205 > + printf (", Filename: %s", filename);
\r
209 > + printf (", Content-id: %s", cid);
\r
211 > + printf (", Content-type: %s\n", g_mime_content_type_to_string (content_type));
\r
214 > + if (node->envelope_part) {
\r
215 > + GMimeMessage *message = GMIME_MESSAGE (node->part);
\r
216 > + InternetAddressList *recipients;
\r
217 > + const char *recipients_string;
\r
219 > + printf ("\fheader{\n");
\r
220 > + printf ("Subject: %s\n", g_mime_message_get_subject (message));
\r
221 > + printf ("From: %s\n", g_mime_message_get_sender (message));
\r
222 > + recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_TO);
\r
223 > + recipients_string = internet_address_list_to_string (recipients, 0);
\r
224 > + if (recipients_string)
\r
225 > + printf ("To: %s\n", recipients_string);
\r
226 > + recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_CC);
\r
227 > + recipients_string = internet_address_list_to_string (recipients, 0);
\r
228 > + if (recipients_string)
\r
229 > + printf ("Cc: %s\n", recipients_string);
\r
230 > + printf ("Date: %s\n", g_mime_message_get_date_as_string (message));
\r
231 > + printf ("\fheader}\n");
\r
234 > + if (!node->envelope_file) {
\r
235 > + if (g_mime_content_type_is_type (content_type, "text", "*") &&
\r
236 > + !g_mime_content_type_is_type (content_type, "text", "html"))
\r
238 > + GMimeStream *stream_stdout = g_mime_stream_file_new (stdout);
\r
239 > + g_mime_stream_file_set_owner (GMIME_STREAM_FILE (stream_stdout), FALSE);
\r
240 > + show_text_part_content (node->part, stream_stdout);
\r
241 > + g_object_unref(stream_stdout);
\r
243 > + else if (g_mime_content_type_is_type (content_type, "multipart", "*") ||
\r
244 > + g_mime_content_type_is_type (content_type, "message", "rfc822"))
\r
246 > + /* Do nothing for multipart since its content will be printed
\r
247 > + * when recursing. */
\r
251 > + printf ("Non-text part: %s\n",
\r
252 > + g_mime_content_type_to_string (content_type));
\r
256 > + if (GMIME_IS_MESSAGE (node->part)) {
\r
257 > + printf ("\fbody{\n");
\r
260 > + for (i = 0; i < node->nchildren; i++)
\r
261 > + format_part_text (ctx, mime_node_child (node, i), indent, params);
\r
263 > + if (GMIME_IS_MESSAGE (node->part)) {
\r
264 > + printf ("\fbody}\n");
\r
267 > + if (node->envelope_file) {
\r
268 > + printf ("\fmessage}\n");
\r
270 > + GMimeContentDisposition *disposition;
\r
272 > + disposition = g_mime_object_get_content_disposition (meta);
\r
273 > + if (disposition &&
\r
274 > + strcmp (disposition->disposition, GMIME_DISPOSITION_ATTACHMENT) == 0)
\r
276 > + printf ("\fattachment}\n");
\r
280 > + printf ("\fpart}\n");
\r
286 > @@ -334,26 +439,6 @@ format_message_mbox (const void *ctx,
\r
292 > -format_headers_text (const void *ctx, notmuch_message_t *message)
\r
294 > - const char *headers[] = {
\r
295 > - "Subject", "From", "To", "Cc", "Bcc", "Date"
\r
297 > - const char *name, *value;
\r
298 > - unsigned int i;
\r
300 > - printf ("%s\n", _get_one_line_summary (ctx, message));
\r
302 > - for (i = 0; i < ARRAY_SIZE (headers); i++) {
\r
303 > - name = headers[i];
\r
304 > - value = notmuch_message_get_header (message, name);
\r
305 > - if (value && strlen (value))
\r
306 > - printf ("%s: %s\n", name, value);
\r
311 > format_headers_message_part_text (GMimeMessage *message)
\r
313 > @@ -503,78 +588,6 @@ signer_status_to_string (GMimeSignerStatus x)
\r
317 > -format_part_start_text (GMimeObject *part, int *part_count)
\r
319 > - GMimeContentDisposition *disposition = g_mime_object_get_content_disposition (part);
\r
321 > - if (disposition &&
\r
322 > - strcmp (disposition->disposition, GMIME_DISPOSITION_ATTACHMENT) == 0)
\r
324 > - printf ("\fattachment{ ID: %d", *part_count);
\r
328 > - printf ("\fpart{ ID: %d", *part_count);
\r
333 > -format_part_content_text (GMimeObject *part)
\r
335 > - const char *cid = g_mime_object_get_content_id (part);
\r
336 > - GMimeContentType *content_type = g_mime_object_get_content_type (GMIME_OBJECT (part));
\r
338 > - if (GMIME_IS_PART (part))
\r
340 > - const char *filename = g_mime_part_get_filename (GMIME_PART (part));
\r
342 > - printf (", Filename: %s", filename);
\r
346 > - printf (", Content-id: %s", cid);
\r
348 > - printf (", Content-type: %s\n", g_mime_content_type_to_string (content_type));
\r
350 > - if (g_mime_content_type_is_type (content_type, "text", "*") &&
\r
351 > - !g_mime_content_type_is_type (content_type, "text", "html"))
\r
353 > - GMimeStream *stream_stdout = g_mime_stream_file_new (stdout);
\r
354 > - g_mime_stream_file_set_owner (GMIME_STREAM_FILE (stream_stdout), FALSE);
\r
355 > - show_text_part_content (part, stream_stdout);
\r
356 > - g_object_unref(stream_stdout);
\r
358 > - else if (g_mime_content_type_is_type (content_type, "multipart", "*") ||
\r
359 > - g_mime_content_type_is_type (content_type, "message", "rfc822"))
\r
361 > - /* Do nothing for multipart since its content will be printed
\r
362 > - * when recursing. */
\r
366 > - printf ("Non-text part: %s\n",
\r
367 > - g_mime_content_type_to_string (content_type));
\r
372 > -format_part_end_text (GMimeObject *part)
\r
374 > - GMimeContentDisposition *disposition;
\r
376 > - disposition = g_mime_object_get_content_disposition (part);
\r
377 > - if (disposition &&
\r
378 > - strcmp (disposition->disposition, GMIME_DISPOSITION_ATTACHMENT) == 0)
\r
380 > - printf ("\fattachment}\n");
\r
384 > - printf ("\fpart}\n");
\r
389 > format_part_start_json (unused (GMimeObject *part), int *part_count)
\r
391 > printf ("{\"id\": %d", *part_count);
\r
395 > _______________________________________________
\r
396 > notmuch mailing list
\r
397 > notmuch@notmuchmail.org
\r
398 > http://notmuchmail.org/mailman/listinfo/notmuch
\r