Commit graph

72 commits

Author SHA1 Message Date
David Bremner
84d3b15d25 lib: add "verbose" versions of notmuch_database_{open,create}
The compatibility wrapper ensures that clients calling
notmuch_database_open will receive consistent output for now.

The changes to notmuch-{new,search} and test/symbol-test are just to
make the test suite pass.

The use of IGNORE_RESULT is justified by two things. 1) I don't know
what else to do.  2) asprintf guarantees the output string is NULL if
an error occurs, so at least we are not passing garbage back.
2015-03-29 00:34:15 +01:00
Jani Nikula
a9e0786f72 cli: fix clang build warnings
Fix the following warning produced by clang 3.5.0:

notmuch-search.c:730:25: warning: initializing 'void *' with an
expression of type 'const notmuch_opt_desc_t (*)[4]' discards
qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
        { NOTMUCH_OPT_INHERIT, &common_options, NULL, 0, 0 },
                               ^~~~~~~~~~~~~~~
1 warning generated.
2015-02-25 23:11:08 +01:00
Tomi Ollila
0d8251dbe2 cli: notmuch address option defaults update
When no --output option were given, change default to display senders
only.

When only --count option is given, display senders (in contrary to not
displaying anything).

Document that --count with --sort=**order** is not supported option
combination.

Clean up some whitespace in the documentation.

One test updated to have --output=count without sender nor recipient
output option.
2014-11-09 10:09:51 +01:00
Michal Sojka
a5a6859197 cli: address: Add --output=count
This output prints how many times was each address encountered during
search.
2014-11-05 23:25:05 +01:00
Michal Sojka
4176e527fc cli: address: Do not output duplicate addresses
This filters out duplicate addresses from address command output.

It also also adds tests for the address command.

The code here is an extended version of a patch from Jani Nikula.
2014-11-05 23:23:01 +01:00
Michal Sojka
5c32365d87 cli: search: Convert --output to keyword argument
Now, when address related outputs are in a separate command, it makes
no sense to combine multiple --output options in search command line.
Using switch statement to handle different outputs is more readable
than a series of if statements.
2014-11-05 23:20:17 +01:00
Michal Sojka
5c27136e64 cli: Introduce "notmuch address" command
This moves address-related functionality from search command to the
new address command. The implementation shares almost all code and
some command line options.

Options --offset and --limit were intentionally not included in the
address command, because they refer to messages numbers, which users
do not see in the output. This could confuse users because, for
example, they could see more addresses in the output that what was
specified with --limit. This functionality can be correctly
reimplemented for address subcommand later.

Also useless values of --exclude flag were not included in the address
command.

This was inspired by a patch from Jani Nikula.
2014-11-05 23:19:12 +01:00
Michal Sojka
f0dfceaf90 cli: search: Split notmuch_search_command to smaller functions
In a subsequent commit, these functions will be used to share some
functionality between search and address commands.
2014-11-05 23:14:24 +01:00
Michal Sojka
5e16b94a23 cli: search: Convert ctx. to ctx->
In the next commit, notmuch_search_command will be refactored to
several smaller functions. In order to simplify the next commit to
verbatim move of several lines to new functions with search_context_t*
argument, we convert all references to this structure to pointer
dereferences. To do so we rename the context variable and use the
original name ctx as the pointer to the renamed structure.
2014-11-05 23:11:20 +01:00
Michal Sojka
33f9109fd3 cli: search: Move more variables into search_context_t
In order to share some command line options between search and address
subcommands we need to add corresponding variables to the context
structure. While we are at it, we also add notmuch_database_t to unify
parameters of all do_search_* functions and to simplify subsequent
commits.

Otherwise, there are no functional changes.
2014-11-05 23:11:09 +01:00
Michal Sojka
15d39e424e cli: search: Rename options to context
In the next commit the options structure will be extended by
non-option variables. Therefore we need a more generic name.

Just text replacement, no other changes.
2014-11-05 23:09:49 +01:00
Jani Nikula
4366b9b88c cli: add support for notmuch search --duplicate=N with --output=messages
Print the message IDs of all messages matching the search terms that
have at least N files associated with them.
2014-11-02 19:42:12 +01:00
Michal Sojka
3cc8ed5978 cli: search: Add --output={sender,recipients}
The new outputs allow printing senders, recipients or both of matching
messages. To print both, the user can use --output=sender and
--output=recipients simultaneously.

Currently, the same address can appear multiple times in the output.
The next commit will change this. For this reason, tests are
introduced there.

We use mailbox_t rather than InternetAddressMailbox because we will
need to extend it in a following commit.

This code is based on a patch from Jani Nikula.
2014-11-01 08:02:58 +01:00
Michal Sojka
db307459fb cli: search: Convert --output to keyword-flag argument
This converts "notmuch search" to use the recently introduced
keyword-flag argument parser. At this point, it only makes the code
slightly less readable but following commits that add new --output
keywords will profit from this.
2014-11-01 08:02:35 +01:00
Michal Sojka
dc39811948 cli: search: Refactor passing of command line options
Many functions that implement the search command need to access command
line options. Instead of passing each option in a separate variable, put
them in a structure and pass only this structure.

This will become handy in the following commits.
2014-11-01 08:01:59 +01:00
Jani Nikula
029790d3ff util: make sanitize string available in string util for reuse
No functional changes.
2014-03-09 10:13:30 -03:00
Jani Nikula
6d0a17c46e cli: sanitize tabs and newlines to spaces in notmuch search
Sanitize tabs and newlines to spaces rather than question marks in
--output=summary --format=text output.

This will also hide any difference in unfolding a header that has been
folded with a tab. Our own header parser replaces tabs with spaces,
while gmime would retain the tab.
2014-03-09 10:12:52 -03:00
Jani Nikula
c745377306 cli: clean up exit status code returned by the cli commands
Apart from the status codes for format mismatches, the non-zero exit
status codes have been arbitrary. Make the cli consistently return
either EXIT_SUCCESS or EXIT_FAILURE.
2014-01-18 14:45:26 -04:00
Austin Clements
abeac48522 search: Add stable queries to thread search results
These queries will match exactly the set of messages currently in the
thread, even if more messages later arrive.  Two queries are provided:
one for matched messages and one for unmatched messages.

This can be used to fix race conditions with tagging threads from
search results.  While tagging based on a thread: query can affect
messages that arrived after the search, tagging based on stable
queries affects only the messages the user was shown in the search UI.

Since we want clients to be able to depend on the presence of these
queries, this ushers in schema version 2.
2013-11-08 20:43:29 -04:00
Jani Nikula
cc4fb2c172 cli: add --duplicate=N option to notmuch search
Effective with --output=files, output the Nth filename associated with
each message matching the query (N is 1-based). If N is greater than
the number of files associated with the message, don't print anything.
2013-08-24 11:41:55 +02:00
Peter Wang
0e035e1ccd cli: use notmuch_exclude_t in option parser
Use notmuch_exclude_t constants directly instead of a redundant
enumeration while parsing search --exclude keyword arguments.
2013-06-24 22:53:34 -07:00
Mark Walters
d29d7e1ee2 lib: add NOTMUCH_EXCLUDE_FLAG to notmuch_exclude_t
Add NOTMUCH_EXCLUDE_FLAG to notmuch_exclude_t so that it can
cover all four values of search --exclude in the cli.

Previously the way to avoid any message being marked excluded was to
pass in an empty list of excluded tags: since we now have an explicit
option we might as well honour it.

The enum is in a slightly strange order as the existing FALSE/TRUE
options correspond to the new
NOTMUCH_EXCLUDE_FLAG/NOTMUCH_EXCLUDE_TRUE options so this means we do
not need to bump the version number.

Indeed, an example of this is that the cli count and show still use
FALSE/TRUE and still work.
2013-06-24 22:53:16 -07:00
Mark Walters
e691783b3b cli: add --exclude=all option to notmuch-search.c
Add a --exclude=all option to notmuch search.
2013-05-13 21:32:14 -03:00
Jani Nikula
4ef2106792 cli: move config open/close to main() from subcommands
This allows specifying config file as a top level argument to notmuch,
and generally makes it possible to override config file options in
main(), without having to touch the subcommands.

If the config file does not exist, one will be created for the notmuch
main command and setup and help subcommands. Help is special in this
regard; the config is created just to avoid errors about missing
config, but it will not be saved.

This also makes notmuch config the talloc context for subcommands.
2013-03-08 07:54:41 -04:00
Jani Nikula
e76f6517de cli: config: make notmuch_config_open() "is new" parameter input only
We now have a notmuch_config_is_new() function to query whether a
config was created or not. Change the notmuch_config_open() is_new
parameter into boolean create_new to determine whether the function
should create a new config if one doesn't exist. This reduces the
complexity of the API.
2013-03-07 09:39:12 -04:00
Jani Nikula
69408c35ff cli: add --format=text0 to notmuch search
Add new format text0, which is otherwise the same as text, but use the
null character as separator instead of the newline character. This is
similar to find(1) -print0 option, and works together with the
xargs(1) -0 option.
2012-12-18 17:04:06 -04:00
Austin Clements
3152cf4b12 search: Support --format-version 2012-12-16 17:20:43 -04:00
Peter Feigl
102f58d7a4 Use the S-Expression structured printer in notmuch-show, notmuch-reply and notmuch-search.
This patch uses the new S-Expression printer in the notmuch CLI (show,
search and reply). You can now use --format=sexp for any of them.
2012-12-08 09:30:19 -04:00
craven@gmx.net
10ab2b5703 Use the structured formatters in notmuch-search.c.
This patch switches from the current ad-hoc printer to the structured
formatters in sprinter.h, sprinter-text.c and sprinter-json.c.

The JSON tests are changed slightly in order to make them PASS for the
new structured output formatter.

The text tests pass without adaptation.
2012-07-24 09:27:09 -03:00
Austin Clements
5fddc07dc3 lib/cli: Make notmuch_database_open return a status code
It has been a long-standing issue that notmuch_database_open doesn't
return any indication of why it failed.  This patch changes its
prototype to return a notmuch_status_t and set an out-argument to the
database itself, like other functions that return both a status and an
object.

In the interest of atomicity, this also updates every use in the CLI
so that notmuch still compiles.  Since this patch does not update the
bindings, the Python bindings test fails.
2012-05-05 10:11:57 -03:00
Justus Winter
6f7469f547 Use notmuch_database_destroy instead of notmuch_database_close
Adapt the notmuch binaries source to the notmuch_database_close split.

Signed-off-by: Justus Winter <4winter@informatik.uni-hamburg.de>
2012-04-28 09:27:33 -03:00
Mark Walters
fd62a25f91 cli: move search to the new --exclude= naming scheme.
This commit replaces the --no-exclude option with a
--exclude=(true|false|flag) option. The default is to omit the
excluded messages.

The flag option only makes sense if output=summary (as otherwise there
is nowhere to print the flag). In summary output exclude=false and
exclude=flag give almost identical output:
they differ in that with the exclude=flag option the match count
(i.e., the x in [x/n] in the output) is the number of matching
non-excluded messages rather than the number of matching messages.

Note this changes the default for output=summary when no --exclude=
option is given: it used to default to flag and now defaults to true
(i.e. omit excluded messages). This is neccesary to keep the cli
output uncluttered and for speed reasons.
2012-04-07 23:05:41 -03:00
Mark Walters
7a1beb9e7c cli: omit excluded messages in results where appropriate.
In all cases of notmuch count/search/show where the results returned
cannot reflect the exclude flag return just the matched not-excluded
results. If the caller wishes to have all the matched results (i.e.,
including the excluded ones) they should call with the
--no-exclude option.

The relevant cases are
    count: both threads and messages
    search: all cases except the summary view
    show: mbox format
2012-03-02 08:37:32 -04:00
Mark Walters
d845662970 cli: add --no-exclude option to count and search.
This option turns off the exclusion so all matching messages are
returned. We do not need to add this to notmuch-show as that does not
(yet) exclude.
2012-03-02 08:24:38 -04:00
Austin Clements
661c357123 Document the JSON schemata used by show and search 2012-02-27 22:32:49 -04:00
Pieter Praet
649a9f5f3a search: rename auto_exclude_tags to {search, }exclude_tags
All other config-related functions and args include the section
title in their name, so for the sake of consistency, mirror that.

Also, the "auto"matic part is a given, so that was dropped.
2012-01-23 19:17:16 -04:00
Austin Clements
42a9079928 search: Support automatic tag exclusions
This adds a "search" section to the config file and an
"auto_tag_exclusions" setting in that section.  The search and count
commands pass tag tags from the configuration to the library.
2012-01-16 21:06:35 -04:00
David Bremner
5b3b1f44ed notmuch-search: convert to command-line-arguments
The switch on format_sel is slightly clunky, but it doesn't seem worth
special casing argument processing for function pointers, when I think
the function pointer approach will be modified/abandoned.
2011-12-08 20:24:24 -04:00
pazz
80936b5f58 json: date_relative for threads
include the date_relative field in the
json formated output of notmuch search
2011-12-07 21:20:49 -04:00
Jani Nikula
796b629c3b cli: add options --offset and --limit to notmuch search
Add options --offset=[-]N and --limit=M to notmuch search to determine the
first result and maximum number of results to display.

Option --limit=M limits the maximum number of results to display to M.

Option --offset=[-]N skips the first N results; with the leading '-' skip
until the Nth result from the end.

Note that --offset with a negative N for thread or summary output requires
counting the number of matching threads in advance.

Signed-off-by: Jani Nikula <jani@nikula.org>
2011-11-15 19:17:24 -04:00
David Bremner
61f0a5b8ee cli: change argument parsing convention for subcommands
previously we deleted the subcommand name from argv before passing to
the subcommand. In this version, the deletion is done in the actual
subcommands. Although this causes some duplication of code, it allows
us to be more flexible about how we parse command line arguments in
the subcommand, including possibly using off-the-shelf routines like
getopt_long that expect the name of the command in argv[0].
2011-10-22 19:42:54 -03:00
Mark Anderson
d752509abf search --output=files: Output all filenames for each matching message
Messages in the database can have multiple files associated with a
single message-id, but until now only one filename for each message
has been reported by "notmuch search --output=files"

Signed-off-by: Mark Anderson <ma.skies@gmail.com>
2011-06-28 12:14:19 -07:00
Daniel Kahn Gillmor
8a7d4aa1b1 avoid segfault when calling sanitize_string() on NULL
Signed-off-by: Jameson Graef Rollins <jrollins@finestructure.net>
2011-06-03 12:30:55 -07:00
Andreas Amann
f954b69251 Sanitize "Subject:" and "Author:" fields to not contain control characters in notmuch-search
When a Subject field contained encoded CRLF sequences, these sequences
would appear unfiltered in the output of notmuch search. This confused
the notmuch emacs interface leading to "Unexpected Output"
messages. This is now fixed by replacing all characters with ASCII
code less than 32 with a question mark.

Signed-off-by: Jameson Graef Rollins <jrollins@finestructure.net>
2011-06-01 21:41:24 -07:00
Jameson Graef Rollins
049ac914f9 Fix missing final newline in notmuch search output
A previous commit to fix json formatting for null results
(0b1ddc5f66) accidentally introduced a
regression that removed trailing newlines for non-json output.  (There
wasn't a good test for this previously, but there is now).  The
problem is due to the fundamental differences in formatting between
the json and non-json outputs.  The only way to fix this was to add a
new formatting field that represents the string to output at the end
of a null result.

All output formatting tests should pass now, (in particular, the 4
recent test failures introduced to show this bug).
2011-06-01 16:30:29 -07:00
Carl Worth
0b1ddc5f66 json: Fix search result with no matches to be a valid json object.
In the original json code, search matching nothing would return a
valid, empty json array (that is, "[]"). I broke this in commit
6dcb7592e3 when adding support for
--output=threads|messages|tags. This time, while fixing the bug also
add a test to the test suite to help avoid future regressions.
2011-03-09 15:10:03 -08:00
Carl Worth
b64afb1ab9 notmuch search: Clean up some memory leaks during search loop.
With talloc, we were already freeing all memory by the time we exited
the loop, but that didn't help with excess use of memory inside the
loop, (which was mostly from tallocing some objects with the incorrect
parent).

Thanks to Andrew Tridgell for sitting next to me and teaching me to
use talloc_report_full to find these leaks.
2011-01-26 15:59:19 +10:00
Carl Worth
fb4ded1cc9 notmuch search: Fix missing final newline in "notmuch search --output=tags"
As mentioned in the recent test commits, this also fixes the missing
'[' and ']' characters in the --format=json variant of "notmuch search
--output=tags" as well.
2010-11-23 17:58:00 -08:00
Michal Sojka
772bde847c Print nothing when search result is empty
This change affects both text and json formats. Now, text format
behaves as before commit 6dcb7592, but json format is changed.
Earlier, the empty search returned '[]', now it returns ''. The emacs
interface seems not to be affected by this change.
2010-11-04 12:36:04 -07:00
Carl Worth
5331161749 notmuch search: Add a new "notmuch search --output=files"
Yet another thing that will be extremely handy for scripts.
2010-10-28 11:35:54 -07:00