[Patch v2] Minor correction to devel/schemata
[notmuch-archives.git] / 82 / 806f869058198eb44f98925a36fce0fae4d656
1 Return-Path: <jrollins@servo.finestructure.net>\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 B632D429E28\r
6         for <notmuch@notmuchmail.org>; Sun,  5 Jun 2011 17:29:38 -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.921\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-1.921 tagged_above=-999 required=5\r
12         tests=[NO_DNS_FOR_FROM=0.379, RCVD_IN_DNSWL_MED=-2.3]\r
13         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 huZ8Ajs5wmgg for <notmuch@notmuchmail.org>;\r
17         Sun,  5 Jun 2011 17:29:38 -0700 (PDT)\r
18 Received: from outgoing-mail.its.caltech.edu (outgoing-mail.its.caltech.edu\r
19         [131.215.239.19])\r
20         by olra.theworths.org (Postfix) with ESMTP id C3E0C429E25\r
21         for <notmuch@notmuchmail.org>; Sun,  5 Jun 2011 17:29:37 -0700 (PDT)\r
22 Received: from earth-doxen.imss.caltech.edu (localhost [127.0.0.1])\r
23         by earth-doxen-postvirus (Postfix) with ESMTP id 1201A66E02C4;\r
24         Sun,  5 Jun 2011 17:29:36 -0700 (PDT)\r
25 X-Spam-Scanned: at Caltech-IMSS on earth-doxen by amavisd-new\r
26 Received: from servo.finestructure.net (cpe-98-149-172-122.socal.res.rr.com\r
27         [98.149.172.122]) (Authenticated sender: jrollins)\r
28         by earth-doxen-submit (Postfix) with ESMTP id A7D7D66E027D;\r
29         Sun,  5 Jun 2011 17:29:30 -0700 (PDT)\r
30 Received: by servo.finestructure.net (Postfix, from userid 1000)\r
31         id 23662AD8; Sun,  5 Jun 2011 17:29:31 -0700 (PDT)\r
32 From: Jameson Graef Rollins <jrollins@finestructure.net>\r
33 To: Notmuch Mail <notmuch@notmuchmail.org>\r
34 Subject: [PATCH 4/5] Improve handling of message/rfc822 parts by adding a new\r
35         header_message_part function to the formating structure.\r
36 Date: Sun,  5 Jun 2011 17:29:28 -0700\r
37 Message-Id: <1307320169-29905-5-git-send-email-jrollins@finestructure.net>\r
38 X-Mailer: git-send-email 1.7.4.4\r
39 In-Reply-To: <1307320169-29905-4-git-send-email-jrollins@finestructure.net>\r
40 References: <87sjrsi2b4.fsf@servo.factory.finestructure.net>\r
41         <1307320169-29905-1-git-send-email-jrollins@finestructure.net>\r
42         <1307320169-29905-2-git-send-email-jrollins@finestructure.net>\r
43         <1307320169-29905-3-git-send-email-jrollins@finestructure.net>\r
44         <1307320169-29905-4-git-send-email-jrollins@finestructure.net>\r
45 X-BeenThere: notmuch@notmuchmail.org\r
46 X-Mailman-Version: 2.1.13\r
47 Precedence: list\r
48 List-Id: "Use and development of the notmuch mail system."\r
49         <notmuch.notmuchmail.org>\r
50 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
51         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
52 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
53 List-Post: <mailto:notmuch@notmuchmail.org>\r
54 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
55 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
56         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
57 X-List-Received-Date: Mon, 06 Jun 2011 00:29:38 -0000\r
58 \r
59 This new function takes a GMimeMessage as input, and outputs the\r
60 formatted headers.  This allows for message/rfc822 parts to be\r
61 formatted on output in a similar way to full messages (see previous\r
62 patch that overhauls the multipart test for more info).\r
63 ---\r
64  notmuch-client.h |    1 +\r
65  notmuch-reply.c  |   31 ++++++++++++++++++-\r
66  notmuch-show.c   |   88 ++++++++++++++++++++++++++++++++++++++++++++++-------\r
67  show-message.c   |   12 +++++++\r
68  4 files changed, 119 insertions(+), 13 deletions(-)\r
69 \r
70 diff --git a/notmuch-client.h b/notmuch-client.h\r
71 index 63be337..b50cb38 100644\r
72 --- a/notmuch-client.h\r
73 +++ b/notmuch-client.h\r
74 @@ -63,6 +63,7 @@ typedef struct notmuch_show_format {\r
75      const char *header_start;\r
76      void (*header) (const void *ctx,\r
77                     notmuch_message_t *message);\r
78 +    void (*header_message_part) (GMimeMessage *message);\r
79      const char *header_end;\r
80      const char *body_start;\r
81      void (*part_start) (GMimeObject *part,\r
82 diff --git a/notmuch-reply.c b/notmuch-reply.c\r
83 index 514bbc6..a19eb19 100644\r
84 --- a/notmuch-reply.c\r
85 +++ b/notmuch-reply.c\r
86 @@ -25,12 +25,15 @@\r
87  #include "gmime-filter-headers.h"\r
88  \r
89  static void\r
90 +reply_headers_message_part (GMimeMessage *message);\r
91 +\r
92 +static void\r
93  reply_part_content (GMimeObject *part);\r
94  \r
95  static const notmuch_show_format_t format_reply = {\r
96      "",\r
97         "", NULL,\r
98 -           "", NULL, "",\r
99 +           "", NULL, reply_headers_message_part, ">\n",\r
100             "",\r
101                 NULL,\r
102                 NULL,\r
103 @@ -63,6 +66,28 @@ show_reply_headers (GMimeMessage *message)\r
104  }\r
105  \r
106  static void\r
107 +reply_headers_message_part (GMimeMessage *message)\r
108 +{\r
109 +    InternetAddressList *recipients;\r
110 +    const char *recipients_string;\r
111 +\r
112 +    printf ("> From: %s\n", g_mime_message_get_sender (message));\r
113 +    recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_TO);\r
114 +    recipients_string = internet_address_list_to_string (recipients, 0);\r
115 +    if (recipients_string)\r
116 +       printf ("> To: %s\n",\r
117 +               recipients_string);\r
118 +    recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_CC);\r
119 +    recipients_string = internet_address_list_to_string (recipients, 0);\r
120 +    if (recipients_string)\r
121 +       printf ("> Cc: %s\n",\r
122 +               recipients_string);\r
123 +    printf ("> Subject: %s\n", g_mime_message_get_subject (message));\r
124 +    printf ("> Date: %s\n", g_mime_message_get_date_as_string (message));\r
125 +}\r
126 +\r
127 +\r
128 +static void\r
129  reply_part_content (GMimeObject *part)\r
130  {\r
131      GMimeContentType *content_type = g_mime_object_get_content_type (GMIME_OBJECT (part));\r
132 @@ -95,6 +120,10 @@ reply_part_content (GMimeObject *part)\r
133         if (stream_stdout)\r
134             g_object_unref(stream_stdout);\r
135      }\r
136 +    else if (g_mime_content_type_is_type (content_type, "message", "rfc822"))\r
137 +    {\r
138 +       /* Output nothing, since rfc822 subparts will be handled individually. */\r
139 +    }\r
140      else\r
141      {\r
142         if (disposition &&\r
143 diff --git a/notmuch-show.c b/notmuch-show.c\r
144 index 0e9d00d..6e2e560 100644\r
145 --- a/notmuch-show.c\r
146 +++ b/notmuch-show.c\r
147 @@ -29,6 +29,9 @@ format_headers_text (const void *ctx,\r
148                      notmuch_message_t *message);\r
149  \r
150  static void\r
151 +format_headers_message_part_text (GMimeMessage *message);\r
152 +\r
153 +static void\r
154  format_part_start_text (GMimeObject *part,\r
155                         int *part_count);\r
156  \r
157 @@ -41,7 +44,7 @@ format_part_end_text (GMimeObject *part);\r
158  static const notmuch_show_format_t format_text = {\r
159      "",\r
160         "\fmessage{ ", format_message_text,\r
161 -           "\fheader{\n", format_headers_text, "\fheader}\n",\r
162 +           "\fheader{\n", format_headers_text, format_headers_message_part_text, "\fheader}\n",\r
163             "\fbody{\n",\r
164                 format_part_start_text,\r
165                 NULL,\r
166 @@ -63,6 +66,9 @@ format_headers_json (const void *ctx,\r
167                      notmuch_message_t *message);\r
168  \r
169  static void\r
170 +format_headers_message_part_json (GMimeMessage *message);\r
171 +\r
172 +static void\r
173  format_part_start_json (unused (GMimeObject *part),\r
174                         int *part_count);\r
175  \r
176 @@ -81,7 +87,7 @@ format_part_end_json (GMimeObject *part);\r
177  static const notmuch_show_format_t format_json = {\r
178      "[",\r
179         "{", format_message_json,\r
180 -           ", \"headers\": {", format_headers_json, "}",\r
181 +           "\"headers\": {", format_headers_json, format_headers_message_part_json, "}",\r
182             ", \"body\": [",\r
183                 format_part_start_json,\r
184                 format_part_encstatus_json,\r
185 @@ -102,7 +108,7 @@ format_message_mbox (const void *ctx,\r
186  static const notmuch_show_format_t format_mbox = {\r
187      "",\r
188          "", format_message_mbox,\r
189 -            "", NULL, "",\r
190 +            "", NULL, NULL, "",\r
191              "",\r
192                  NULL,\r
193                  NULL,\r
194 @@ -121,7 +127,7 @@ format_part_content_raw (GMimeObject *part);\r
195  static const notmuch_show_format_t format_raw = {\r
196      "",\r
197         "", NULL,\r
198 -           "", NULL, "",\r
199 +           "", NULL, format_headers_message_part_text, "\n",\r
200              "",\r
201                  NULL,\r
202                  NULL,\r
203 @@ -216,7 +222,7 @@ format_message_json (const void *ctx, notmuch_message_t *message, unused (int in\r
204                 json_quote_str (ctx_quote, notmuch_tags_get (tags)));\r
205           first = 0;\r
206      }\r
207 -    printf("]");\r
208 +    printf("], ");\r
209      talloc_free (ctx_quote);\r
210  }\r
211  \r
212 @@ -326,6 +332,7 @@ format_message_mbox (const void *ctx,\r
213      fclose (file);\r
214  }\r
215  \r
216 +\r
217  static void\r
218  format_headers_text (const void *ctx, notmuch_message_t *message)\r
219  {\r
220 @@ -346,6 +353,27 @@ format_headers_text (const void *ctx, notmuch_message_t *message)\r
221  }\r
222  \r
223  static void\r
224 +format_headers_message_part_text (GMimeMessage *message)\r
225 +{\r
226 +    InternetAddressList *recipients;\r
227 +    const char *recipients_string;\r
228 +\r
229 +    printf ("From: %s\n", g_mime_message_get_sender (message));\r
230 +    recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_TO);\r
231 +    recipients_string = internet_address_list_to_string (recipients, 0);\r
232 +    if (recipients_string)\r
233 +       printf ("To: %s\n",\r
234 +               recipients_string);\r
235 +    recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_CC);\r
236 +    recipients_string = internet_address_list_to_string (recipients, 0);\r
237 +    if (recipients_string)\r
238 +       printf ("Cc: %s\n",\r
239 +               recipients_string);\r
240 +    printf ("Subject: %s\n", g_mime_message_get_subject (message));\r
241 +    printf ("Date: %s\n", g_mime_message_get_date_as_string (message));\r
242 +}\r
243 +\r
244 +static void\r
245  format_headers_json (const void *ctx, notmuch_message_t *message)\r
246  {\r
247      const char *headers[] = {\r
248 @@ -374,6 +402,40 @@ format_headers_json (const void *ctx, notmuch_message_t *message)\r
249      talloc_free (ctx_quote);\r
250  }\r
251  \r
252 +static void\r
253 +format_headers_message_part_json (GMimeMessage *message)\r
254 +{\r
255 +    void *ctx = talloc_new (NULL);\r
256 +    void *ctx_quote = talloc_new (ctx);\r
257 +    InternetAddressList *recipients;\r
258 +    const char *recipients_string;\r
259 +\r
260 +    printf ("%s: %s",\r
261 +           json_quote_str (ctx_quote, "From"),\r
262 +           json_quote_str (ctx_quote, g_mime_message_get_sender (message)));\r
263 +    recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_TO);\r
264 +    recipients_string = internet_address_list_to_string (recipients, 0);\r
265 +    if (recipients_string)\r
266 +       printf (", %s: %s",\r
267 +               json_quote_str (ctx_quote, "To"),\r
268 +               json_quote_str (ctx_quote, recipients_string));\r
269 +    recipients = g_mime_message_get_recipients (message, GMIME_RECIPIENT_TYPE_CC);\r
270 +    recipients_string = internet_address_list_to_string (recipients, 0);\r
271 +    if (recipients_string)\r
272 +       printf (", %s: %s",\r
273 +               json_quote_str (ctx_quote, "Cc"),\r
274 +               json_quote_str (ctx_quote, recipients_string));\r
275 +    printf (", %s: %s",\r
276 +           json_quote_str (ctx_quote, "Subject"),\r
277 +           json_quote_str (ctx_quote, g_mime_message_get_subject (message)));\r
278 +    printf (", %s: %s",\r
279 +           json_quote_str (ctx_quote, "Date"),\r
280 +           json_quote_str (ctx_quote, g_mime_message_get_date_as_string (message)));\r
281 +\r
282 +    talloc_free (ctx_quote);\r
283 +    talloc_free (ctx);\r
284 +}\r
285 +\r
286  /* Write a MIME text part out to the given stream.\r
287   *\r
288   * Both line-ending conversion (CRLF->LF) and charset conversion ( ->\r
289 @@ -616,11 +678,14 @@ format_part_content_json (GMimeObject *part)\r
290  \r
291         printf (", \"content\": %s", json_quote_chararray (ctx, (char *) part_content->data, part_content->len));\r
292      }\r
293 -    else if (g_mime_content_type_is_type (content_type, "multipart", "*") ||\r
294 -            g_mime_content_type_is_type (content_type, "message", "rfc822"))\r
295 +    else if (g_mime_content_type_is_type (content_type, "multipart", "*"))\r
296      {\r
297         printf (", \"content\": [");\r
298      }\r
299 +    else if (g_mime_content_type_is_type (content_type, "message", "rfc822"))\r
300 +    {\r
301 +       printf (", \"content\": [{");\r
302 +    }\r
303  \r
304      talloc_free (ctx);\r
305      if (stream_memory)\r
306 @@ -630,13 +695,12 @@ format_part_content_json (GMimeObject *part)\r
307  static void\r
308  format_part_end_json (GMimeObject *part)\r
309  {\r
310 -    GMimeContentType *content_type;\r
311 -\r
312 -    content_type = g_mime_object_get_content_type (GMIME_OBJECT (part));\r
313 +    GMimeContentType *content_type = g_mime_object_get_content_type (GMIME_OBJECT (part));\r
314  \r
315 -    if (g_mime_content_type_is_type (content_type, "multipart", "*") ||\r
316 -       g_mime_content_type_is_type (content_type, "message", "rfc822"))\r
317 +    if (g_mime_content_type_is_type (content_type, "multipart", "*"))\r
318         printf ("]");\r
319 +    else if (g_mime_content_type_is_type (content_type, "message", "rfc822"))\r
320 +       printf ("}]");\r
321  \r
322      printf ("}");\r
323  }\r
324 diff --git a/show-message.c b/show-message.c\r
325 index 7a4bbc2..d83f04e 100644\r
326 --- a/show-message.c\r
327 +++ b/show-message.c\r
328 @@ -149,9 +149,21 @@ show_message_part (GMimeObject *part,\r
329         if (selected)\r
330             state->in_zone = 1;\r
331  \r
332 +       if (selected || (!selected && state->in_zone)) {\r
333 +           fputs (format->header_start, stdout);\r
334 +           if (format->header_message_part)\r
335 +               format->header_message_part (mime_message);\r
336 +           fputs (format->header_end, stdout);\r
337 +\r
338 +           fputs (format->body_start, stdout);\r
339 +       }\r
340 +\r
341         show_message_part (g_mime_message_get_mime_part (mime_message),\r
342                            state, format, params, TRUE);\r
343  \r
344 +       if (selected || (!selected && state->in_zone))\r
345 +           fputs (format->body_end, stdout);\r
346 +\r
347         if (selected)\r
348             state->in_zone = 0;\r
349      }\r
350 -- \r
351 1.7.4.4\r
352 \r