mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-21 18:38:08 +01:00
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.
This commit is contained in:
parent
d2177d0b22
commit
6c2417cabc
4 changed files with 17 additions and 21 deletions
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)));
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue