show: Convert mbox format to new self-recursive style

Given the lack of recursion, this is pretty easy.
This commit is contained in:
Austin Clements 2012-03-06 18:48:41 +00:00 committed by David Bremner
parent 8d01b0749c
commit d431239353

View file

@ -45,25 +45,15 @@ static const notmuch_show_format_t format_json = {
.message_set_end = "]" .message_set_end = "]"
}; };
static void static notmuch_status_t
format_message_mbox (const void *ctx, format_part_mbox (const void *ctx, mime_node_t *node,
notmuch_message_t *message, int indent, const notmuch_show_params_t *params);
unused (int indent));
static const notmuch_show_format_t format_mbox = { static const notmuch_show_format_t format_mbox = {
"", NULL, .message_set_start = "",
"", format_message_mbox, .part = format_part_mbox,
"", NULL, NULL, "", .message_set_sep = "",
"", .message_set_end = ""
NULL,
NULL,
NULL,
NULL,
NULL,
"",
"",
"", "",
""
}; };
static void static void
@ -719,11 +709,12 @@ format_part_json_entry (const void *ctx, mime_node_t *node, unused (int indent),
* *
* http://qmail.org/qmail-manual-html/man5/mbox.html * http://qmail.org/qmail-manual-html/man5/mbox.html
*/ */
static void static notmuch_status_t
format_message_mbox (const void *ctx, format_part_mbox (const void *ctx, mime_node_t *node, unused (int indent),
notmuch_message_t *message, unused (const notmuch_show_params_t *params))
unused (int indent))
{ {
notmuch_message_t *message = node->envelope_file;
const char *filename; const char *filename;
FILE *file; FILE *file;
const char *from; const char *from;
@ -736,12 +727,15 @@ format_message_mbox (const void *ctx,
size_t line_size; size_t line_size;
ssize_t line_len; ssize_t line_len;
if (!message)
INTERNAL_ERROR ("format_part_mbox requires a root part");
filename = notmuch_message_get_filename (message); filename = notmuch_message_get_filename (message);
file = fopen (filename, "r"); file = fopen (filename, "r");
if (file == NULL) { if (file == NULL) {
fprintf (stderr, "Failed to open %s: %s\n", fprintf (stderr, "Failed to open %s: %s\n",
filename, strerror (errno)); filename, strerror (errno));
return; return NOTMUCH_STATUS_FILE_ERROR;
} }
from = notmuch_message_get_header (message, "from"); from = notmuch_message_get_header (message, "from");
@ -762,6 +756,8 @@ format_message_mbox (const void *ctx,
printf ("\n"); printf ("\n");
fclose (file); fclose (file);
return NOTMUCH_STATUS_SUCCESS;
} }
static notmuch_status_t static notmuch_status_t