Commit graph

38 commits

Author SHA1 Message Date
David Bremner
0018a8d787 cli: define shared options, use for --help and --version
Unfortunately it seems trickier to support --config globally

The non-trivial changes are in notmuch.c; most of the other changes
consists of blindly inserting two lines into every subcommand.
2015-06-01 07:32:54 +02:00
David Bremner
4c62d9366a restore: transparently support gzipped input
We rely completely on zlib to do the right thing in detecting gzipped
input. Since our dump format is chosen to be 7 bit ascii, this should
be fine.
2014-04-12 07:59:44 -03:00
Jani Nikula
3863755f6d cli: abstract dump file open from the dump command
Also expose the dump function to the rest of notmuch. No functional
changes, except for slight improvement in error handling.
2014-03-30 19:23:16 -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
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
Austin Clements
425e2bc812 dump/restore: Use Xapian queries for batch-tag format
This switches the new batch-tag format away from using a home-grown
hex-encoding scheme for message IDs in the dump to simply using Xapian
queries with Xapian quoting syntax.

This has a variety of advantages beyond presenting a cleaner and more
consistent interface.  Foremost is that it will dramatically simplify
the quoting for batch tagging, which shares the same input format.
While the hex-encoding is no better or worse for the simple ID queries
used by dump/restore, it becomes onerous for general-purpose queries
used in batch tagging.  It also better handles strange cases like
"id:foo and bar", since this is no longer syntactically valid.
2013-01-06 22:40:32 -04:00
Austin Clements
baca1219af restore: Make missing messages non-fatal (again)
Previously, restore would abort if a message ID in the dump was
missing.  Furthermore, it would only report this as a warning.  This
patch makes it distinguish abort-worthy lookup failures like
out-of-memory from non-fatal failure to find a message ID.  The former
is reported as an error and causes restore to abort, while the latter
is reported as a warning and does not cause an abort.

This restores 0.14's non-fatal handling of missing message IDs in
restore (though 0.14 also considered serious errors non-fatal; we
retain the new and better handling of serious errors).
2013-01-06 22:39:23 -04:00
David Bremner
d705a6a45b notmuch-restore: handle empty input file, leading blank lines and comments.
This patch corrects several undesirable behaviours:

1) Empty files were not detected, leading to buffer read overrun.

2) An initial blank line cause restore to silently abort

3) Initial comment line caused format detection to fail
2013-01-06 10:04:19 -04:00
David Bremner
e40bb1561a notmuch-restore: use debug version of talloc_strndup
This gives line numbers for better debugging.
2012-12-30 21:12:11 -04:00
David Bremner
0919ea4c55 notmuch-restore: allocate a temporary talloc context for each line parsed.
This lets the high level code in notmuch restore be ignorant about
what the lower level code is doing as far as allocating memory.
2012-12-22 23:19:43 -04:00
David Bremner
ba4e856529 tag-utils: use the tag_opt_list_t as talloc context, if possible.
The memory usage discipline of tag_op_list_t is never to free the
internal array of tag operations before freeing the whole list, so it
makes sense to take advantage of hierarchical de-allocation by talloc.

By not relying on the context passed into tag_parse_line, we can allow
tag_op_list_t structures to live longer than that context.
2012-12-22 23:13:15 -04:00
David Bremner
77b4ec70ec notmuch-restore: fix return value propagation
Previously notmuch_restore_command returned 0 if tag_message returned
a non-zero (failure) value. This is wrong, since non-zero status
indicates something mysterious went wrong with retrieving the message,
or applying it.

There was also a failure to check or propagate the return value from
tag_op_list_apply in tag_message.
2012-12-22 23:11:47 -04:00
David Bremner
ea85725450 notmuch-restore: normalize case of error messages.
In English, (unlike German) one does not capitalize the first word
after a colon.
2012-12-09 13:33:34 -04:00
David Bremner
33434d76f3 notmuch-restore: add support for input format 'batch-tag'
This can be enabled with the new --format=batch-tag command line
option to "notmuch restore". The input must consist of lines of the
format:

    +<tag>|-<tag> [...] [--] id:<msg-id>

Each line is interpreted similarly to "notmuch tag" command line
arguments. The delimiter is one or more spaces ' '. Any characters in
<tag> and <search-terms> MAY be hex encoded with %NN where NN is the
hexadecimal value of the character. Any ' ' and '%' characters in
<tag> and <msg-id> MUST be hex encoded (using %20 and %25,
respectively). Any characters that are not part of <tag> or
<search-terms> MUST NOT be hex encoded.

Leading and trailing space ' ' is ignored. Empty lines and lines
beginning with '#' are ignored.

Commit message mainly stolen from Jani's batch tagging commit, to
follow.
2012-12-09 13:33:34 -04:00
David Bremner
660e1b6437 notmuch-restore: tidy formatting
This is again the work of uncrustify.

I remember there is some controversy about "! foo" versus "!foo", but
in context I think "! foo" looks OK. Also, for functions "! foo
(blah)" seems better than "!foo (blah)".
2012-11-16 08:46:07 -04:00
David Bremner
5aba32208f notmuch-restore: fix error message for extra positional parameter.
Note that a single positional parameter will take this code path also,
so the old message really makes no sense anymore.
2012-11-15 18:20:10 -04:00
David Bremner
fe13a55421 notmuch-restore: remove extra increment of optind
This is left over from when the file name was a positional parameter.
2012-11-15 18:19:38 -04:00
David Bremner
19c824c3fd notmuch-restore: replace positional argument for input with option
Since notmuch dump doesn't use positional arguments anymore, it seems
better to be consistent.
2012-08-06 08:52:45 -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
Jani Nikula
7400e18fb5 cli: refactor "notmuch restore" message tagging into a separate function
Refactor to make tagging code easier to reuse in the future. No
functional changes.

Signed-off-by: Jani Nikula <jani@nikula.org>
2012-03-30 21:22:44 -03:00
David Bremner
a077d2b103 notmuch-restore: convert to command-line-arguments
The new argument handling is a bit more concise, and bit more
flexible.  It allows the input file name to go before the --accumulate
option.
2011-12-08 20:24:24 -04:00
David Bremner
7a87830f5e xregcomp: don't consider every regex compilation failure an internal error.
This pushes the error handling up one step, but makes the function
more flexible. Running out of memory still triggers an internal error,
in the spirit of other xutils functions.
2011-10-30 23:10:38 -03:00
David Bremner
903fe63986 notmuch-restore: check for extra arguments.
We consider it an error to pass more than one file to restore, since
extra ones are ignored.
2011-10-23 10:27:57 -03:00
David Bremner
a77d9adcac notmuch-restore: implement --accumulate option
Modify command line argument handling to take a --accumulate flag.
Test for extra arguments beyond the input file.

The --accumulate switch causes the union of the existing and new tags to be
applied, instead of replacing each message's tags as they are read in from the
dump file.

Based on a patch by Thomas Schwinge:

      id:"1317317857-29636-1-git-send-email-thomas@schwinge.name"
2011-10-23 10:27:57 -03: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
Ali Polatel
02a3076711 lib: make find_message{,by_filename) report errors
Previously, the functions notmuch_database_find_message() and
notmuch_database_find_message_by_filename() functions did not properly
report error condition to the library user.

For more information, read the thread on the notmuch mailing list
starting with my mail "id:871uv2unfd.fsf@gmail.com"

Make these functions accept a pointer to 'notmuch_message_t' as argument
and return notmuch_status_t which may be used to check for any error
condition.

restore: Modify for the new notmuch_database_find_message()
new: Modify for the new notmuch_database_find_message_by_filename()
2011-10-04 07:55:29 +03:00
Carl Worth
bb74e9dff8 lib: Rework interface for maildir_flags synchronization
Instead of having an API for setting a library-wide flag for
synchronization (notmuch_database_set_maildir_sync) we instead
implement maildir synchronization with two new library functions:

	notmuch_message_maildir_flags_to_tags
  and   notmuch_message_tags_to_maildir_flags

These functions are nicely documented here, (though the implementation
does not quite match the documentation yet---as plainly evidenced by
the current results of the test suite).
2010-11-11 03:40:19 -08:00
Carl Worth
4cfb2a0277 Avoid abbreviation, preferring notmuch_config_get_maildir_synchronize_flags
Since the name of the configuration parameter here is:

	maildir.synchronize_flags

the convention is that the functions to get and set this parameter
should match it in name. Hence:

       notmuch_config_get_maildir_synchronize_flags

etc. (as opposed to notmuch_config_get_maildir_sync).
2010-11-11 03:40:19 -08:00
Michal Sojka
d9d3d3e6f0 Make maildir synchronization configurable
This adds group [maildir] and key 'synchronize_flags' to the
configuration file. Its value enables (true) or diables (false) the
synchronization between notmuch tags and maildir flags. By default,
the synchronization is disabled.
2010-11-10 13:09:32 -08: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
069cb5a73a notmuch restore: Don't waste time with messages with unchanged tags.
It's a simple optimization to look at a message and check that the
existing tags are actually different than the tags we are setting
before we do anything.

For my mail store this takes a "notmuch restore" that does nothing
from about 10 minutes down to 1 minute, so there's a significant
speedup here.
2010-02-05 17:29:56 -08: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
Keith Packard
c004e1e04b notmuch restore was skipping entries with no new tags
notmuch restore used to only add tags; now that it clears existing
tags, it needs to operate on messages even if the new tag list is empty.

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Carl Worth <cworth@cworth.org>:

I fixed up the indentation here, (someday we might switch to 8-space
indents, but we haven't yet).
2009-11-16 12:03:05 -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