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 12673431FD0 for ; Sat, 1 Nov 2014 04:31:02 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[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 PcPtho5f4EkN for ; Sat, 1 Nov 2014 04:30:58 -0700 (PDT) Received: from mail-wi0-f174.google.com (mail-wi0-f174.google.com [209.85.212.174]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 139FE431FAF for ; Sat, 1 Nov 2014 04:30:57 -0700 (PDT) Received: by mail-wi0-f174.google.com with SMTP id d1so3143718wiv.13 for ; Sat, 01 Nov 2014 04:30:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=O4cZtjwTJw73+w6zjAZtxUanEcJwLMfRWki4OT6RXSM=; b=ckoQsIvTOQ1M5ouJCiL5REbwVk8gsJUQpCIWaxwMoHfSg/C4zBO0VM8I6Es8Dhh+52 5o+PgFw+X4m4J/QP/RI2jDZMi0WFe7ByE7gmT/abQ/l/YtZ/H44nFVJsXUr3XCBA0xFs N06TTTa1QPxR0w2jMhFof1ESZZkU9HQTtR42GcGhN/MpCQpjiqcLrEeLccbogV3nsaWG NPB9/QZPs98ULg6tLPPOVhD1YMEVOgrm5TsX5NeyaISNIM2D9Pdcjr9ICHGvguIbwQvA o3dPcuPKMUOMo5IMOg3D3UZq84i3HTGOUwcPOiQWmS3T0zNIIn9nTT4vNGjog1tUeKk5 lx+A== X-Gm-Message-State: ALoCoQl2hIExmt3awwpeXFUvCEhcS3AT1JOLof2k3+zOBynG1gl+R53rFXij65pZPYvQKMmWWQGL X-Received: by 10.181.11.131 with SMTP id ei3mr3422990wid.24.1414841456945; Sat, 01 Nov 2014 04:30:56 -0700 (PDT) Received: from localhost (dsl-hkibrasgw2-58c36d-48.dhcp.inet.fi. [88.195.109.48]) by mx.google.com with ESMTPSA id ny6sm1648800wic.22.2014.11.01.04.30.55 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 01 Nov 2014 04:30:56 -0700 (PDT) From: Jani Nikula To: Michal Sojka Subject: [RFC PATCH 2/2] cli: add notmuch address command Date: Sat, 1 Nov 2014 13:30:48 +0200 Message-Id: <1bc05ab764867004fd5b6c79266ffcd0249909cd.1414839970.git.jani@nikula.org> X-Mailer: git-send-email 2.1.1 In-Reply-To: References: <87egtn2s4z.fsf@steelpick.2x.cz> In-Reply-To: References: Cc: notmuch@notmuchmail.org 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: Sat, 01 Nov 2014 11:31:02 -0000 --- notmuch-client.h | 3 ++ notmuch-search.c | 128 +++++++++++++++++++++++++++++++++++-------------------- notmuch.c | 2 + 3 files changed, 87 insertions(+), 46 deletions(-) diff --git a/notmuch-client.h b/notmuch-client.h index e1efbe0c8252..5e0d47508c6a 100644 --- a/notmuch-client.h +++ b/notmuch-client.h @@ -199,6 +199,9 @@ int notmuch_search_command (notmuch_config_t *config, int argc, char *argv[]); int +notmuch_address_command (notmuch_config_t *config, int argc, char *argv[]); + +int notmuch_setup_command (notmuch_config_t *config, int argc, char *argv[]); int diff --git a/notmuch-search.c b/notmuch-search.c index 671fe4139981..07755f115776 100644 --- a/notmuch-search.c +++ b/notmuch-search.c @@ -35,6 +35,7 @@ typedef enum { #define OUTPUT_ADDRESS_FLAGS (OUTPUT_SENDER | OUTPUT_RECIPIENTS) typedef struct { + notmuch_bool_t address_command; sprinter_t *format; notmuch_query_t *query; notmuch_sort_t sort; @@ -440,17 +441,11 @@ do_search_tags (notmuch_database_t *notmuch, return 0; } -int -notmuch_search_command (notmuch_config_t *config, int argc, char *argv[]) +static int +_notmuch_search_command (notmuch_config_t *config, int argc, char *argv[], + search_options_t *opt, notmuch_opt_desc_t *subopts) { notmuch_database_t *notmuch; - search_options_t opt = { - .sort = NOTMUCH_SORT_NEWEST_FIRST, - .output = 0, - .offset = 0, - .limit = -1, /* unlimited */ - .dupe = -1, - }; char *query_str; int opt_index, ret; notmuch_exclude_t exclude = NOTMUCH_EXCLUDE_TRUE; @@ -464,7 +459,8 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[]) } format_sel = NOTMUCH_FORMAT_TEXT; notmuch_opt_desc_t options[] = { - { NOTMUCH_OPT_KEYWORD, &opt.sort, "sort", 's', + { NOTMUCH_OPT_INHERIT, subopts, NULL, 0, 0 }, + { NOTMUCH_OPT_KEYWORD, &opt->sort, "sort", 's', (notmuch_keyword_t []){ { "oldest-first", NOTMUCH_SORT_OLDEST_FIRST }, { "newest-first", NOTMUCH_SORT_NEWEST_FIRST }, { 0, 0 } } }, @@ -475,24 +471,15 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[]) { "text0", NOTMUCH_FORMAT_TEXT0 }, { 0, 0 } } }, { NOTMUCH_OPT_INT, ¬much_format_version, "format-version", 0, 0 }, - { NOTMUCH_OPT_KEYWORD_FLAGS, &opt.output, "output", 'o', - (notmuch_keyword_t []){ { "summary", OUTPUT_SUMMARY }, - { "threads", OUTPUT_THREADS }, - { "messages", OUTPUT_MESSAGES }, - { "sender", OUTPUT_SENDER }, - { "recipients", OUTPUT_RECIPIENTS }, - { "files", OUTPUT_FILES }, - { "tags", OUTPUT_TAGS }, - { 0, 0 } } }, { NOTMUCH_OPT_KEYWORD, &exclude, "exclude", 'x', (notmuch_keyword_t []){ { "true", NOTMUCH_EXCLUDE_TRUE }, { "false", NOTMUCH_EXCLUDE_FALSE }, { "flag", NOTMUCH_EXCLUDE_FLAG }, { "all", NOTMUCH_EXCLUDE_ALL }, { 0, 0 } } }, - { NOTMUCH_OPT_INT, &opt.offset, "offset", 'O', 0 }, - { NOTMUCH_OPT_INT, &opt.limit, "limit", 'L', 0 }, - { NOTMUCH_OPT_INT, &opt.dupe, "duplicate", 'D', 0 }, + { NOTMUCH_OPT_INT, &opt->offset, "offset", 'O', 0 }, + { NOTMUCH_OPT_INT, &opt->limit, "limit", 'L', 0 }, + { NOTMUCH_OPT_INT, &opt->dupe, "duplicate", 'D', 0 }, { 0, 0, 0, 0, 0 } }; @@ -500,25 +487,25 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[]) if (opt_index < 0) return EXIT_FAILURE; - if (! opt.output) - opt.output = OUTPUT_SUMMARY; + if (! opt->output) + opt->output = OUTPUT_SUMMARY; switch (format_sel) { case NOTMUCH_FORMAT_TEXT: - opt.format = sprinter_text_create (config, stdout); + opt->format = sprinter_text_create (config, stdout); break; case NOTMUCH_FORMAT_TEXT0: - if (opt.output == OUTPUT_SUMMARY) { + if (opt->output == OUTPUT_SUMMARY) { fprintf (stderr, "Error: --format=text0 is not compatible with --output=summary.\n"); return EXIT_FAILURE; } - opt.format = sprinter_text0_create (config, stdout); + opt->format = sprinter_text0_create (config, stdout); break; case NOTMUCH_FORMAT_JSON: - opt.format = sprinter_json_create (config, stdout); + opt->format = sprinter_json_create (config, stdout); break; case NOTMUCH_FORMAT_SEXP: - opt.format = sprinter_sexp_create (config, stdout); + opt->format = sprinter_sexp_create (config, stdout); break; default: /* this should never happen */ @@ -541,15 +528,15 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[]) return EXIT_FAILURE; } - opt.query = notmuch_query_create (notmuch, query_str); - if (opt.query == NULL) { + opt->query = notmuch_query_create (notmuch, query_str); + if (opt->query == NULL) { fprintf (stderr, "Out of memory\n"); return EXIT_FAILURE; } - notmuch_query_set_sort (opt.query, opt.sort); + notmuch_query_set_sort (opt->query, opt->sort); - if (exclude == NOTMUCH_EXCLUDE_FLAG && opt.output != OUTPUT_SUMMARY) { + if (exclude == NOTMUCH_EXCLUDE_FLAG && opt->output != OUTPUT_SUMMARY) { /* If we are not doing summary output there is nowhere to * print the excluded flag so fall back on including the * excluded messages. */ @@ -564,28 +551,77 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[]) search_exclude_tags = notmuch_config_get_search_exclude_tags (config, &search_exclude_tags_length); for (i = 0; i < search_exclude_tags_length; i++) - notmuch_query_add_tag_exclude (opt.query, search_exclude_tags[i]); - notmuch_query_set_omit_excluded (opt.query, exclude); + notmuch_query_add_tag_exclude (opt->query, search_exclude_tags[i]); + notmuch_query_set_omit_excluded (opt->query, exclude); } - if (opt.output == OUTPUT_SUMMARY || - opt.output == OUTPUT_THREADS) - ret = do_search_threads (&opt); - else if (opt.output == OUTPUT_MESSAGES || - opt.output == OUTPUT_FILES || - (opt.output & OUTPUT_ADDRESS_FLAGS && !(opt.output & ~OUTPUT_ADDRESS_FLAGS))) - ret = do_search_messages (&opt); - else if (opt.output == OUTPUT_TAGS) - ret = do_search_tags (notmuch, &opt); + if (opt->output == OUTPUT_SUMMARY || + opt->output == OUTPUT_THREADS) + ret = do_search_threads (opt); + else if (opt->output == OUTPUT_MESSAGES || + opt->output == OUTPUT_FILES || + (opt->output & OUTPUT_ADDRESS_FLAGS && !(opt->output & ~OUTPUT_ADDRESS_FLAGS))) + ret = do_search_messages (opt); + else if (opt->output == OUTPUT_TAGS) + ret = do_search_tags (notmuch, opt); else { fprintf (stderr, "Error: the combination of outputs is not supported.\n"); ret = 1; } - notmuch_query_destroy (opt.query); + notmuch_query_destroy (opt->query); notmuch_database_destroy (notmuch); - talloc_free (opt.format); + talloc_free (opt->format); return ret ? EXIT_FAILURE : EXIT_SUCCESS; } + +int +notmuch_search_command (notmuch_config_t *config, int argc, char *argv[]) +{ + search_options_t opt = { + .address_command = FALSE, + .sort = NOTMUCH_SORT_NEWEST_FIRST, + .output = 0, + .offset = 0, + .limit = -1, /* unlimited */ + .dupe = -1, + }; + + notmuch_opt_desc_t options[] = { + { NOTMUCH_OPT_KEYWORD_FLAGS, &opt.output, "output", 'o', + (notmuch_keyword_t []){ { "summary", OUTPUT_SUMMARY }, + { "threads", OUTPUT_THREADS }, + { "messages", OUTPUT_MESSAGES }, + { "files", OUTPUT_FILES }, + { "tags", OUTPUT_TAGS }, + { 0, 0 } } }, + { 0, 0, 0, 0, 0 } + }; + + return _notmuch_search_command (config, argc, argv, &opt, options); +} + +int +notmuch_address_command (notmuch_config_t *config, int argc, char *argv[]) +{ + search_options_t opt = { + .address_command = TRUE, + .sort = NOTMUCH_SORT_NEWEST_FIRST, + .output = 0, + .offset = 0, + .limit = -1, /* unlimited */ + .dupe = -1, + }; + + notmuch_opt_desc_t options[] = { + { NOTMUCH_OPT_KEYWORD_FLAGS, &opt.output, "output", 'o', + (notmuch_keyword_t []){ { "sender", OUTPUT_SENDER }, + { "recipients", OUTPUT_RECIPIENTS }, + { 0, 0 } } }, + { 0, 0, 0, 0, 0 } + }; + + return _notmuch_search_command (config, argc, argv, &opt, options); +} diff --git a/notmuch.c b/notmuch.c index dcda0392a094..0fac0997865e 100644 --- a/notmuch.c +++ b/notmuch.c @@ -54,6 +54,8 @@ static command_t commands[] = { "Add a new message into the maildir and notmuch database." }, { "search", notmuch_search_command, FALSE, "Search for messages matching the given search terms." }, + { "address", notmuch_address_command, FALSE, + "Get addresses from messages matching the given search terms." }, { "show", notmuch_show_command, FALSE, "Show all messages matching the search terms." }, { "count", notmuch_count_command, FALSE, -- 2.1.1