Re: [PATCH v2 3/3] show: Introduce mime_node formatter callback
[notmuch-archives.git] / 78 / d350a95044d5a2d031a33a70ff53c40e6e2ffe
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 0A18C429E54\r
6         for <notmuch@notmuchmail.org>; Mon, 23 Jan 2012 14:38: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.799\r
10 X-Spam-Level: \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 2zvMBLeQFHfm for <notmuch@notmuchmail.org>;\r
17         Mon, 23 Jan 2012 14:38:37 -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 202F3429E21\r
22         for <notmuch@notmuchmail.org>; Mon, 23 Jan 2012 14:38:36 -0800 (PST)\r
23 Received: by bkbzt19 with SMTP id zt19so1782240bkb.26\r
24         for <notmuch@notmuchmail.org>; Mon, 23 Jan 2012 14:38:35 -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=zVi4hNELe+v81INSGDuYzniUcsTy8U9IJATbr4MermE=;\r
29         b=wm+5ljffm6M1BZAynbdo7lUZ7Q1CmfUkMIAZLLuaziEHMSb7gcQhzNShG92UDV527Y\r
30         yXDNbQgbGf1zPfCUkyNpupF8uq9ZHONl8BGOtYUVY/9jd92+sFH2j6LarJgoLOcvWDGw\r
31         Slc0w4M7bpy7HfPsDbd+LaZDWrKgyP1NmbLs4=\r
32 Received: by 10.204.154.211 with SMTP id p19mr4072050bkw.130.1327358315691;\r
33         Mon, 23 Jan 2012 14:38:35 -0800 (PST)\r
34 Received: from localhost ([91.144.186.21])\r
35         by mx.google.com with ESMTPS id ga13sm31546122bkc.5.2012.01.23.14.38.34\r
36         (version=TLSv1/SSLv3 cipher=OTHER);\r
37         Mon, 23 Jan 2012 14:38:34 -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: [PATCH v2 3/3] show: Introduce mime_node formatter callback\r
41 In-Reply-To: <1327285873-4713-4-git-send-email-amdragon@mit.edu>\r
42 References: <1326918507-28033-1-git-send-email-amdragon@mit.edu>\r
43         <1327285873-4713-1-git-send-email-amdragon@mit.edu>\r
44         <1327285873-4713-4-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 02:37:30 +0400\r
48 Message-ID: <8739b6niz9.fsf@gmail.com>\r
49 MIME-Version: 1.0\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
53 Precedence: list\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: Mon, 23 Jan 2012 22:38:38 -0000\r
64 \r
65 On Sun, 22 Jan 2012 21:31:13 -0500, Austin Clements <amdragon@MIT.EDU> wrote:\r
66 > This callback is the gateway to the new mime_node_t-based formatters.\r
67 > This maintains backwards compatibility so the formatters can be\r
68 > transitioned one at a time.  Once all formatters are converted, the\r
69 > formatter structure can be reduced to only message_set_{start,sep,end}\r
70 > and part, most of show_message can be deleted, and all of\r
71 > show-message.c can be deleted.\r
72 \r
73 Few comments below.\r
74 \r
75 > ---\r
76 >  notmuch-client.h |    6 ++++++\r
77 >  notmuch-reply.c  |    2 +-\r
78 >  notmuch-show.c   |   23 +++++++++++++++++++----\r
79 >  3 files changed, 26 insertions(+), 5 deletions(-)\r
80\r
81 > diff --git a/notmuch-client.h b/notmuch-client.h\r
82 > index abfe5d3..59606b4 100644\r
83 > --- a/notmuch-client.h\r
84 > +++ b/notmuch-client.h\r
85 > @@ -62,8 +62,14 @@\r
86 >  #define STRINGIFY(s) STRINGIFY_(s)\r
87 >  #define STRINGIFY_(s) #s\r
88 >  \r
89 > +struct mime_node;\r
90 > +struct notmuch_show_params;\r
91 > +\r
92 >  typedef struct notmuch_show_format {\r
93 >      const char *message_set_start;\r
94 > +    void (*part) (const void *ctx,\r
95 > +               struct mime_node *node, int indent,\r
96 > +               struct notmuch_show_params *params);\r
97 \r
98 Can we make the params parameter const?\r
99 \r
100 >      const char *message_start;\r
101 >      void (*message) (const void *ctx,\r
102 >                    notmuch_message_t *message,\r
103 > diff --git a/notmuch-reply.c b/notmuch-reply.c\r
104 > index bf67960..f55b1d2 100644\r
105 > --- a/notmuch-reply.c\r
106 > +++ b/notmuch-reply.c\r
107 > @@ -31,7 +31,7 @@ static void\r
108 >  reply_part_content (GMimeObject *part);\r
109 >  \r
110 >  static const notmuch_show_format_t format_reply = {\r
111 > -    "",\r
112 > +    "", NULL,\r
113 >       "", NULL,\r
114 >           "", NULL, reply_headers_message_part, ">\n",\r
115 >           "",\r
116 > diff --git a/notmuch-show.c b/notmuch-show.c\r
117 > index 682aa71..8185b02 100644\r
118 > --- a/notmuch-show.c\r
119 > +++ b/notmuch-show.c\r
120 > @@ -42,7 +42,7 @@ static void\r
121 >  format_part_end_text (GMimeObject *part);\r
122 >  \r
123 >  static const notmuch_show_format_t format_text = {\r
124 > -    "",\r
125 > +    "", NULL,\r
126 >       "\fmessage{ ", format_message_text,\r
127 >           "\fheader{\n", format_headers_text, format_headers_message_part_text, "\fheader}\n",\r
128 >           "\fbody{\n",\r
129 > @@ -89,7 +89,7 @@ static void\r
130 >  format_part_end_json (GMimeObject *part);\r
131 >  \r
132 >  static const notmuch_show_format_t format_json = {\r
133 > -    "[",\r
134 > +    "[", NULL,\r
135 >       "{", format_message_json,\r
136 >           "\"headers\": {", format_headers_json, format_headers_message_part_json, "}",\r
137 >           ", \"body\": [",\r
138 > @@ -110,7 +110,7 @@ format_message_mbox (const void *ctx,\r
139 >                    unused (int indent));\r
140 >  \r
141 >  static const notmuch_show_format_t format_mbox = {\r
142 > -    "",\r
143 > +    "", NULL,\r
144 >          "", format_message_mbox,\r
145 >              "", NULL, NULL, "",\r
146 >              "",\r
147 > @@ -129,7 +129,7 @@ static void\r
148 >  format_part_content_raw (GMimeObject *part);\r
149 >  \r
150 >  static const notmuch_show_format_t format_raw = {\r
151 > -    "",\r
152 > +    "", NULL,\r
153 >       "", NULL,\r
154 >           "", NULL, format_headers_message_part_text, "\n",\r
155 >              "",\r
156 > @@ -850,6 +850,21 @@ show_message (void *ctx,\r
157 >             int indent,\r
158 >             notmuch_show_params_t *params)\r
159 >  {\r
160 > +    if (format->part) {\r
161 > +     void *local = talloc_new (ctx);\r
162 > +     mime_node_t *root, *part;\r
163 > +\r
164 > +     if (mime_node_open (local, message, params->cryptoctx, params->decrypt,\r
165 > +                         &root) != NOTMUCH_STATUS_SUCCESS)\r
166 > +         goto DONE;\r
167 > +     part = mime_node_seek_dfs (root, params->part < 0 ? 0 : params->part);\r
168 \r
169 This should be done as a separate patch, but it looks like zero and\r
170 negative params->part is handled in the same way so we can change it to\r
171 always be non-negative.\r
172 \r
173 > +     if (part)\r
174 > +         format->part (local, part, indent, params);\r
175 > +      DONE:\r
176 > +     talloc_free (local);\r
177 > +     return;\r
178 \r
179 Please move part assignment inside the if and remove the goto:\r
180 \r
181   if (mime_node_open() == success && (part = seek()))\r
182     format->part();\r
183 \r
184 Regards,\r
185   Dmitry\r
186 \r
187 > +    }\r
188 > +\r
189 >      if (params->part <= 0) {\r
190 >       fputs (format->message_start, stdout);\r
191 >       if (format->message)\r
192 > -- \r
193 > 1.7.7.3\r
194\r
195 > _______________________________________________\r
196 > notmuch mailing list\r
197 > notmuch@notmuchmail.org\r
198 > http://notmuchmail.org/mailman/listinfo/notmuch\r