[PATCH v3 06/10] cli: Introduce "notmuch address" command
authorMichal Sojka <sojkam1@fel.cvut.cz>
Wed, 5 Nov 2014 00:25:55 +0000 (01:25 +0100)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 18:06:14 +0000 (10:06 -0800)
4d/b729db509186b870552153ae541a91e8d78dc0 [new file with mode: 0644]

diff --git a/4d/b729db509186b870552153ae541a91e8d78dc0 b/4d/b729db509186b870552153ae541a91e8d78dc0
new file mode 100644 (file)
index 0000000..50be399
--- /dev/null
@@ -0,0 +1,512 @@
+Return-Path: <sojkam1@fel.cvut.cz>\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 9A7F9429E38\r
+       for <notmuch@notmuchmail.org>; Tue,  4 Nov 2014 16:26:52 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -2.3\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_MED=-2.3] 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 Rsqeu-H1y4nt for <notmuch@notmuchmail.org>;\r
+       Tue,  4 Nov 2014 16:26:44 -0800 (PST)\r
+Received: from max.feld.cvut.cz (max.feld.cvut.cz [147.32.192.36])\r
+       by olra.theworths.org (Postfix) with ESMTP id 785DC431FC3\r
+       for <notmuch@notmuchmail.org>; Tue,  4 Nov 2014 16:26:22 -0800 (PST)\r
+Received: from localhost (unknown [192.168.200.7])\r
+       by max.feld.cvut.cz (Postfix) with ESMTP id D47BD5CD1AA\r
+       for <notmuch@notmuchmail.org>; Wed,  5 Nov 2014 01:26:21 +0100 (CET)\r
+X-Virus-Scanned: IMAP STYX AMAVIS\r
+Received: from max.feld.cvut.cz ([192.168.200.1])\r
+       by localhost (styx.feld.cvut.cz [192.168.200.7]) (amavisd-new,\r
+       port 10044) with ESMTP id ekCy3NQNhquW for <notmuch@notmuchmail.org>;\r
+       Wed,  5 Nov 2014 01:26:17 +0100 (CET)\r
+Received: from imap.feld.cvut.cz (imap.feld.cvut.cz [147.32.192.34])\r
+       by max.feld.cvut.cz (Postfix) with ESMTP id 42D815CD1AD\r
+       for <notmuch@notmuchmail.org>; Wed,  5 Nov 2014 01:26:14 +0100 (CET)\r
+Received: from wsh by steelpick.2x.cz with local (Exim 4.84)\r
+       (envelope-from <sojkam1@fel.cvut.cz>)\r
+       id 1XloQI-0005D2-TT; Wed, 05 Nov 2014 01:26:06 +0100\r
+From: Michal Sojka <sojkam1@fel.cvut.cz>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v3 06/10] cli: Introduce "notmuch address" command\r
+Date: Wed,  5 Nov 2014 01:25:55 +0100\r
+Message-Id: <1415147159-19946-7-git-send-email-sojkam1@fel.cvut.cz>\r
+X-Mailer: git-send-email 2.1.1\r
+In-Reply-To: <1415147159-19946-1-git-send-email-sojkam1@fel.cvut.cz>\r
+References: <1415147159-19946-1-git-send-email-sojkam1@fel.cvut.cz>\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: Wed, 05 Nov 2014 00:26:52 -0000\r
+\r
+This moves address-related functionality from search command to the\r
+new address command. The implementation shares almost all code and\r
+some command line options.\r
+\r
+Options --offset and --limit were intentionally not included in the\r
+address command, because they refer to messages numbers, which users\r
+do not see in the output. This could confuse users because, for\r
+example, they could see more addresses in the output that what was\r
+specified with --limit. This functionality can be correctly\r
+reimplemented for address subcommand later.\r
+\r
+Also useless values of --exclude flag were not included in the address\r
+command.\r
+\r
+This was inspired by a patch from Jani Nikula.\r
+---\r
+ completion/notmuch-completion.bash | 42 ++++++++++++++++-\r
+ completion/notmuch-completion.zsh  | 10 +++-\r
+ doc/man1/notmuch-address.rst       | 89 ++++++++++++++++++++++++++++++++++++\r
+ doc/man1/notmuch-search.rst        | 20 +-------\r
+ doc/man1/notmuch.rst               |  7 +--\r
+ notmuch-client.h                   |  3 ++\r
+ notmuch-search.c                   | 93 +++++++++++++++++++++++++++-----------\r
+ notmuch.c                          |  2 +\r
+ 8 files changed, 216 insertions(+), 50 deletions(-)\r
+ create mode 100644 doc/man1/notmuch-address.rst\r
+\r
+diff --git a/completion/notmuch-completion.bash b/completion/notmuch-completion.bash\r
+index cfbd389..94ea2d5 100644\r
+--- a/completion/notmuch-completion.bash\r
++++ b/completion/notmuch-completion.bash\r
+@@ -294,7 +294,7 @@ _notmuch_search()\r
+           return\r
+           ;;\r
+       --output)\r
+-          COMPREPLY=( $( compgen -W "summary threads messages files tags sender recipients" -- "${cur}" ) )\r
++          COMPREPLY=( $( compgen -W "summary threads messages files tags" -- "${cur}" ) )\r
+           return\r
+           ;;\r
+       --sort)\r
+@@ -320,6 +320,44 @@ _notmuch_search()\r
+     esac\r
+ }\r
\r
++_notmuch_address()\r
++{\r
++    local cur prev words cword split\r
++    _init_completion -s || return\r
++\r
++    $split &&\r
++    case "${prev}" in\r
++      --format)\r
++          COMPREPLY=( $( compgen -W "json sexp text text0" -- "${cur}" ) )\r
++          return\r
++          ;;\r
++      --output)\r
++          COMPREPLY=( $( compgen -W "sender recipients" -- "${cur}" ) )\r
++          return\r
++          ;;\r
++      --sort)\r
++          COMPREPLY=( $( compgen -W "newest-first oldest-first" -- "${cur}" ) )\r
++          return\r
++          ;;\r
++      --exclude)\r
++          COMPREPLY=( $( compgen -W "true false flag all" -- "${cur}" ) )\r
++          return\r
++          ;;\r
++    esac\r
++\r
++    ! $split &&\r
++    case "${cur}" in\r
++      -*)\r
++          local options="--format= --output= --sort= --exclude="\r
++          compopt -o nospace\r
++          COMPREPLY=( $(compgen -W "$options" -- ${cur}) )\r
++          ;;\r
++      *)\r
++          _notmuch_search_terms\r
++          ;;\r
++    esac\r
++}\r
++\r
+ _notmuch_show()\r
+ {\r
+     local cur prev words cword split\r
+@@ -393,7 +431,7 @@ _notmuch_tag()\r
\r
+ _notmuch()\r
+ {\r
+-    local _notmuch_commands="compact config count dump help insert new reply restore search setup show tag"\r
++    local _notmuch_commands="compact config count dump help insert new reply restore search address setup show tag"\r
+     local arg cur prev words cword split\r
\r
+     # require bash-completion with _init_completion\r
+diff --git a/completion/notmuch-completion.zsh b/completion/notmuch-completion.zsh\r
+index 3e52a00..c606b75 100644\r
+--- a/completion/notmuch-completion.zsh\r
++++ b/completion/notmuch-completion.zsh\r
+@@ -10,6 +10,7 @@ _notmuch_commands()\r
+     'setup:interactively set up notmuch for first use'\r
+     'new:find and import any new message to the database'\r
+     'search:search for messages matching the search terms, display matching threads as results'\r
++    'address:get addresses from messages matching the given search terms'\r
+     'reply:constructs a reply template for a set of messages'\r
+     'show:show all messages matching the search terms'\r
+     'tag:add or remove tags for all messages matching the search terms'\r
+@@ -53,7 +54,14 @@ _notmuch_search()\r
+     '--max-threads=[display only the first x threads from the search results]:number of threads to show: ' \\r
+     '--first=[omit the first x threads from the search results]:number of threads to omit: ' \\r
+     '--sort=[sort results]:sorting:((newest-first\:"reverse chronological order" oldest-first\:"chronological order"))' \\r
+-    '--output=[select what to output]:output:((summary threads messages files tags sender recipients))'\r
++    '--output=[select what to output]:output:((summary threads messages files tags))'\r
++}\r
++\r
++_notmuch_address()\r
++{\r
++  _arguments -s : \\r
++    '--sort=[sort results]:sorting:((newest-first\:"reverse chronological order" oldest-first\:"chronological order"))' \\r
++    '--output=[select what to output]:output:((sender recipients))'\r
+ }\r
\r
+ _notmuch()\r
+diff --git a/doc/man1/notmuch-address.rst b/doc/man1/notmuch-address.rst\r
+new file mode 100644\r
+index 0000000..d349237\r
+--- /dev/null\r
++++ b/doc/man1/notmuch-address.rst\r
+@@ -0,0 +1,89 @@\r
++===============\r
++notmuch-address\r
++===============\r
++\r
++SYNOPSIS\r
++========\r
++\r
++**notmuch** **address** [*option* ...] <*search-term*> ...\r
++\r
++DESCRIPTION\r
++===========\r
++\r
++Search for messages matching the given search terms, and display the\r
++addresses from them.\r
++\r
++See **notmuch-search-terms(7)** for details of the supported syntax for\r
++<search-terms>.\r
++\r
++Supported options for **address** include\r
++\r
++    ``--format=``\ (**json**\ \|\ **sexp**\ \|\ **text**\ \|\ **text0**)\r
++        Presents the results in either JSON, S-Expressions, newline\r
++        character separated plain-text (default), or null character\r
++        separated plain-text (compatible with **xargs(1)** -0 option\r
++        where available).\r
++\r
++    ``--format-version=N``\r
++        Use the specified structured output format version. This is\r
++        intended for programs that invoke **notmuch(1)** internally. If\r
++        omitted, the latest supported version will be used.\r
++\r
++    ``--output=(sender|recipients)``\r
++\r
++        Controls which information appears in the output. This option\r
++      can be given multiple times to combine different outputs.\r
++      Omitting this option is equivalent to\r
++      --output=sender --output=recipients.\r
++\r
++      **sender**\r
++            Output all addresses from the *From* header.\r
++\r
++          Note: Searching for **sender** should be much faster than\r
++          searching for **recipients**, because sender addresses are\r
++          cached directly in the database whereas other addresses\r
++          need to be fetched from message files.\r
++\r
++      **recipients**\r
++            Output all addresses from the *To*, *Cc* and *Bcc*\r
++            headers.\r
++\r
++    ``--sort=``\ (**newest-first**\ \|\ **oldest-first**)\r
++        This option can be used to present results in either\r
++        chronological order (**oldest-first**) or reverse chronological\r
++        order (**newest-first**).\r
++\r
++        By default, results will be displayed in reverse chronological\r
++        order, (that is, the newest results will be displayed first).\r
++\r
++    ``--exclude=(true|false)``\r
++        A message is called "excluded" if it matches at least one tag in\r
++        search.tag\_exclude that does not appear explicitly in the\r
++        search terms. This option specifies whether to omit excluded\r
++        messages in the search process.\r
++\r
++        The default value, **true**, prevents excluded messages from\r
++        matching the search terms.\r
++\r
++        **false** allows excluded messages to match search terms and\r
++        appear in displayed results.\r
++\r
++EXIT STATUS\r
++===========\r
++\r
++This command supports the following special exit status codes\r
++\r
++``20``\r
++    The requested format version is too old.\r
++\r
++``21``\r
++    The requested format version is too new.\r
++\r
++SEE ALSO\r
++========\r
++\r
++**notmuch(1)**, **notmuch-config(1)**, **notmuch-count(1)**,\r
++**notmuch-dump(1)**, **notmuch-hooks(5)**, **notmuch-insert(1)**,\r
++**notmuch-new(1)**, **notmuch-reply(1)**, **notmuch-restore(1)**,\r
++**notmuch-search-terms(7)**, **notmuch-show(1)**, **notmuch-tag(1)**,\r
++***notmuch-search(1)**\r
+diff --git a/doc/man1/notmuch-search.rst b/doc/man1/notmuch-search.rst\r
+index 8110086..65df288 100644\r
+--- a/doc/man1/notmuch-search.rst\r
++++ b/doc/man1/notmuch-search.rst\r
+@@ -78,25 +78,8 @@ Supported options for **search** include\r
+             by null characters (--format=text0), as a JSON array\r
+             (--format=json), or as an S-Expression list (--format=sexp).\r
\r
+-      **sender**\r
+-            Output all addresses from the *From* header that appear on\r
+-            any message matching the search terms, either one per line\r
+-            (--format=text), separated by null characters\r
+-            (--format=text0), as a JSON array (--format=json), or as\r
+-            an S-Expression list (--format=sexp).\r
+-\r
+-          Note: Searching for **sender** should be much faster than\r
+-          searching for **recipients**, because sender addresses are\r
+-          cached directly in the database whereas other addresses\r
+-          need to be fetched from message files.\r
+-\r
+-      **recipients**\r
+-            Like **sender** but for addresses from *To*, *Cc* and\r
+-          *Bcc* headers.\r
+-\r
+       This option can be given multiple times to combine different\r
+-      outputs. Currently, this is only supported for **sender** and\r
+-      **recipients** outputs.\r
++      outputs.\r
\r
+     ``--sort=``\ (**newest-first**\ \|\ **oldest-first**)\r
+         This option can be used to present results in either\r
+@@ -173,3 +156,4 @@ SEE ALSO\r
+ **notmuch-dump(1)**, **notmuch-hooks(5)**, **notmuch-insert(1)**,\r
+ **notmuch-new(1)**, **notmuch-reply(1)**, **notmuch-restore(1)**,\r
+ **notmuch-search-terms(7)**, **notmuch-show(1)**, **notmuch-tag(1)**\r
++***notmuch-address(1)**\r
+diff --git a/doc/man1/notmuch.rst b/doc/man1/notmuch.rst\r
+index 9710294..98590a4 100644\r
+--- a/doc/man1/notmuch.rst\r
++++ b/doc/man1/notmuch.rst\r
+@@ -88,8 +88,8 @@ Several of the notmuch commands accept search terms with a common\r
+ syntax. See **notmuch-search-terms**\ (7) for more details on the\r
+ supported syntax.\r
\r
+-The **search**, **show** and **count** commands are used to query the\r
+-email database.\r
++The **search**, **show**, **address** and **count** commands are used\r
++to query the email database.\r
\r
+ The **reply** command is useful for preparing a template for an email\r
+ reply.\r
+@@ -128,7 +128,8 @@ SEE ALSO\r
+ **notmuch-config(1)**, **notmuch-count(1)**, **notmuch-dump(1)**,\r
+ **notmuch-hooks(5)**, **notmuch-insert(1)**, **notmuch-new(1)**,\r
+ **notmuch-reply(1)**, **notmuch-restore(1)**, **notmuch-search(1)**,\r
+-**notmuch-search-terms(7)**, **notmuch-show(1)**, **notmuch-tag(1)**\r
++**notmuch-search-terms(7)**, **notmuch-show(1)**, **notmuch-tag(1)**,\r
++***notmuch-address(1)**\r
\r
+ The notmuch website: **http://notmuchmail.org**\r
\r
+diff --git a/notmuch-client.h b/notmuch-client.h\r
+index e1efbe0..5e0d475 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 f115359..69938d6 100644\r
+--- a/notmuch-search.c\r
++++ b/notmuch-search.c\r
+@@ -23,17 +23,18 @@\r
+ #include "string-util.h"\r
\r
+ typedef enum {\r
++    /* Search command */\r
+     OUTPUT_SUMMARY    = 1 << 0,\r
+     OUTPUT_THREADS    = 1 << 1,\r
+     OUTPUT_MESSAGES   = 1 << 2,\r
+     OUTPUT_FILES      = 1 << 3,\r
+     OUTPUT_TAGS               = 1 << 4,\r
++\r
++    /* Address command */\r
+     OUTPUT_SENDER     = 1 << 5,\r
+     OUTPUT_RECIPIENTS = 1 << 6,\r
+ } output_t;\r
\r
+-#define OUTPUT_ADDRESS_FLAGS (OUTPUT_SENDER | OUTPUT_RECIPIENTS)\r
+-\r
+ typedef enum {\r
+     NOTMUCH_FORMAT_JSON,\r
+     NOTMUCH_FORMAT_TEXT,\r
+@@ -554,39 +555,42 @@ _notmuch_search_cleanup (search_context_t *ctx)\r
+     talloc_free (ctx->format);\r
+ }\r
\r
++static search_context_t search_context = {\r
++    .format_sel = NOTMUCH_FORMAT_TEXT,\r
++    .exclude = NOTMUCH_EXCLUDE_TRUE,\r
++    .sort = NOTMUCH_SORT_NEWEST_FIRST,\r
++    .output = 0,\r
++    .offset = 0,\r
++    .limit = -1, /* unlimited */\r
++    .dupe = -1,\r
++};\r
++\r
++static const notmuch_opt_desc_t common_options[] = {\r
++    { NOTMUCH_OPT_KEYWORD, &search_context.sort, "sort", 's',\r
++      (notmuch_keyword_t []){ { "oldest-first", NOTMUCH_SORT_OLDEST_FIRST },\r
++                            { "newest-first", NOTMUCH_SORT_NEWEST_FIRST },\r
++                            { 0, 0 } } },\r
++    { NOTMUCH_OPT_KEYWORD, &search_context.format_sel, "format", 'f',\r
++      (notmuch_keyword_t []){ { "json", NOTMUCH_FORMAT_JSON },\r
++                            { "sexp", NOTMUCH_FORMAT_SEXP },\r
++                            { "text", NOTMUCH_FORMAT_TEXT },\r
++                            { "text0", NOTMUCH_FORMAT_TEXT0 },\r
++                            { 0, 0 } } },\r
++    { NOTMUCH_OPT_INT, &notmuch_format_version, "format-version", 0, 0 },\r
++    { 0, 0, 0, 0, 0 }\r
++};\r
++\r
+ int\r
+ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
+ {\r
+-    search_context_t search_context = {\r
+-      .format_sel = NOTMUCH_FORMAT_TEXT,\r
+-      .exclude = NOTMUCH_EXCLUDE_TRUE,\r
+-      .sort = NOTMUCH_SORT_NEWEST_FIRST,\r
+-      .output = 0,\r
+-      .offset = 0,\r
+-      .limit = -1, /* unlimited */\r
+-      .dupe = -1,\r
+-    };\r
+     search_context_t *ctx = &search_context;\r
+     int opt_index, ret;\r
\r
+     notmuch_opt_desc_t options[] = {\r
+-      { NOTMUCH_OPT_KEYWORD, &ctx->sort, "sort", 's',\r
+-        (notmuch_keyword_t []){ { "oldest-first", NOTMUCH_SORT_OLDEST_FIRST },\r
+-                                { "newest-first", NOTMUCH_SORT_NEWEST_FIRST },\r
+-                                { 0, 0 } } },\r
+-      { NOTMUCH_OPT_KEYWORD, &ctx->format_sel, "format", 'f',\r
+-        (notmuch_keyword_t []){ { "json", NOTMUCH_FORMAT_JSON },\r
+-                                { "sexp", NOTMUCH_FORMAT_SEXP },\r
+-                                { "text", NOTMUCH_FORMAT_TEXT },\r
+-                                { "text0", NOTMUCH_FORMAT_TEXT0 },\r
+-                                { 0, 0 } } },\r
+-      { NOTMUCH_OPT_INT, &notmuch_format_version, "format-version", 0, 0 },\r
+       { NOTMUCH_OPT_KEYWORD_FLAGS, &ctx->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
+@@ -599,6 +603,7 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
+       { NOTMUCH_OPT_INT, &ctx->offset, "offset", 'O', 0 },\r
+       { NOTMUCH_OPT_INT, &ctx->limit, "limit", 'L', 0  },\r
+       { NOTMUCH_OPT_INT, &ctx->dupe, "duplicate", 'D', 0  },\r
++      { NOTMUCH_OPT_INHERIT, &common_options, NULL, 0, 0 },\r
+       { 0, 0, 0, 0, 0 }\r
+     };\r
\r
+@@ -623,8 +628,7 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
+       ctx->output == OUTPUT_THREADS)\r
+       ret = do_search_threads (ctx);\r
+     else if (ctx->output == OUTPUT_MESSAGES ||\r
+-           ctx->output == OUTPUT_FILES ||\r
+-           (ctx->output & OUTPUT_ADDRESS_FLAGS && !(ctx->output & ~OUTPUT_ADDRESS_FLAGS)))\r
++           ctx->output == OUTPUT_FILES)\r
+       ret = do_search_messages (ctx);\r
+     else if (ctx->output == OUTPUT_TAGS)\r
+       ret = do_search_tags (ctx);\r
+@@ -637,3 +641,40 @@ notmuch_search_command (notmuch_config_t *config, int argc, char *argv[])\r
\r
+     return ret ? EXIT_FAILURE : EXIT_SUCCESS;\r
+ }\r
++\r
++int\r
++notmuch_address_command (notmuch_config_t *config, int argc, char *argv[])\r
++{\r
++    search_context_t *ctx = &search_context;\r
++    int opt_index, ret;\r
++\r
++    notmuch_opt_desc_t options[] = {\r
++      { NOTMUCH_OPT_KEYWORD_FLAGS, &ctx->output, "output", 'o',\r
++        (notmuch_keyword_t []){ { "sender", OUTPUT_SENDER },\r
++                                { "recipients", OUTPUT_RECIPIENTS },\r
++                                { 0, 0 } } },\r
++      { NOTMUCH_OPT_KEYWORD, &ctx->exclude, "exclude", 'x',\r
++        (notmuch_keyword_t []){ { "true", NOTMUCH_EXCLUDE_TRUE },\r
++                                { "false", NOTMUCH_EXCLUDE_FALSE },\r
++                                { 0, 0 } } },\r
++      { NOTMUCH_OPT_INHERIT, &common_options, NULL, 0, 0 },\r
++      { 0, 0, 0, 0, 0 }\r
++    };\r
++\r
++    opt_index = parse_arguments (argc, argv, options, 1);\r
++    if (opt_index < 0)\r
++      return EXIT_FAILURE;\r
++\r
++    if (! ctx->output)\r
++      ctx->output = OUTPUT_SENDER | OUTPUT_RECIPIENTS;\r
++\r
++    if (_notmuch_search_prepare (ctx, config,\r
++                               argc - opt_index, argv + opt_index))\r
++      return EXIT_FAILURE;\r
++\r
++    ret = do_search_messages (ctx);\r
++\r
++    _notmuch_search_cleanup (ctx);\r
++\r
++    return ret ? EXIT_FAILURE : EXIT_SUCCESS;\r
++}\r
+diff --git a/notmuch.c b/notmuch.c\r
+index dcda039..0fac099 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