[PATCH v3 4/7] Add internal functions to search for alternate doc types
[notmuch-archives.git] / 93 / 24664d665c7d8adfa7d6178dae328edfa0ba76
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 74078429E54\r
6         for <notmuch@notmuchmail.org>; Mon, 23 Jan 2012 15:37:46 -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 e4lVpKl281M1 for <notmuch@notmuchmail.org>;\r
17         Mon, 23 Jan 2012 15:37:46 -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 BAAA8429E21\r
22         for <notmuch@notmuchmail.org>; Mon, 23 Jan 2012 15:37:45 -0800 (PST)\r
23 Received: by mail-bk0-f53.google.com with SMTP id zt19so1820797bkb.26\r
24         for <notmuch@notmuchmail.org>; Mon, 23 Jan 2012 15:37:45 -0800 (PST)\r
25 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;\r
26         h=from:to:cc:subject:in-reply-to:references:user-agent:date\r
27         :message-id:mime-version:content-type;\r
28         bh=sNNR73U9gI3OQv8Fq0797LDQ1T+8xzIvyEwCa9n+t/Y=;\r
29         b=gB/yVNKzG4dX5+Rx0yJthS2xlo20K1BampSkr04fd2i+vei0tMHVjWXfHJMqEc9mMp\r
30         XF4GyfR2rwDNZKQNujViBFewq+MMyCctidro9OPOT4Hg5KtwMDJv5RVPlZu2I40Gd/RV\r
31         wlTsxuo6JaEQHGNKIQ//moUauwBWnpSLe4Okg=\r
32 Received: by 10.204.150.69 with SMTP id x5mr3970669bkv.53.1327361865361;\r
33         Mon, 23 Jan 2012 15:37:45 -0800 (PST)\r
34 Received: from localhost ([91.144.186.21])\r
35         by mx.google.com with ESMTPS id ew13sm8169080bkb.1.2012.01.23.15.37.44\r
36         (version=TLSv1/SSLv3 cipher=OTHER);\r
37         Mon, 23 Jan 2012 15:37:44 -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 v5 2/2] show: Introduce mime_node formatter callback\r
41 In-Reply-To: <1327361590-19273-3-git-send-email-amdragon@mit.edu>\r
42 References: <1326918507-28033-1-git-send-email-amdragon@mit.edu>\r
43         <1327361590-19273-1-git-send-email-amdragon@mit.edu>\r
44         <1327361590-19273-3-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 03:36:39 +0400\r
48 Message-ID: <87r4yqm1o8.fsf@gmail.com>\r
49 MIME-Version: 1.0\r
50 Content-Type: text/plain; charset=us-ascii\r
51 Cc: tomi.ollila@iki.fi\r
52 X-BeenThere: notmuch@notmuchmail.org\r
53 X-Mailman-Version: 2.1.13\r
54 Precedence: list\r
55 List-Id: "Use and development of the notmuch mail system."\r
56         <notmuch.notmuchmail.org>\r
57 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
58         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
59 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
60 List-Post: <mailto:notmuch@notmuchmail.org>\r
61 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
62 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
63         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
64 X-List-Received-Date: Mon, 23 Jan 2012 23:37:46 -0000\r
65 \r
66 On Mon, 23 Jan 2012 18:33:10 -0500, Austin Clements <amdragon@MIT.EDU> wrote:\r
67 > This callback is the gateway to the new mime_node_t-based formatters.\r
68 > This maintains backwards compatibility so the formatters can be\r
69 > transitioned one at a time.  Once all formatters are converted, the\r
70 > formatter structure can be reduced to only message_set_{start,sep,end}\r
71 > and part, most of show_message can be deleted, and all of\r
72 > show-message.c can be deleted.\r
73 \r
74 LGTM\r
75 \r
76 Regards,\r
77   Dmitry\r
78 \r
79 > ---\r
80 >  notmuch-client.h |    6 ++++++\r
81 >  notmuch-reply.c  |    2 +-\r
82 >  notmuch-show.c   |   21 +++++++++++++++++----\r
83 >  3 files changed, 24 insertions(+), 5 deletions(-)\r
84\r
85 > diff --git a/notmuch-client.h b/notmuch-client.h\r
86 > index abfe5d3..093c789 100644\r
87 > --- a/notmuch-client.h\r
88 > +++ b/notmuch-client.h\r
89 > @@ -62,8 +62,14 @@\r
90 >  #define STRINGIFY(s) STRINGIFY_(s)\r
91 >  #define STRINGIFY_(s) #s\r
92 >  \r
93 > +struct mime_node;\r
94 > +struct notmuch_show_params;\r
95 > +\r
96 >  typedef struct notmuch_show_format {\r
97 >      const char *message_set_start;\r
98 > +    void (*part) (const void *ctx,\r
99 > +               struct mime_node *node, int indent,\r
100 > +               const struct notmuch_show_params *params);\r
101 >      const char *message_start;\r
102 >      void (*message) (const void *ctx,\r
103 >                    notmuch_message_t *message,\r
104 > diff --git a/notmuch-reply.c b/notmuch-reply.c\r
105 > index bf67960..f55b1d2 100644\r
106 > --- a/notmuch-reply.c\r
107 > +++ b/notmuch-reply.c\r
108 > @@ -31,7 +31,7 @@ static void\r
109 >  reply_part_content (GMimeObject *part);\r
110 >  \r
111 >  static const notmuch_show_format_t format_reply = {\r
112 > -    "",\r
113 > +    "", NULL,\r
114 >       "", NULL,\r
115 >           "", NULL, reply_headers_message_part, ">\n",\r
116 >           "",\r
117 > diff --git a/notmuch-show.c b/notmuch-show.c\r
118 > index 682aa71..dec799c 100644\r
119 > --- a/notmuch-show.c\r
120 > +++ b/notmuch-show.c\r
121 > @@ -42,7 +42,7 @@ static void\r
122 >  format_part_end_text (GMimeObject *part);\r
123 >  \r
124 >  static const notmuch_show_format_t format_text = {\r
125 > -    "",\r
126 > +    "", NULL,\r
127 >       "\fmessage{ ", format_message_text,\r
128 >           "\fheader{\n", format_headers_text, format_headers_message_part_text, "\fheader}\n",\r
129 >           "\fbody{\n",\r
130 > @@ -89,7 +89,7 @@ static void\r
131 >  format_part_end_json (GMimeObject *part);\r
132 >  \r
133 >  static const notmuch_show_format_t format_json = {\r
134 > -    "[",\r
135 > +    "[", NULL,\r
136 >       "{", format_message_json,\r
137 >           "\"headers\": {", format_headers_json, format_headers_message_part_json, "}",\r
138 >           ", \"body\": [",\r
139 > @@ -110,7 +110,7 @@ format_message_mbox (const void *ctx,\r
140 >                    unused (int indent));\r
141 >  \r
142 >  static const notmuch_show_format_t format_mbox = {\r
143 > -    "",\r
144 > +    "", NULL,\r
145 >          "", format_message_mbox,\r
146 >              "", NULL, NULL, "",\r
147 >              "",\r
148 > @@ -129,7 +129,7 @@ static void\r
149 >  format_part_content_raw (GMimeObject *part);\r
150 >  \r
151 >  static const notmuch_show_format_t format_raw = {\r
152 > -    "",\r
153 > +    "", NULL,\r
154 >       "", NULL,\r
155 >           "", NULL, format_headers_message_part_text, "\n",\r
156 >              "",\r
157 > @@ -850,6 +850,19 @@ show_message (void *ctx,\r
158 >             int indent,\r
159 >             notmuch_show_params_t *params)\r
160 >  {\r
161 > +    if (format->part) {\r
162 > +     void *local = talloc_new (ctx);\r
163 > +     mime_node_t *root, *part;\r
164 > +\r
165 > +     if (mime_node_open (local, message, params->cryptoctx, params->decrypt,\r
166 > +                         &root) == NOTMUCH_STATUS_SUCCESS &&\r
167 > +         (part = mime_node_seek_dfs (root, (params->part < 0 ?\r
168 > +                                            0 : params->part))))\r
169 > +         format->part (local, part, indent, params);\r
170 > +     talloc_free (local);\r
171 > +     return;\r
172 > +    }\r
173 > +\r
174 >      if (params->part <= 0) {\r
175 >       fputs (format->message_start, stdout);\r
176 >       if (format->message)\r
177 > -- \r
178 > 1.7.7.3\r
179\r