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
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
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
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
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
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
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
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
87 #include "gmime-filter-headers.h"
\r
90 +reply_headers_message_part (GMimeMessage *message);
\r
93 reply_part_content (GMimeObject *part);
\r
95 static const notmuch_show_format_t format_reply = {
\r
99 + "", NULL, reply_headers_message_part, ">\n",
\r
103 @@ -63,6 +66,28 @@ show_reply_headers (GMimeMessage *message)
\r
107 +reply_headers_message_part (GMimeMessage *message)
\r
109 + InternetAddressList *recipients;
\r
110 + const char *recipients_string;
\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
129 reply_part_content (GMimeObject *part)
\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
134 g_object_unref(stream_stdout);
\r
136 + else if (g_mime_content_type_is_type (content_type, "message", "rfc822"))
\r
138 + /* Output nothing, since rfc822 subparts will be handled individually. */
\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
151 +format_headers_message_part_text (GMimeMessage *message);
\r
154 format_part_start_text (GMimeObject *part,
\r
157 @@ -41,7 +44,7 @@ format_part_end_text (GMimeObject *part);
\r
158 static const notmuch_show_format_t format_text = {
\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
164 format_part_start_text,
\r
166 @@ -63,6 +66,9 @@ format_headers_json (const void *ctx,
\r
167 notmuch_message_t *message);
\r
170 +format_headers_message_part_json (GMimeMessage *message);
\r
173 format_part_start_json (unused (GMimeObject *part),
\r
176 @@ -81,7 +87,7 @@ format_part_end_json (GMimeObject *part);
\r
177 static const notmuch_show_format_t format_json = {
\r
179 "{", format_message_json,
\r
180 - ", \"headers\": {", format_headers_json, "}",
\r
181 + "\"headers\": {", format_headers_json, format_headers_message_part_json, "}",
\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
188 "", format_message_mbox,
\r
190 + "", NULL, NULL, "",
\r
194 @@ -121,7 +127,7 @@ format_part_content_raw (GMimeObject *part);
\r
195 static const notmuch_show_format_t format_raw = {
\r
199 + "", NULL, format_headers_message_part_text, "\n",
\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
209 talloc_free (ctx_quote);
\r
212 @@ -326,6 +332,7 @@ format_message_mbox (const void *ctx,
\r
218 format_headers_text (const void *ctx, notmuch_message_t *message)
\r
220 @@ -346,6 +353,27 @@ format_headers_text (const void *ctx, notmuch_message_t *message)
\r
224 +format_headers_message_part_text (GMimeMessage *message)
\r
226 + InternetAddressList *recipients;
\r
227 + const char *recipients_string;
\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
245 format_headers_json (const void *ctx, notmuch_message_t *message)
\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
253 +format_headers_message_part_json (GMimeMessage *message)
\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
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
282 + talloc_free (ctx_quote);
\r
283 + talloc_free (ctx);
\r
286 /* Write a MIME text part out to the given stream.
\r
288 * Both line-ending conversion (CRLF->LF) and charset conversion ( ->
\r
289 @@ -616,11 +678,14 @@ format_part_content_json (GMimeObject *part)
\r
291 printf (", \"content\": %s", json_quote_chararray (ctx, (char *) part_content->data, part_content->len));
\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
297 printf (", \"content\": [");
\r
299 + else if (g_mime_content_type_is_type (content_type, "message", "rfc822"))
\r
301 + printf (", \"content\": [{");
\r
306 @@ -630,13 +695,12 @@ format_part_content_json (GMimeObject *part)
\r
308 format_part_end_json (GMimeObject *part)
\r
310 - GMimeContentType *content_type;
\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
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
319 + else if (g_mime_content_type_is_type (content_type, "message", "rfc822"))
\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
330 state->in_zone = 1;
\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
338 + fputs (format->body_start, stdout);
\r
341 show_message_part (g_mime_message_get_mime_part (mime_message),
\r
342 state, format, params, TRUE);
\r
344 + if (selected || (!selected && state->in_zone))
\r
345 + fputs (format->body_end, stdout);
\r
348 state->in_zone = 0;
\r