diff options
author | Jameson Graef Rollins <jrollins@finestructure.net> | 2011-05-22 19:56:53 -0700 |
---|---|---|
committer | Carl Worth <cworth@cworth.org> | 2011-05-23 14:55:27 -0700 |
commit | 6c2417cabc1b35ea4fc9db6493d85354b1039d6d (patch) | |
tree | 2294ff3d2ad52b12cb657966d984c29b0acd89c0 | |
parent | d2177d0b22a95989dee4f46a1b2cca68484a2ce3 (diff) |
add part_sep formatter to replace "first" argument to part format functions
A new field "part_sep" is added to the notmuch_show_format structure,
to be used for part separation. This is cleaner than the "first"
argument that was being passed around to the part arguments, and
allows the function that handles overall part output formatting
(show_message_part) to directly handle when outputting the separator.
-rw-r--r-- | notmuch-client.h | 4 | ||||
-rw-r--r-- | notmuch-reply.c | 8 | ||||
-rw-r--r-- | notmuch-show.c | 19 | ||||
-rw-r--r-- | show-message.c | 7 |
4 files changed, 17 insertions, 21 deletions
diff --git a/notmuch-client.h b/notmuch-client.h index 8899ab2..5e8e3e5 100644 --- a/notmuch-client.h +++ b/notmuch-client.h @@ -66,9 +66,9 @@ typedef struct notmuch_show_format { const char *header_end; const char *body_start; void (*part) (GMimeObject *part, - int *part_count, - int first); + int *part_count); void (*part_end) (GMimeObject *part); + const char *part_sep; const char *body_end; const char *message_end; const char *message_set_sep; diff --git a/notmuch-reply.c b/notmuch-reply.c index 064d27e..b5ca19c 100644 --- a/notmuch-reply.c +++ b/notmuch-reply.c @@ -26,14 +26,13 @@ static void reply_part (GMimeObject *part, - unused (int *part_count), - unused (int first)); + unused (int *part_count)); static const notmuch_show_format_t format_reply = { NULL, NULL, NULL, NULL, NULL, NULL, - NULL, reply_part, NULL, NULL, + NULL, reply_part, NULL, NULL, NULL, NULL, NULL, NULL }; @@ -87,8 +86,7 @@ show_reply_headers (GMimeMessage *message) static void reply_part (GMimeObject *part, - unused (int *part_count), - unused (int first)) + unused (int *part_count)) { GMimeContentDisposition *disposition; GMimeContentType *content_type; diff --git a/notmuch-show.c b/notmuch-show.c index 006ccf9..412f908 100644 --- a/notmuch-show.c +++ b/notmuch-show.c @@ -30,8 +30,7 @@ format_headers_text (const void *ctx, static void format_part_text (GMimeObject *part, - int *part_count, - int first); + int *part_count); static void format_part_end_text (GMimeObject *part); @@ -40,7 +39,7 @@ static const notmuch_show_format_t format_text = { "", "\fmessage{ ", format_message_text, "\fheader{\n", format_headers_text, "\fheader}\n", - "\fbody{\n", format_part_text, format_part_end_text, "\fbody}\n", + "\fbody{\n", format_part_text, format_part_end_text, "", "\fbody}\n", "\fmessage}\n", "", "" }; @@ -55,8 +54,7 @@ format_headers_json (const void *ctx, static void format_part_json (GMimeObject *part, - int *part_count, - int first); + int *part_count); static void format_part_end_json (GMimeObject *part); @@ -65,7 +63,7 @@ static const notmuch_show_format_t format_json = { "[", "{", format_message_json, ", \"headers\": {", format_headers_json, "}", - ", \"body\": [", format_part_json, format_part_end_json, "]", + ", \"body\": [", format_part_json, format_part_end_json, ", ", "]", "}", ", ", "]" }; @@ -79,7 +77,7 @@ static const notmuch_show_format_t format_mbox = { "", "", format_message_mbox, "", NULL, "", - "", NULL, NULL, "", + "", NULL, NULL, "", "", "", "", "" }; @@ -357,7 +355,7 @@ show_part_content (GMimeObject *part, GMimeStream *stream_out) } static void -format_part_text (GMimeObject *part, int *part_count, unused (int first)) +format_part_text (GMimeObject *part, int *part_count) { GMimeContentDisposition *disposition; GMimeContentType *content_type; @@ -431,7 +429,7 @@ format_part_end_text (GMimeObject *part) } static void -format_part_json (GMimeObject *part, int *part_count, int first) +format_part_json (GMimeObject *part, int *part_count) { GMimeContentType *content_type; GMimeContentDisposition *disposition; @@ -442,9 +440,6 @@ format_part_json (GMimeObject *part, int *part_count, int first) content_type = g_mime_object_get_content_type (GMIME_OBJECT (part)); - if (! first) - fputs (", ", stdout); - printf ("{\"id\": %d, \"content-type\": %s", *part_count, json_quote_str (ctx, g_mime_content_type_to_string (content_type))); diff --git a/show-message.c b/show-message.c index 3c29f26..c5556d8 100644 --- a/show-message.c +++ b/show-message.c @@ -28,12 +28,15 @@ show_message_part (GMimeObject *part, const notmuch_show_format_t *format, int first) { + if (!first) + fputs (format->part_sep, stdout); + if (GMIME_IS_MULTIPART (part)) { GMimeMultipart *multipart = GMIME_MULTIPART (part); int i; *part_count = *part_count + 1; - format->part (part, part_count, first); + format->part (part, part_count); for (i = 0; i < g_mime_multipart_get_count (multipart); i++) { show_message_part (g_mime_multipart_get_part (multipart, i), @@ -65,7 +68,7 @@ show_message_part (GMimeObject *part, *part_count = *part_count + 1; - format->part (part, part_count, first); + format->part (part, part_count); if (format->part_end) format->part_end (part); } |