Formatter errors are propagated to the exit status of notmuch show.
This isn't used by the JSON or text formatters, but it will be useful
for the raw format, which is pickier.
typedef struct notmuch_show_format {
const char *message_set_start;
typedef struct notmuch_show_format {
const char *message_set_start;
- void (*part) (const void *ctx,
- struct mime_node *node, int indent,
- const struct notmuch_show_params *params);
+ notmuch_status_t (*part) (const void *ctx,
+ struct mime_node *node, int indent,
+ const struct notmuch_show_params *params);
const char *message_start;
void (*message) (const void *ctx,
notmuch_message_t *message,
const char *message_start;
void (*message) (const void *ctx,
notmuch_message_t *message,
static void
format_headers_message_part_text (GMimeMessage *message);
static void
format_headers_message_part_text (GMimeMessage *message);
format_part_text (const void *ctx, mime_node_t *node,
int indent, const notmuch_show_params_t *params);
format_part_text (const void *ctx, mime_node_t *node,
int indent, const notmuch_show_params_t *params);
format_part_json_entry (const void *ctx, mime_node_t *node,
int indent, const notmuch_show_params_t *params);
format_part_json_entry (const void *ctx, mime_node_t *node,
int indent, const notmuch_show_params_t *params);
g_object_unref(stream_stdout);
}
g_object_unref(stream_stdout);
}
format_part_text (const void *ctx, mime_node_t *node,
int indent, const notmuch_show_params_t *params)
{
format_part_text (const void *ctx, mime_node_t *node,
int indent, const notmuch_show_params_t *params)
{
printf ("\fbody}\n");
printf ("\f%s}\n", part_type);
printf ("\fbody}\n");
printf ("\f%s}\n", part_type);
+
+ return NOTMUCH_STATUS_SUCCESS;
printf ("%s}", terminator);
}
printf ("%s}", terminator);
}
format_part_json_entry (const void *ctx, mime_node_t *node, unused (int indent),
unused (const notmuch_show_params_t *params))
{
format_part_json (ctx, node, TRUE);
format_part_json_entry (const void *ctx, mime_node_t *node, unused (int indent),
unused (const notmuch_show_params_t *params))
{
format_part_json (ctx, node, TRUE);
+
+ return NOTMUCH_STATUS_SUCCESS;
show_message (void *ctx,
const notmuch_show_format_t *format,
notmuch_message_t *message,
show_message (void *ctx,
const notmuch_show_format_t *format,
notmuch_message_t *message,
if (format->part) {
void *local = talloc_new (ctx);
mime_node_t *root, *part;
if (format->part) {
void *local = talloc_new (ctx);
mime_node_t *root, *part;
-
- if (mime_node_open (local, message, params->cryptoctx, params->decrypt,
- &root) == NOTMUCH_STATUS_SUCCESS &&
- (part = mime_node_seek_dfs (root, (params->part < 0 ?
- 0 : params->part))))
- format->part (local, part, indent, params);
+ notmuch_status_t status;
+
+ status = mime_node_open (local, message, params->cryptoctx,
+ params->decrypt, &root);
+ if (status)
+ goto DONE;
+ part = mime_node_seek_dfs (root, (params->part < 0 ? 0 : params->part));
+ if (part)
+ status = format->part (local, part, indent, params);
+ DONE:
}
if (params->part <= 0) {
}
if (params->part <= 0) {
fputs (format->message_end, stdout);
}
fputs (format->message_end, stdout);
}
+
+ return NOTMUCH_STATUS_SUCCESS;
show_messages (void *ctx,
const notmuch_show_format_t *format,
notmuch_messages_t *messages,
show_messages (void *ctx,
const notmuch_show_format_t *format,
notmuch_messages_t *messages,
notmuch_bool_t match;
int first_set = 1;
int next_indent;
notmuch_bool_t match;
int first_set = 1;
int next_indent;
+ notmuch_status_t status, res = NOTMUCH_STATUS_SUCCESS;
fputs (format->message_set_start, stdout);
fputs (format->message_set_start, stdout);
next_indent = indent;
if (match || params->entire_thread) {
next_indent = indent;
if (match || params->entire_thread) {
- show_message (ctx, format, message, indent, params);
+ status = show_message (ctx, format, message, indent, params);
+ if (status && !res)
+ res = status;
next_indent = indent + 1;
next_indent = indent + 1;
- fputs (format->message_set_sep, stdout);
+ if (!status)
+ fputs (format->message_set_sep, stdout);
- show_messages (ctx,
- format,
- notmuch_message_get_replies (message),
- next_indent,
- params);
+ status = show_messages (ctx,
+ format,
+ notmuch_message_get_replies (message),
+ next_indent,
+ params);
+ if (status && !res)
+ res = status;
notmuch_message_destroy (message);
notmuch_message_destroy (message);
}
fputs (format->message_set_end, stdout);
}
fputs (format->message_set_end, stdout);
}
/* Formatted output of single message */
}
/* Formatted output of single message */
- show_message (ctx, format, message, 0, params);
+ return show_message (ctx, format, message, 0, params) != NOTMUCH_STATUS_SUCCESS;
}
/* Formatted output of threads */
}
/* Formatted output of threads */
notmuch_thread_t *thread;
notmuch_messages_t *messages;
int first_toplevel = 1;
notmuch_thread_t *thread;
notmuch_messages_t *messages;
int first_toplevel = 1;
+ notmuch_status_t status, res = NOTMUCH_STATUS_SUCCESS;
fputs (format->message_set_start, stdout);
fputs (format->message_set_start, stdout);
fputs (format->message_set_sep, stdout);
first_toplevel = 0;
fputs (format->message_set_sep, stdout);
first_toplevel = 0;
- show_messages (ctx, format, messages, 0, params);
+ status = show_messages (ctx, format, messages, 0, params);
+ if (status && !res)
+ res = status;
notmuch_thread_destroy (thread);
notmuch_thread_destroy (thread);
fputs (format->message_set_end, stdout);
fputs (format->message_set_end, stdout);
+ return res != NOTMUCH_STATUS_SUCCESS;