[PATCH 5/7] cli: Make notmuch-show respect excludes.
Mark Walters
markwalters1009 at gmail.com
Sun Jan 29 10:39:52 PST 2012
This adds the excludes to notmuch-show.c. We do not exclude when only
a single message (or part) is requested. notmuch-show will output the
exclude information when either text or json format is requested. As
this changes the output from notmuch-show it breaks many tests (in a
trivial and expected fashion).
---
notmuch-show.c | 26 +++++++++++++++++++++-----
1 files changed, 21 insertions(+), 5 deletions(-)
diff --git a/notmuch-show.c b/notmuch-show.c
index dec799c..681827f 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -193,10 +193,12 @@ _get_one_line_summary (const void *ctx, notmuch_message_t *message)
static void
format_message_text (unused (const void *ctx), notmuch_message_t *message, int indent)
{
- printf ("id:%s depth:%d match:%d filename:%s\n",
+ /* Could changing this could break users ? */
+ printf ("id:%s depth:%d match:%d excluded:%d filename:%s\n",
notmuch_message_get_message_id (message),
indent,
- notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_MATCH),
+ notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_MATCH) ? 1 : 0,
+ notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED) ? 1 : 0,
notmuch_message_get_filename (message));
}
@@ -212,9 +214,10 @@ format_message_json (const void *ctx, notmuch_message_t *message, unused (int in
date = notmuch_message_get_date (message);
relative_date = notmuch_time_relative_date (ctx, date);
- printf ("\"id\": %s, \"match\": %s, \"filename\": %s, \"timestamp\": %ld, \"date_relative\": \"%s\", \"tags\": [",
+ printf ("\"id\": %s, \"match\": %s, \"excluded\": %s, \"filename\": %s, \"timestamp\": %ld, \"date_relative\": \"%s\", \"tags\": [",
json_quote_str (ctx_quote, notmuch_message_get_message_id (message)),
notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_MATCH) ? "true" : "false",
+ notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED) ? "true" : "false",
json_quote_str (ctx_quote, notmuch_message_get_filename (message)),
date, relative_date);
@@ -1059,9 +1062,13 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
char *opt;
const notmuch_show_format_t *format = &format_text;
notmuch_show_params_t params;
+ const char **search_exclude_tags;
+ size_t search_exclude_tags_length;
int mbox = 0;
int format_specified = 0;
int i;
+ notmuch_bool_t do_not_exclude = FALSE;
+ unsigned int j;
params.entire_thread = 0;
params.raw = 0;
@@ -1098,6 +1105,8 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
params.part = atoi(argv[i] + sizeof ("--part=") - 1);
} else if (STRNCMP_LITERAL (argv[i], "--entire-thread") == 0) {
params.entire_thread = 1;
+ } else if (STRNCMP_LITERAL (argv[i], "--do-not-exclude") == 0) {
+ do_not_exclude = TRUE;
} else if ((STRNCMP_LITERAL (argv[i], "--verify") == 0) ||
(STRNCMP_LITERAL (argv[i], "--decrypt") == 0)) {
if (params.cryptoctx == NULL) {
@@ -1105,7 +1114,7 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
/* TODO: GMimePasswordRequestFunc */
if (NULL == (params.cryptoctx = g_mime_gpg_context_new(NULL, "gpg")))
#else
- GMimeSession* session = g_object_new(g_mime_session_get_type(), NULL);
+ GMimeSession* session = g_object_new(g_mime_session_get_type(), NULL);
if (NULL == (params.cryptoctx = g_mime_gpg_context_new(session, "gpg")))
#endif
fprintf (stderr, "Failed to construct gpg context.\n");
@@ -1167,10 +1176,17 @@ notmuch_show_command (void *ctx, unused (int argc), unused (char *argv[]))
if (params.raw && params.part < 0)
params.part = 0;
+ /* if a single message is requested we do not use search_excludes */
if (params.part >= 0)
return do_show_single (ctx, query, format, ¶ms);
else
- return do_show (ctx, query, format, ¶ms);
+ if (!do_not_exclude) {
+ search_exclude_tags = notmuch_config_get_search_exclude_tags
+ (config, &search_exclude_tags_length);
+ for (j = 0; j < search_exclude_tags_length; j++)
+ notmuch_query_add_tag_exclude (query, search_exclude_tags[j]);
+ return do_show (ctx, query, format, ¶ms);
+ }
notmuch_query_destroy (query);
notmuch_database_close (notmuch);
--
1.7.2.3
More information about the notmuch
mailing list