Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / d0 / 223210aa00a2869a236639a497b5fcf3781a7d
1 Return-Path: <bremner@pivot.cs.unb.ca>\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 96BEC431FC1\r
6         for <notmuch@notmuchmail.org>; Sat, 24 Apr 2010 04:45:39 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -1.9\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-1.9 tagged_above=-999 required=5\r
12         tests=[BAYES_00=-1.9] autolearn=ham\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 ENJNmvh24AYr for <notmuch@notmuchmail.org>;\r
16         Sat, 24 Apr 2010 04:45:37 -0700 (PDT)\r
17 Received: from pivot.cs.unb.ca (pivot.cs.unb.ca [131.202.240.57])\r
18         by olra.theworths.org (Postfix) with ESMTP id 3C37C414BAE\r
19         for <notmuch@notmuchmail.org>; Sat, 24 Apr 2010 04:45:35 -0700 (PDT)\r
20 Received: from\r
21         fctnnbsc30w-142167190087.pppoe-dynamic.high-speed.nb.bellaliant.net\r
22         ([142.167.190.87] helo=rocinante.cs.unb.ca)\r
23         by pivot.cs.unb.ca with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32)\r
24         (Exim 4.69) (envelope-from <bremner@pivot.cs.unb.ca>)\r
25         id 1O5dni-00030n-Mq; Sat, 24 Apr 2010 08:45:34 -0300\r
26 Received: from bremner by rocinante.cs.unb.ca with local (Exim 4.71)\r
27         (envelope-from <bremner@rocinante.cs.unb.ca>)\r
28         id 1O5dnB-0005Qo-Ku; Sat, 24 Apr 2010 08:45:01 -0300\r
29 From: david@tethera.net\r
30 To: notmuch@notmuchmail.org\r
31 Subject: [PATCH 3/3] notmuch-show.c: control which headers are show for json\r
32         output.\r
33 Date: Sat, 24 Apr 2010 08:44:38 -0300\r
34 Message-Id: <1272109478-20686-4-git-send-email-david@tethera.net>\r
35 X-Mailer: git-send-email 1.7.0\r
36 In-Reply-To: <1272109478-20686-1-git-send-email-david@tethera.net>\r
37 References: <1272109478-20686-1-git-send-email-david@tethera.net>\r
38 X-Sender-Verified: bremner@pivot.cs.unb.ca\r
39 Cc: David Bremner <bremner@unb.ca>\r
40 X-BeenThere: notmuch@notmuchmail.org\r
41 X-Mailman-Version: 2.1.13\r
42 Precedence: list\r
43 List-Id: "Use and development of the notmuch mail system."\r
44         <notmuch.notmuchmail.org>\r
45 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
46         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
47 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
48 List-Post: <mailto:notmuch@notmuchmail.org>\r
49 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
50 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
51         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
52 X-List-Received-Date: Sat, 24 Apr 2010 11:45:39 -0000\r
53 \r
54 From: David Bremner <bremner@unb.ca>\r
55 \r
56 This commit adds argument handling from and callbacks to\r
57 notmuch-output.c to determine what headers to show in json output.\r
58 This requires passing a pointer to a struct containing the output\r
59 parameters into several functions, and in particular changes the type of\r
60 the function pointers in the show_format structure.\r
61 ---\r
62  notmuch-show.c |   81 ++++++++++++++++++++++++++++++++++++++------------------\r
63  1 files changed, 55 insertions(+), 26 deletions(-)\r
64 \r
65 diff --git a/notmuch-show.c b/notmuch-show.c\r
66 index 6aa9072..29e2819 100644\r
67 --- a/notmuch-show.c\r
68 +++ b/notmuch-show.c\r
69 @@ -19,6 +19,7 @@\r
70   */\r
71  \r
72  #include "notmuch-client.h"\r
73 +#include "notmuch-output.h"\r
74  \r
75  typedef struct show_format {\r
76      const char *message_set_start;\r
77 @@ -28,6 +29,7 @@ typedef struct show_format {\r
78                      int indent);\r
79      const char *header_start;\r
80      void (*header) (const void *ctx,\r
81 +                   notmuch_output_options_t *output_opts,\r
82                     notmuch_message_t *message);\r
83      const char *header_end;\r
84      const char *body_start;\r
85 @@ -45,6 +47,7 @@ format_message_text (unused (const void *ctx),\r
86                      int indent);\r
87  static void\r
88  format_headers_text (const void *ctx,\r
89 +                    notmuch_output_options_t *opts,\r
90                      notmuch_message_t *message);\r
91  static void\r
92  format_part_text (GMimeObject *part,\r
93 @@ -64,6 +67,7 @@ format_message_json (const void *ctx,\r
94                      unused (int indent));\r
95  static void\r
96  format_headers_json (const void *ctx,\r
97 +                    unused (notmuch_output_options_t *opts),\r
98                      notmuch_message_t *message);\r
99  static void\r
100  format_part_json (GMimeObject *part,\r
101 @@ -164,7 +168,9 @@ format_message_json (const void *ctx, notmuch_message_t *message, unused (int in\r
102  }\r
103  \r
104  static void\r
105 -format_headers_text (const void *ctx, notmuch_message_t *message)\r
106 +format_headers_text (const void *ctx,\r
107 +                    unused (notmuch_output_options_t *opts),\r
108 +                    notmuch_message_t *message)\r
109  {\r
110      const char *headers[] = {\r
111         "Subject", "From", "To", "Cc", "Bcc", "Date"\r
112 @@ -183,28 +189,38 @@ format_headers_text (const void *ctx, notmuch_message_t *message)\r
113  }\r
114  \r
115  static void\r
116 -format_headers_json (const void *ctx, notmuch_message_t *message)\r
117 +format_headers_json (const void *ctx,\r
118 +                    notmuch_output_options_t *output_opts,\r
119 +                    notmuch_message_t *message)\r
120  {\r
121 -    const char *headers[] = {\r
122 -       "Subject", "From", "To", "Cc", "Bcc", "Date"\r
123 +    const struct { const char *name; notmuch_output_t key; } headers[] = {\r
124 +       { "Subject", NOTMUCH_OUTPUT_SUBJECT},\r
125 +       { "From", NOTMUCH_OUTPUT_FROM},\r
126 +       { "To", NOTMUCH_OUTPUT_TO},\r
127 +       { "Cc", NOTMUCH_OUTPUT_TO},\r
128 +       { "Bcc", NOTMUCH_OUTPUT_BCC },\r
129 +       { "Date",       NOTMUCH_OUTPUT_DATE}\r
130      };\r
131 +\r
132      const char *name, *value;\r
133      unsigned int i;\r
134      int first_header = 1;\r
135      void *ctx_quote = talloc_new (ctx);\r
136  \r
137      for (i = 0; i < ARRAY_SIZE (headers); i++) {\r
138 -       name = headers[i];\r
139 -       value = notmuch_message_get_header (message, name);\r
140 -       if (value)\r
141 -       {\r
142 -           if (!first_header)\r
143 -               fputs (", ", stdout);\r
144 -           first_header = 0;\r
145 -\r
146 -           printf ("%s: %s",\r
147 -                   json_quote_str (ctx_quote, name),\r
148 -                   json_quote_str (ctx_quote, value));\r
149 +       if (output_get_flag(output_opts,headers[i].key)) {\r
150 +           name = headers[i].name;\r
151 +           value = notmuch_message_get_header (message, name);\r
152 +           if (value)\r
153 +           {\r
154 +               if (!first_header)\r
155 +                   fputs (", ", stdout);\r
156 +               first_header = 0;\r
157 +\r
158 +               printf ("%s: %s",\r
159 +                       json_quote_str (ctx_quote, name),\r
160 +                       json_quote_str (ctx_quote, value));\r
161 +           }\r
162         }\r
163      }\r
164  \r
165 @@ -337,7 +353,9 @@ format_part_json (GMimeObject *part, int *part_count)\r
166  }\r
167  \r
168  static void\r
169 -show_message (void *ctx, const show_format_t *format, notmuch_message_t *message, int indent)\r
170 +show_message (void *ctx, const show_format_t *format,\r
171 +             notmuch_output_options_t *output_options,\r
172 +             notmuch_message_t *message, int indent)\r
173  {\r
174      fputs (format->message_start, stdout);\r
175      if (format->message)\r
176 @@ -345,20 +363,24 @@ show_message (void *ctx, const show_format_t *format, notmuch_message_t *message\r
177  \r
178      fputs (format->header_start, stdout);\r
179      if (format->header)\r
180 -       format->header(ctx, message);\r
181 +       format->header(ctx, output_options, message);\r
182      fputs (format->header_end, stdout);\r
183  \r
184 -    fputs (format->body_start, stdout);\r
185 -    if (format->part)\r
186 -       show_message_body (notmuch_message_get_filename (message), format->part);\r
187 -    fputs (format->body_end, stdout);\r
188 +    if (output_get_flag(output_options, NOTMUCH_OUTPUT_BODY)){\r
189 +       fputs (format->body_start, stdout);\r
190 +       if (format->part)\r
191 +           show_message_body (notmuch_message_get_filename (message), format->part);\r
192 +       fputs (format->body_end, stdout);\r
193 +    }\r
194  \r
195      fputs (format->message_end, stdout);\r
196  }\r
197  \r
198  \r
199  static void\r
200 -show_messages (void *ctx, const show_format_t *format, notmuch_messages_t *messages, int indent,\r
201 +show_messages (void *ctx, const show_format_t *format,\r
202 +              notmuch_output_options_t *output_opts,\r
203 +              notmuch_messages_t *messages, int indent,\r
204                notmuch_bool_t entire_thread)\r
205  {\r
206      notmuch_message_t *message;\r
207 @@ -385,13 +407,14 @@ show_messages (void *ctx, const show_format_t *format, notmuch_messages_t *messa\r
208         next_indent = indent;\r
209  \r
210         if (match || entire_thread) {\r
211 -           show_message (ctx, format, message, indent);\r
212 +           show_message (ctx, format, output_opts, message, indent);\r
213             next_indent = indent + 1;\r
214  \r
215             fputs (format->message_set_sep, stdout);\r
216         }\r
217  \r
218 -       show_messages (ctx, format, notmuch_message_get_replies (message),\r
219 +       show_messages (ctx, format, output_opts,\r
220 +                      notmuch_message_get_replies (message),\r
221                        next_indent, entire_thread);\r
222  \r
223         notmuch_message_destroy (message);\r
224 @@ -411,6 +434,7 @@ notmuch_show_command (void *ctx, int argc, char *argv[])\r
225      notmuch_threads_t *threads;\r
226      notmuch_thread_t *thread;\r
227      notmuch_messages_t *messages;\r
228 +    notmuch_output_options_t *output_opts;\r
229      char *query_string;\r
230      char *opt;\r
231      const show_format_t *format = &format_text;\r
232 @@ -418,12 +442,17 @@ notmuch_show_command (void *ctx, int argc, char *argv[])\r
233      int i;\r
234      int first_toplevel = 1;\r
235  \r
236 +    output_opts = output_init(ctx);\r
237 +\r
238      for (i = 0; i < argc && argv[i][0] == '-'; i++) {\r
239         if (strcmp (argv[i], "--") == 0) {\r
240             i++;\r
241             break;\r
242         }\r
243 -       if (STRNCMP_LITERAL (argv[i], "--format=") == 0) {\r
244 +       if (STRNCMP_LITERAL (argv[i], "--output=") == 0) {\r
245 +         if(output_parse_arg(output_opts, argv[i]))\r
246 +           return 1;\r
247 +       } else if (STRNCMP_LITERAL (argv[i], "--format=") == 0) {\r
248             opt = argv[i] + sizeof ("--format=") - 1;\r
249             if (strcmp (opt, "text") == 0) {\r
250                 format = &format_text;\r
251 @@ -489,7 +518,7 @@ notmuch_show_command (void *ctx, int argc, char *argv[])\r
252             fputs (format->message_set_sep, stdout);\r
253         first_toplevel = 0;\r
254  \r
255 -       show_messages (ctx, format, messages, 0, entire_thread);\r
256 +       show_messages (ctx, format, output_opts, messages, 0, entire_thread);\r
257  \r
258         notmuch_thread_destroy (thread);\r
259  \r
260 -- \r
261 1.7.0\r
262 \r