Commit graph

83 commits

Author SHA1 Message Date
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
Carl Worth
6dcb7592e3 notmuch search: Add a new --output=(summary|threads|messages|tags) option.
This can be handy for scripts which need to extract just a thread ID from
a search term, for example.
2010-10-28 11:35:16 -07:00
Carl Worth
14a2227f77 notmuch search: Fix to handle failure of notmuch_query_search_threads.
Now that notmuch_query_search_threads can return NULL, (for example,
due to a Xapian exception), we need to handle that case (rather than
just segfault). It's simple enough to just return a non-zero exit
code.
2010-10-22 18:03:39 -07:00
Dirk Hohndel
6ddc2e0442 removed unused variables
trivial compiler warning fix

Signed-off-by: Dirk Hohndel <hohndel@infradead.org>
2010-04-23 17:53:52 -07:00
Carl Worth
e6e0cb942c notmuch search: Fix timezone of timestamp in --format=json output
This is one of those cases that I move love. Deleting code fixes
a bug, (test suite now passes again).
2010-04-22 17:12:07 -07:00
Carl Worth
4e5d2f22db lib: Rename iterator functions to prepare for reverse iteration.
We rename 'has_more' to 'valid' so that it can function whether
iterating in a forward or reverse direction. We also rename
'advance' to 'move_to_next' to setup parallel naming with
the proposed functions 'move_to_first', 'move_to_last', and
'move_to_previous'.
2010-03-09 09:22:29 -08:00
Carl Worth
5171831813 notmuch search: Use "thread" rather than "id" when formatting with JSON
The text output uses thread:<foo>, (which is a syntax directly supported
by "notmuch show"), so make the json output be "thread", "<foo>" rather
than "id", "<foo>". This should help avoid confusion of thread IDs with
message IDs, (which do use the "id" prefix in searches).
2010-02-23 12:50:46 -08:00
Scott Robinson
6ce2bf68f5 Add an "--format=(json|text)" command-line option to both notmuch-search and notmuch-show.
In the case of notmuch-show, "--format=json" also implies
"--entire-thread" as the thread structure is implicit in the emitted
document tree.

As a coincidence to the implementation, multipart message ID numbers are
now incremented with each part printed. This changes the previous
semantics, which were unclear and not necessary related to the actual
ordering of the message parts.
2010-02-23 12:01:12 -08:00
Carl Worth
1fd8b7866f notmuch search: Remove the chunked-searching hack.
This was a poor workaround around the fact that the existing
notmuch_threads_t object is implemented poorly. It's got a fine
iterartor-based interface, but the implementation does all of the
work up-front in _create rather than doing the work incrementally
while iterating.

So to start fixing this, first get rid of all the hacks we had working
around this. This drops the --first and --max-threads options from the
search command, (but hopefully nobody was using them
anyway---notmuch.el certainly wasn't).
2009-11-23 20:17:37 -08:00
Carl Worth
bc0a873b18 search : Extend "intial burst" optimization to return all results by chunks
This way, the user gets a steady (but bursty) stream of reults. We
double the chunk size each time since each successive chunk has to
redo work from all previous chunks.

Of course, the overall time is thereby slower, as the price we pay for
increased responsiveness. With a search returning about 17000 thread
results I measured a total time of 48.8 seconds before this change and
58.4 seconds afterwards.
2009-11-23 18:14:47 +01:00
Carl Worth
637f99d8f3 Rename NOTMUCH_DATABASE_MODE_WRITABLE to NOTMUCH_DATABASE_MODE_READ_WRITE
And correspondingly, READONLY to READ_ONLY.
2009-11-21 22:10:18 +01:00
Chris Wilson
f379aa5284 Permit opening the notmuch database in read-only mode.
We only rarely need to actually open the database for writing, but we
always create a Xapian::WritableDatabase. This has the effect of
preventing searches and like whilst updating the index.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Acked-by: Carl Worth <cworth@cworth.org>
2009-11-21 22:04:49 +01:00
Carl Worth
306635c27d notmuch search: Avoid infinite stream of exceptions from "notmuch search"
That is, give a nice error message and exit if no search terms are
provided. Thanks to Priit Laes <plaes@plaes.org> for reporting the
error and providing an early version of the fix.
2009-11-18 03:29:30 -08:00
Ingmar Vanhassel
2ce25b93a7 Typsos 2009-11-18 03:21:36 -08:00
Carl Worth
3334865725 notmuch search: Change default search order to be newest messages first.
This is what most people want for a _search_ command. It's often
different for actually reading mail in an inbox, (where it makes more
sense to have results displayed in chronological order), but in such a
case, ther user is likely using an interface that can simply pass the
--sort=oldest-first option to "notmuch search".

Here we're also change the sort enum from NOTMUCH_SORT_DATE and
NOTMUCH_SORT_DATE_REVERSE to NOTMUCH_SORT_OLDEST_FIRST and
NOTMUCH_SORT_NEWEST_FIRST. Similarly we replace the --reverse option
to "notmuch search" with two options: --sort=oldest-first and
--sort=newest-first.

Finally, these changes are all tracked in the emacs interface, (which
has no change in its behavior).
2009-11-17 20:58:30 -08:00
Carl Worth
5dec429f45 notmuch search: Return first 100 results as quickly as possible.
This is one of those cases where total time is not the metric of
interest. We increase the total time of the search, (by doing some
redundant work for the initial threads). But more significantly, we
give the user *some* results nearly instantaneously, (so that the user
might see the result of interest without ever even waiting for the
complete results to come in).
2009-11-17 19:11:05 -08:00
Carl Worth
f7b49d658a notmuch search: Add support for a --reverse option to reverse sort order.
Note that the difference between thread results in date order and
thread results in reverse-date order is not simply a matter of
reversing the final results. When sorting in date order, the threads
are sorted by the oldest message in the thread. When sorting in
reverse-date order, the threads are sorted by the newest message in
the thread.

This difference means that we might want an explicit option in the
interface to reverse the order, (even though the default will be to
display the inbox in date order and global searches in reverse-date
order).
2009-11-12 22:35:16 -08:00
Carl Worth
c168e24174 notmuch search: Print the number of matched/total messages for each thread.
Note that we don't print the number of *unread* messages, but instead
the number of messages that matched the search terms. This is in
keeping with our philosophy that the inbox is nothing more than a
search view. If we search for messages with an inbox tag, then that's
what we'll get a count of. (And if somebody does want to see unread
counts, then they can search for the "unread" tag.)

Getting the number of matched messages is really nice when doing
historical searches. For example in a search like:

	notmuch search tag:sent

(where the "sent" tag has been applied to all messages originating
from the user's email address)---here it's really nice to be able to
see a thread where the user just mentioned one point [1/13] vs. really
getting involved in the discussion [10/29].
2009-11-12 22:01:44 -08:00
Carl Worth
fc2053b022 notmuch search: Add --first and --max-threads options for incremental search.
This time, things are actually tested. The current results aren't
exactly the same as previous results since the incremental search
doesn't necessarily see all the new messages that pertain to the
thread. This means that some author names are missing.

I plan to fix this by doing an additional database search for all
messages in each thread. Of course, this will also be different than
before since now the result will display *all* authors in the thread
(rather than only those that matched the search) but that's probably
what we really want to display anyway.
2009-11-12 20:47:12 -08:00
Carl Worth
93dcc3b695 libnotmuch: Underlying support for doing partial-results searches.
The library interface now allows the caller to do incremental searches,
(such as one page of results at a time). Next we'll just need to hook
this up to "notmuch search" and the emacs interface.
2009-11-12 16:47:27 -08:00
Carl Worth
2f4c587474 notmuch search: Print the names of author of matched emails.
It's important to have the names present for determining whether a
thread is worth reading or not. We may want to think about
abbreviating the list somehow if it is excessively long (or redundant
as in bugzilla-daemon, bugzilla-daemon, bugzilla-daemon, etc.).
2009-11-12 09:59:47 -08:00
Carl Worth
13569ad6c9 Unbreak several notmuch commands after the addition of configuration.
All of the following commands:

	notmuch dump
	notmuch reply
	notmuch restore
	notmuch search
	notmuch show
	notmuch tag

were calling notmuch_database_open with an argument of NULL. This was
a legitimate call until the recent addition of configuration, after
which it is expected that all commands will lookup the correct path in
the configuration file. So fix all these commands to do that.

Also, while touching all of these commands, we fix them to use the
talloc context that is passed in rather than creating a local talloc
context. We also switch from using goto for return values, to doing
direct returns as soon as an error is detected, (which can be leak
free thanks to talloc).
2009-11-11 20:29:30 -08:00
Carl Worth
50144f95ca notmuch: Break notmuch.c up into several smaller files.
Now that the client sources are alone here in their own directory,
(with all the library sources down inside the lib directory), we can
break the client up into multiple files without mixing the files up.
The hope is that these smaller files will be easier to manage and
maintain.
2009-11-10 12:03:05 -08:00