From 3bbe9eb97b46d00a3a10cf6db168689d577880a9 Mon Sep 17 00:00:00 2001 From: Mark Walters Date: Sun, 29 Jan 2012 18:39:52 +0000 Subject: [PATCH] [PATCH 5/7] cli: Make notmuch-show respect excludes. --- 93/94e886281de878450782ba1a03b2b28c4d270b | 154 ++++++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 93/94e886281de878450782ba1a03b2b28c4d270b diff --git a/93/94e886281de878450782ba1a03b2b28c4d270b b/93/94e886281de878450782ba1a03b2b28c4d270b new file mode 100644 index 000000000..699a897fa --- /dev/null +++ b/93/94e886281de878450782ba1a03b2b28c4d270b @@ -0,0 +1,154 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 67BBB429E43 + for ; Sun, 29 Jan 2012 10:39:26 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: 0.201 +X-Spam-Level: +X-Spam-Status: No, score=0.201 tagged_above=-999 required=5 + tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, + FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001, + RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id z0bT2IWceEUI for ; + Sun, 29 Jan 2012 10:39:25 -0800 (PST) +Received: from mail-wi0-f181.google.com (mail-wi0-f181.google.com + [209.85.212.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 942F5429E3F + for ; Sun, 29 Jan 2012 10:39:25 -0800 (PST) +Received: by mail-wi0-f181.google.com with SMTP id hi8so2994807wib.26 + for ; Sun, 29 Jan 2012 10:39:25 -0800 (PST) +DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; + h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; + bh=Vb/vCEGOf9tKHwAE8SRmOis9qs2PnzdN6DbCeqij/EM=; + b=CEp/M6qQmPMQnCpgAg08D22p/TX2LYraf4Q12ifizG1PndxTO4KveqExZXgwbjP9Cs + TvX17Jl+tVZQcsJ4i4FYOK0B3tYK1I62zKssG/HNG352U1OfpJGuuOy1RhlOyPmJAc4M + bH6cqoEAErSYeKbdgVcIBjCPaxpJ55vl+9dGE= +Received: by 10.180.77.200 with SMTP id u8mr22886353wiw.18.1327862365310; + Sun, 29 Jan 2012 10:39:25 -0800 (PST) +Received: from localhost (94-192-233-223.zone6.bethere.co.uk. + [94.192.233.223]) by mx.google.com with ESMTPS id + j16sm44636947wie.4.2012.01.29.10.39.23 (version=TLSv1/SSLv3 cipher=OTHER); + Sun, 29 Jan 2012 10:39:24 -0800 (PST) +From: Mark Walters +To: notmuch@notmuchmail.org, + amdragon@MIT.EDU +Subject: [PATCH 5/7] cli: Make notmuch-show respect excludes. +Date: Sun, 29 Jan 2012 18:39:52 +0000 +Message-Id: <1327862394-14334-5-git-send-email-markwalters1009@gmail.com> +X-Mailer: git-send-email 1.7.2.3 +In-Reply-To: <8762fu4aqt.fsf@qmul.ac.uk> +References: <8762fu4aqt.fsf@qmul.ac.uk> +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Sun, 29 Jan 2012 18:39:26 -0000 + +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 + -- 2.26.2