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