1 Return-Path: <jani@nikula.org>
\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 BAC64431FBC
\r
6 for <notmuch@notmuchmail.org>; Tue, 24 Jan 2012 10:26:27 -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 VRolIkXJos5n for <notmuch@notmuchmail.org>;
\r
16 Tue, 24 Jan 2012 10:26:27 -0800 (PST)
\r
17 Received: from mail-lpp01m010-f53.google.com (mail-lpp01m010-f53.google.com
\r
18 [209.85.215.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))
\r
19 (No client certificate requested)
\r
20 by olra.theworths.org (Postfix) with ESMTPS id D744C431FB6
\r
21 for <notmuch@notmuchmail.org>; Tue, 24 Jan 2012 10:26:26 -0800 (PST)
\r
22 Received: by lahd3 with SMTP id d3so1543359lah.26
\r
23 for <notmuch@notmuchmail.org>; Tue, 24 Jan 2012 10:26:25 -0800 (PST)
\r
24 Received: by 10.112.99.69 with SMTP id eo5mr3501196lbb.77.1327429585068;
\r
25 Tue, 24 Jan 2012 10:26:25 -0800 (PST)
\r
26 Received: from localhost (dsl-hkibrasgw4-fe50f800-253.dhcp.inet.fi.
\r
28 by mx.google.com with ESMTPS id pf12sm5951587lab.16.2012.01.24.10.26.19
\r
29 (version=SSLv3 cipher=OTHER); Tue, 24 Jan 2012 10:26:21 -0800 (PST)
\r
30 From: Jani Nikula <jani@nikula.org>
\r
31 To: Austin Clements <amdragon@MIT.EDU>, notmuch@notmuchmail.org
\r
32 Subject: Re: [PATCH v5 2/2] show: Introduce mime_node formatter callback
\r
33 In-Reply-To: <1327361590-19273-3-git-send-email-amdragon@mit.edu>
\r
34 References: <1326918507-28033-1-git-send-email-amdragon@mit.edu>
\r
35 <1327361590-19273-1-git-send-email-amdragon@mit.edu>
\r
36 <1327361590-19273-3-git-send-email-amdragon@mit.edu>
\r
37 User-Agent: Notmuch/0.11+76~g1de742d (http://notmuchmail.org) Emacs/23.3.1
\r
39 Date: Tue, 24 Jan 2012 20:26:18 +0200
\r
40 Message-ID: <87fwf59ctx.fsf@nikula.org>
\r
43 ALoCoQnnCbjQO98p2GX/49OYEg/Y/O4U75En/FGqE07ZZKpb4dIRaxGN80EM2Dx8slld9ChxiihO
\r
44 Content-Type: text/plain; charset=us-ascii
\r
45 Cc: tomi.ollila@iki.fi
\r
46 X-BeenThere: notmuch@notmuchmail.org
\r
47 X-Mailman-Version: 2.1.13
\r
49 List-Id: "Use and development of the notmuch mail system."
\r
50 <notmuch.notmuchmail.org>
\r
51 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
52 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
53 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
54 List-Post: <mailto:notmuch@notmuchmail.org>
\r
55 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
56 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
57 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
58 X-List-Received-Date: Tue, 24 Jan 2012 18:26:28 -0000
\r
60 On Mon, 23 Jan 2012 18:33:10 -0500, Austin Clements <amdragon@MIT.EDU> wrote:
\r
61 > This callback is the gateway to the new mime_node_t-based formatters.
\r
62 > This maintains backwards compatibility so the formatters can be
\r
63 > transitioned one at a time. Once all formatters are converted, the
\r
64 > formatter structure can be reduced to only message_set_{start,sep,end}
\r
65 > and part, most of show_message can be deleted, and all of
\r
66 > show-message.c can be deleted.
\r
68 > notmuch-client.h | 6 ++++++
\r
69 > notmuch-reply.c | 2 +-
\r
70 > notmuch-show.c | 21 +++++++++++++++++----
\r
71 > 3 files changed, 24 insertions(+), 5 deletions(-)
\r
73 > diff --git a/notmuch-client.h b/notmuch-client.h
\r
74 > index abfe5d3..093c789 100644
\r
75 > --- a/notmuch-client.h
\r
76 > +++ b/notmuch-client.h
\r
77 > @@ -62,8 +62,14 @@
\r
78 > #define STRINGIFY(s) STRINGIFY_(s)
\r
79 > #define STRINGIFY_(s) #s
\r
81 > +struct mime_node;
\r
82 > +struct notmuch_show_params;
\r
84 > typedef struct notmuch_show_format {
\r
85 > const char *message_set_start;
\r
86 > + void (*part) (const void *ctx,
\r
87 > + struct mime_node *node, int indent,
\r
88 > + const struct notmuch_show_params *params);
\r
89 > const char *message_start;
\r
90 > void (*message) (const void *ctx,
\r
91 > notmuch_message_t *message,
\r
92 > diff --git a/notmuch-reply.c b/notmuch-reply.c
\r
93 > index bf67960..f55b1d2 100644
\r
94 > --- a/notmuch-reply.c
\r
95 > +++ b/notmuch-reply.c
\r
96 > @@ -31,7 +31,7 @@ static void
\r
97 > reply_part_content (GMimeObject *part);
\r
99 > static const notmuch_show_format_t format_reply = {
\r
103 > "", NULL, reply_headers_message_part, ">\n",
\r
105 > diff --git a/notmuch-show.c b/notmuch-show.c
\r
106 > index 682aa71..dec799c 100644
\r
107 > --- a/notmuch-show.c
\r
108 > +++ b/notmuch-show.c
\r
109 > @@ -42,7 +42,7 @@ static void
\r
110 > format_part_end_text (GMimeObject *part);
\r
112 > static const notmuch_show_format_t format_text = {
\r
115 > "\fmessage{ ", format_message_text,
\r
116 > "\fheader{\n", format_headers_text, format_headers_message_part_text, "\fheader}\n",
\r
118 > @@ -89,7 +89,7 @@ static void
\r
119 > format_part_end_json (GMimeObject *part);
\r
121 > static const notmuch_show_format_t format_json = {
\r
124 > "{", format_message_json,
\r
125 > "\"headers\": {", format_headers_json, format_headers_message_part_json, "}",
\r
127 > @@ -110,7 +110,7 @@ format_message_mbox (const void *ctx,
\r
128 > unused (int indent));
\r
130 > static const notmuch_show_format_t format_mbox = {
\r
133 > "", format_message_mbox,
\r
134 > "", NULL, NULL, "",
\r
136 > @@ -129,7 +129,7 @@ static void
\r
137 > format_part_content_raw (GMimeObject *part);
\r
139 > static const notmuch_show_format_t format_raw = {
\r
143 > "", NULL, format_headers_message_part_text, "\n",
\r
145 > @@ -850,6 +850,19 @@ show_message (void *ctx,
\r
147 > notmuch_show_params_t *params)
\r
149 > + if (format->part) {
\r
150 > + void *local = talloc_new (ctx);
\r
151 > + mime_node_t *root, *part;
\r
153 > + if (mime_node_open (local, message, params->cryptoctx, params->decrypt,
\r
154 > + &root) == NOTMUCH_STATUS_SUCCESS &&
\r
155 > + (part = mime_node_seek_dfs (root, (params->part < 0 ?
\r
156 > + 0 : params->part))))
\r
157 > + format->part (local, part, indent, params);
\r
159 I know you did this because Dmitry asked to remove the goto, but I'd
\r
160 argue this is *much* less readable than the original with goto. There's
\r
161 just way too much going on in the if. Two calls, an assignment, a
\r
162 ternary operator. KISS.
\r
171 > + talloc_free (local);
\r
175 > if (params->part <= 0) {
\r
176 > fputs (format->message_start, stdout);
\r
177 > if (format->message)
\r