From: david@tethera.net
To: notmuch@notmuchmail.org
Cc: David Bremner <bremner@unb.ca>
Subject: [PATCH 3/3] notmuch-show.c: control which headers are show for json output.
Date: Sat, 24 Apr 2010 08:44:38 -0300 [thread overview]
Message-ID: <1272109478-20686-4-git-send-email-david@tethera.net> (raw)
In-Reply-To: <1272109478-20686-1-git-send-email-david@tethera.net>
From: David Bremner <bremner@unb.ca>
This commit adds argument handling from and callbacks to
notmuch-output.c to determine what headers to show in json output.
This requires passing a pointer to a struct containing the output
parameters into several functions, and in particular changes the type of
the function pointers in the show_format structure.
---
notmuch-show.c | 81 ++++++++++++++++++++++++++++++++++++++------------------
1 files changed, 55 insertions(+), 26 deletions(-)
diff --git a/notmuch-show.c b/notmuch-show.c
index 6aa9072..29e2819 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -19,6 +19,7 @@
*/
#include "notmuch-client.h"
+#include "notmuch-output.h"
typedef struct show_format {
const char *message_set_start;
@@ -28,6 +29,7 @@ typedef struct show_format {
int indent);
const char *header_start;
void (*header) (const void *ctx,
+ notmuch_output_options_t *output_opts,
notmuch_message_t *message);
const char *header_end;
const char *body_start;
@@ -45,6 +47,7 @@ format_message_text (unused (const void *ctx),
int indent);
static void
format_headers_text (const void *ctx,
+ notmuch_output_options_t *opts,
notmuch_message_t *message);
static void
format_part_text (GMimeObject *part,
@@ -64,6 +67,7 @@ format_message_json (const void *ctx,
unused (int indent));
static void
format_headers_json (const void *ctx,
+ unused (notmuch_output_options_t *opts),
notmuch_message_t *message);
static void
format_part_json (GMimeObject *part,
@@ -164,7 +168,9 @@ format_message_json (const void *ctx, notmuch_message_t *message, unused (int in
}
static void
-format_headers_text (const void *ctx, notmuch_message_t *message)
+format_headers_text (const void *ctx,
+ unused (notmuch_output_options_t *opts),
+ notmuch_message_t *message)
{
const char *headers[] = {
"Subject", "From", "To", "Cc", "Bcc", "Date"
@@ -183,28 +189,38 @@ format_headers_text (const void *ctx, notmuch_message_t *message)
}
static void
-format_headers_json (const void *ctx, notmuch_message_t *message)
+format_headers_json (const void *ctx,
+ notmuch_output_options_t *output_opts,
+ notmuch_message_t *message)
{
- const char *headers[] = {
- "Subject", "From", "To", "Cc", "Bcc", "Date"
+ const struct { const char *name; notmuch_output_t key; } headers[] = {
+ { "Subject", NOTMUCH_OUTPUT_SUBJECT},
+ { "From", NOTMUCH_OUTPUT_FROM},
+ { "To", NOTMUCH_OUTPUT_TO},
+ { "Cc", NOTMUCH_OUTPUT_TO},
+ { "Bcc", NOTMUCH_OUTPUT_BCC },
+ { "Date", NOTMUCH_OUTPUT_DATE}
};
+
const char *name, *value;
unsigned int i;
int first_header = 1;
void *ctx_quote = talloc_new (ctx);
for (i = 0; i < ARRAY_SIZE (headers); i++) {
- name = headers[i];
- value = notmuch_message_get_header (message, name);
- if (value)
- {
- if (!first_header)
- fputs (", ", stdout);
- first_header = 0;
-
- printf ("%s: %s",
- json_quote_str (ctx_quote, name),
- json_quote_str (ctx_quote, value));
+ if (output_get_flag(output_opts,headers[i].key)) {
+ name = headers[i].name;
+ value = notmuch_message_get_header (message, name);
+ if (value)
+ {
+ if (!first_header)
+ fputs (", ", stdout);
+ first_header = 0;
+
+ printf ("%s: %s",
+ json_quote_str (ctx_quote, name),
+ json_quote_str (ctx_quote, value));
+ }
}
}
@@ -337,7 +353,9 @@ format_part_json (GMimeObject *part, int *part_count)
}
static void
-show_message (void *ctx, const show_format_t *format, notmuch_message_t *message, int indent)
+show_message (void *ctx, const show_format_t *format,
+ notmuch_output_options_t *output_options,
+ notmuch_message_t *message, int indent)
{
fputs (format->message_start, stdout);
if (format->message)
@@ -345,20 +363,24 @@ show_message (void *ctx, const show_format_t *format, notmuch_message_t *message
fputs (format->header_start, stdout);
if (format->header)
- format->header(ctx, message);
+ format->header(ctx, output_options, message);
fputs (format->header_end, stdout);
- fputs (format->body_start, stdout);
- if (format->part)
- show_message_body (notmuch_message_get_filename (message), format->part);
- fputs (format->body_end, stdout);
+ if (output_get_flag(output_options, NOTMUCH_OUTPUT_BODY)){
+ fputs (format->body_start, stdout);
+ if (format->part)
+ show_message_body (notmuch_message_get_filename (message), format->part);
+ fputs (format->body_end, stdout);
+ }
fputs (format->message_end, stdout);
}
static void
-show_messages (void *ctx, const show_format_t *format, notmuch_messages_t *messages, int indent,
+show_messages (void *ctx, const show_format_t *format,
+ notmuch_output_options_t *output_opts,
+ notmuch_messages_t *messages, int indent,
notmuch_bool_t entire_thread)
{
notmuch_message_t *message;
@@ -385,13 +407,14 @@ show_messages (void *ctx, const show_format_t *format, notmuch_messages_t *messa
next_indent = indent;
if (match || entire_thread) {
- show_message (ctx, format, message, indent);
+ show_message (ctx, format, output_opts, message, indent);
next_indent = indent + 1;
fputs (format->message_set_sep, stdout);
}
- show_messages (ctx, format, notmuch_message_get_replies (message),
+ show_messages (ctx, format, output_opts,
+ notmuch_message_get_replies (message),
next_indent, entire_thread);
notmuch_message_destroy (message);
@@ -411,6 +434,7 @@ notmuch_show_command (void *ctx, int argc, char *argv[])
notmuch_threads_t *threads;
notmuch_thread_t *thread;
notmuch_messages_t *messages;
+ notmuch_output_options_t *output_opts;
char *query_string;
char *opt;
const show_format_t *format = &format_text;
@@ -418,12 +442,17 @@ notmuch_show_command (void *ctx, int argc, char *argv[])
int i;
int first_toplevel = 1;
+ output_opts = output_init(ctx);
+
for (i = 0; i < argc && argv[i][0] == '-'; i++) {
if (strcmp (argv[i], "--") == 0) {
i++;
break;
}
- if (STRNCMP_LITERAL (argv[i], "--format=") == 0) {
+ if (STRNCMP_LITERAL (argv[i], "--output=") == 0) {
+ if(output_parse_arg(output_opts, argv[i]))
+ return 1;
+ } else if (STRNCMP_LITERAL (argv[i], "--format=") == 0) {
opt = argv[i] + sizeof ("--format=") - 1;
if (strcmp (opt, "text") == 0) {
format = &format_text;
@@ -489,7 +518,7 @@ notmuch_show_command (void *ctx, int argc, char *argv[])
fputs (format->message_set_sep, stdout);
first_toplevel = 0;
- show_messages (ctx, format, messages, 0, entire_thread);
+ show_messages (ctx, format, output_opts, messages, 0, entire_thread);
notmuch_thread_destroy (thread);
--
1.7.0
prev parent reply other threads:[~2010-04-24 11:45 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-04-24 11:44 Initial support for selecting what is output david
2010-04-24 11:44 ` [PATCH 1/3] remove stale "unused" from around argv and argc in notmuch_show_command david
2010-04-24 11:44 ` [PATCH 2/3] notmuch-output.[ch]: initial implementation of output selection argument handling david
2010-04-24 11:44 ` david [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1272109478-20686-4-git-send-email-david@tethera.net \
--to=david@tethera.net \
--cc=bremner@unb.ca \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).