[thread_node*] # children of message
]
-# A message (format_part_json)
+# A message (format_part_sprinter)
message = {
- # (format_message_json)
+ # (format_message_sprinter)
id: messageid,
match: bool,
filename: string,
body?: [part] # omitted if --body=false
}
-# A MIME part (format_part_json)
+# A MIME part (format_part_sprinter)
part = {
id: int|string, # part id (currently DFS part number)
content?: string
}
-# The headers of a message or part (format_headers_json with reply = FALSE)
+# The headers of a message or part (format_headers_sprinter with reply = FALSE)
headers = {
Subject: string,
From: string,
Date: string
}
-# Encryption status (format_part_json)
+# Encryption status (format_part_sprinter)
encstatus = [{status: "good"|"bad"}]
-# Signature status (format_part_sigstatus_json)
+# Signature status (format_part_sigstatus_sprinter)
sigstatus = [signature*]
signature = {
# The headers of the constructed reply
reply-headers: reply_headers,
- # As in the show format (format_part_json)
+ # As in the show format (format_part_sprinter)
original: message
}
-# Reply headers (format_headers_json with reply = TRUE)
+# Reply headers (format_headers_sprinter with reply = TRUE)
reply_headers = {
Subject: string,
From: string,
show_one_part (const char *filename, int part);
void
-format_part_json (const void *ctx, struct sprinter *sp, mime_node_t *node,
- notmuch_bool_t first, notmuch_bool_t output_body);
+format_part_sprinter (const void *ctx, struct sprinter *sp, mime_node_t *node,
+ notmuch_bool_t first, notmuch_bool_t output_body);
void
-format_headers_json (struct sprinter *sp, GMimeMessage *message,
- notmuch_bool_t reply);
+format_headers_sprinter (struct sprinter *sp, GMimeMessage *message,
+ notmuch_bool_t reply);
typedef enum {
NOTMUCH_SHOW_TEXT_PART_REPLY = 1 << 0,
notmuch_config_t *config,
notmuch_query_t *query,
notmuch_show_params_t *params,
- notmuch_bool_t reply_all)
+ notmuch_bool_t reply_all,
+ unused (sprinter_t *sp))
{
GMimeMessage *reply;
notmuch_messages_t *messages;
}
static int
-notmuch_reply_format_json(void *ctx,
- notmuch_config_t *config,
- notmuch_query_t *query,
- notmuch_show_params_t *params,
- notmuch_bool_t reply_all)
+notmuch_reply_format_sprinter(void *ctx,
+ notmuch_config_t *config,
+ notmuch_query_t *query,
+ notmuch_show_params_t *params,
+ notmuch_bool_t reply_all,
+ sprinter_t *sp)
{
GMimeMessage *reply;
notmuch_messages_t *messages;
notmuch_message_t *message;
mime_node_t *node;
- sprinter_t *sp;
if (notmuch_query_count_messages (query) != 1) {
fprintf (stderr, "Error: search term did not match precisely one message.\n");
if (!reply)
return 1;
- sp = sprinter_json_create (ctx, stdout);
sp->begin_map (sp);
/* The headers of the reply message we've created */
sp->map_key (sp, "reply-headers");
- format_headers_json (sp, reply, TRUE);
+ format_headers_sprinter (sp, reply, TRUE);
g_object_unref (G_OBJECT (reply));
reply = NULL;
/* Start the original */
sp->map_key (sp, "original");
- format_part_json (ctx, sp, node, TRUE, TRUE);
+ format_part_sprinter (ctx, sp, node, TRUE, TRUE);
/* End */
sp->end (sp);
notmuch_config_t *config,
notmuch_query_t *query,
unused (notmuch_show_params_t *params),
- notmuch_bool_t reply_all)
+ notmuch_bool_t reply_all,
+ unused (sprinter_t *sp))
{
GMimeMessage *reply;
notmuch_messages_t *messages;
notmuch_query_t *query;
char *query_string;
int opt_index, ret = 0;
- int (*reply_format_func)(void *ctx, notmuch_config_t *config, notmuch_query_t *query, notmuch_show_params_t *params, notmuch_bool_t reply_all);
+ int (*reply_format_func) (void *ctx,
+ notmuch_config_t *config,
+ notmuch_query_t *query,
+ notmuch_show_params_t *params,
+ notmuch_bool_t reply_all,
+ struct sprinter *sp);
notmuch_show_params_t params = {
.part = -1,
.crypto = {
};
int format = FORMAT_DEFAULT;
int reply_all = TRUE;
+ struct sprinter *sp = NULL;
notmuch_opt_desc_t options[] = {
{ NOTMUCH_OPT_KEYWORD, &format, "format", 'f',
return 1;
}
- if (format == FORMAT_HEADERS_ONLY)
+ if (format == FORMAT_HEADERS_ONLY) {
reply_format_func = notmuch_reply_format_headers_only;
- else if (format == FORMAT_JSON)
- reply_format_func = notmuch_reply_format_json;
- else
+ } else if (format == FORMAT_JSON) {
+ reply_format_func = notmuch_reply_format_sprinter;
+ sp = sprinter_json_create (ctx, stdout);
+ } else {
reply_format_func = notmuch_reply_format_default;
+ }
config = notmuch_config_open (ctx, NULL, NULL);
if (config == NULL)
return 1;
}
- if (reply_format_func (ctx, config, query, ¶ms, reply_all) != 0)
+ if (reply_format_func (ctx, config, query, ¶ms, reply_all, sp) != 0)
return 1;
notmuch_crypto_cleanup (¶ms.crypto);
};
static notmuch_status_t
-format_part_json_entry (const void *ctx, sprinter_t *sp, mime_node_t *node,
- int indent, const notmuch_show_params_t *params);
+format_part_sprinter_entry (const void *ctx, sprinter_t *sp, mime_node_t *node,
+ int indent, const notmuch_show_params_t *params);
static const notmuch_show_format_t format_json = {
.new_sprinter = sprinter_json_create,
- .part = format_part_json_entry,
+ .part = format_part_sprinter_entry,
};
static notmuch_status_t
/* Emit a sequence of key/value pairs for the metadata of message.
* The caller should begin a map before calling this. */
static void
-format_message_json (sprinter_t *sp, notmuch_message_t *message)
+format_message_sprinter (sprinter_t *sp, notmuch_message_t *message)
{
/* Any changes to the JSON format should be reflected in the file
* devel/schemata. */
}
void
-format_headers_json (sprinter_t *sp, GMimeMessage *message,
- notmuch_bool_t reply)
+format_headers_sprinter (sprinter_t *sp, GMimeMessage *message,
+ notmuch_bool_t reply)
{
/* Any changes to the JSON format should be reflected in the file
* devel/schemata. */
#ifdef GMIME_ATLEAST_26
static void
-format_part_sigstatus_json (sprinter_t *sp, mime_node_t *node)
+format_part_sigstatus_sprinter (sprinter_t *sp, mime_node_t *node)
{
/* Any changes to the JSON format should be reflected in the file
* devel/schemata. */
}
#else
static void
-format_part_sigstatus_json (sprinter_t *sp, mime_node_t *node)
+format_part_sigstatus_sprinter (sprinter_t *sp, mime_node_t *node)
{
const GMimeSignatureValidity* validity = node->sig_validity;
}
void
-format_part_json (const void *ctx, sprinter_t *sp, mime_node_t *node,
- notmuch_bool_t first, notmuch_bool_t output_body)
+format_part_sprinter (const void *ctx, sprinter_t *sp, mime_node_t *node,
+ notmuch_bool_t first, notmuch_bool_t output_body)
{
/* Any changes to the JSON format should be reflected in the file
* devel/schemata. */
if (node->envelope_file) {
sp->begin_map (sp);
- format_message_json (sp, node->envelope_file);
+ format_message_sprinter (sp, node->envelope_file);
sp->map_key (sp, "headers");
- format_headers_json (sp, GMIME_MESSAGE (node->part), FALSE);
+ format_headers_sprinter (sp, GMIME_MESSAGE (node->part), FALSE);
if (output_body) {
sp->map_key (sp, "body");
sp->begin_list (sp);
- format_part_json (ctx, sp, mime_node_child (node, 0), first, TRUE);
+ format_part_sprinter (ctx, sp, mime_node_child (node, 0), first, TRUE);
sp->end (sp);
}
sp->end (sp);
if (node->verify_attempted) {
sp->map_key (sp, "sigstatus");
- format_part_sigstatus_json (sp, node);
+ format_part_sigstatus_sprinter (sp, node);
}
sp->map_key (sp, "content-type");
sp->begin_map (sp);
sp->map_key (sp, "headers");
- format_headers_json (sp, GMIME_MESSAGE (node->part), FALSE);
+ format_headers_sprinter (sp, GMIME_MESSAGE (node->part), FALSE);
sp->map_key (sp, "body");
sp->begin_list (sp);
}
for (i = 0; i < node->nchildren; i++)
- format_part_json (ctx, sp, mime_node_child (node, i), i == 0, TRUE);
+ format_part_sprinter (ctx, sp, mime_node_child (node, i), i == 0, TRUE);
/* Close content structures */
for (i = 0; i < nclose; i++)
}
static notmuch_status_t
-format_part_json_entry (const void *ctx, sprinter_t *sp,
- mime_node_t *node, unused (int indent),
- const notmuch_show_params_t *params)
+format_part_sprinter_entry (const void *ctx, sprinter_t *sp,
+ mime_node_t *node, unused (int indent),
+ const notmuch_show_params_t *params)
{
- format_part_json (ctx, sp, node, TRUE, params->output_body);
+ format_part_sprinter (ctx, sp, node, TRUE, params->output_body);
return NOTMUCH_STATUS_SUCCESS;
}