Commit graph

239 commits

Author SHA1 Message Date
David Bremner
1c10d91d8e Pass error message from GLib ini parser to CLI
The function _notmuch_config_load_from_file is only called in two
places in open.cc. Update internal API to match the idiom in open.cc.
Adding a newline is needed for consistency with other status strings.

Based in part on a patch [1] from Eric Blake.

[1]: id:20230906153402.101471-1-eblake@redhat.com
2023-09-23 08:34:48 -03:00
David Bremner
dbb5ff3385 CLI: exit with error when load_config returns an error.
For now print a generic error message and exit with error on any
non-success code. Previously the code exited, but with exit code zero,
leading users / scripts to think the command had succeeded.
2023-09-23 08:26:40 -03:00
Tomi Ollila
54190d091c notmuch.c: add missing trailing newlines in two error messages
Removed duplicate error check (and the message) in 3rd case where
the same error message (w/o trailing newline) was present.

In case of test/T040-setup.sh, command substitution deletes
trailing newlines, so related test there cannot be changed
(and therefore could not notice this user experience flaw).
2022-07-31 21:03:59 -03:00
David Bremner
5cbddf7e7a CLI: pass --config to external commands via NOTMUCH_CONFIG.
This makes `notmuch --config foo external-subcommand` work
consistently with the built in subcommands.
2022-06-13 07:28:05 -03:00
David Bremner
82957c9632 CLI: mention sexp-queries in help topics, alphabetize
There does not seem to be an easy way to automate maintaining this
list, but new topics are not added very often.
2022-06-13 07:18:26 -03:00
David Bremner
52470ddfbf CLI: simplify help command
This will allow "notmuch help" to work for arbitrary external commands
and for any added non-command topics (such as notmuch-sexp-queries).
2022-06-13 07:17:59 -03:00
David Bremner
2ce6c76a61 CLI: move indexopts variable out of shared options block
This reduces the amount of global state.  Furthermore, index options
can be set (in principle) in several ways, not just in the one
function for processing indexing command line options.
2021-10-23 09:51:50 -03:00
David Bremner
a2e7af5b69 CLI: move query syntax to shared option
This will allow easy addition of a query syntax option to other subcommands.
2021-09-04 17:07:19 -07:00
David Bremner
d447b694b4 CLI: make variable n_requested_db_uuid file scope.
It turns out that now that we pass an open database into the
subcommands, it is easy to check any requested uuid against the
database at the same time as we process the other shared
arguments. This results in overall less boilerplate code, as well as
making a CLI scope function and variable file scope in notmuch.c.
2021-09-04 17:07:19 -07:00
David Bremner
ea301102ab lib: write talloc report in notmuch_database_destroy
Since most memory allocation is (ultimately) in the talloc context
defined by a notmuch_database_t pointer, this gives a more complete
view of memory still allocated at program shutdown.

We also change the talloc report in notmuch.c to mode "a" to avoid
clobbering the newly reported log.
2021-06-25 09:20:37 -03:00
David Bremner
121f9ddad3 CLI/notmuch: make immutable tables const
Let the compiler enforce the immutability.
2021-05-14 06:44:00 -03:00
David Bremner
5a8d174f67 CLI: centralize initialization in notmuch_client_init
Initially make sure gmime_filter_reply initialization is
thread-safe (assuming notmuch_client_init is only called once).
For tidyness, also put talloc initialization in the new function.
2021-05-14 06:40:37 -03:00
David Bremner
1c747a501c CLI: drop notmuch_config_t from subcommand interface.
At this point it is unused in all subcommands.
2021-04-06 21:32:36 -03:00
David Bremner
ec4b7efbe4 CLI/config: remove calls to notmuch_config_open from top level
This will allow simplifying the subcommand interface.

Change the internal API to notmuch_config_open to not tie it to the
implementation of subcommands in notmuch.c.

It also fixes a previously broken test, since notmuch_config_open does
not understand the notion of the empty string as a config file name.
2021-04-06 21:32:36 -03:00
David Bremner
77d4b26d3e CLI/config: support set/get with split configuration
There are two small code changes. The main one is to retrieve the
possibly updated config file name found during the database opening
call. The second change is to allow empty config file names, as
a (currently broken) way of specifying that configuration should only
be taken from the database.
2021-03-27 09:26:14 -03:00
David Bremner
217f819608 CLI+lib: detect missing database in split configurations.
Eventually we want to do all opening of databases in the top
level (main function). This means that detection of missing databases
needs to move out of subcommands. It also requires updating the
library to use the new NO_DATABASE status code.
2021-03-27 09:26:14 -03:00
David Bremner
8d5b8753cf CLI/notmuch: switch notmuch_command to notmuch_config_get
The goal at this point is to remove the dependence on
notmuch_config_get_* without breaking any existing functionality. This
is a step towards removing notmuch_config_get_* in a future commit.
2021-03-27 09:26:14 -03:00
David Bremner
b76da87d29 CLI/config: migrate notmuch_config_open to new config
notmuch_config_open will be preserved in the medium term for use by
the commands that are manipulating the config file directly (config
and setup)
2021-03-27 09:26:14 -03:00
David Bremner
34f734e26b CLI/setup: switch to new configuration framework
Most of the changes are the elimination of notmuch_config_t accessor
use. We also migrate some of the diagnostics to the top level where we
are opening the files in question.
2021-03-27 09:26:14 -03:00
David Bremner
d9bc5c8528 CLI: load merged config at top level
This paves the way for the conversion of the remaining subcommands to
the new configuration framework.
2021-03-27 09:26:14 -03:00
David Bremner
6e6c319c26 CLI/show: complete conversion to new configuration framework.
In order to open the database in main() for this command, we may need
to re-open it in the (possibly less common) case where crypto options
require write access.
2021-03-19 22:06:19 -03:00
uncrustify
eef21c2847 cli: run uncrustify
This is the result of running

     $ uncrustify --replace --config devel/uncrustify.cfg *.c *.h

in the top level source directory

Line breaks were then adjusted manually to keep argc and argv
together.
2021-03-13 08:45:34 -04:00
David Bremner
0d3bef312d cli/new: convert to new config framework
In addition to the same type of changes as converting other
subcommands, add the possibility of creating a database at the top
level. It would probably make sense to use this for insert as well.
2021-02-06 19:52:11 -04:00
David Bremner
f118ef3c3d cli/compact: convert to new configuration framework
Switch to the newly created API function notmuch_database_compact_db,
which takes the database opened in main().
2021-02-06 19:36:06 -04:00
David Bremner
c56dcea7e2 cli/tag: convert to new config framework.
In addition to changing configuration access, change talloc context
for allocation.
2021-02-06 19:30:20 -04:00
David Bremner
d613d10ddd CLI/{search,address}: convert to new configuration framework
Since we are already passing a search context around as a kind of
parameter block, add a new talloc context to that to replace relying
on 'config'.

Convert notmuch-search and notmuch-address at the same time, because
they share some code.

Add a test to make sure we don't break passing configuration as a
command line argument.
2021-02-06 19:23:28 -04:00
David Bremner
8588719eb1 CLI/reply: convert to new config framework
This is messier than some of the other conversions because the
extensive use of 'config' as a talloc context.
2021-02-06 19:21:23 -04:00
David Bremner
0ab0b48be2 cli/reindex: convert new config framework
The only non-trivial part is switching the talloc context for
query_string_from args from 'config' to 'notmuch'.
2021-02-06 19:19:18 -04:00
David Bremner
f994f0e7df CLI/insert: convert to new config framework.
The new talloc context is needed to run the hook at the very end of
the function. That in turn is needed so that this process gives up the
write lock on the database.
2021-02-06 19:17:34 -04:00
David Bremner
66adcd4f53 CLI/restore: convert to new config framework
Switch one configuration check to new n_c_get_bool function, and
switch use of config as talloc context to notmuch.
2021-02-06 19:15:53 -04:00
David Bremner
53f27aaf73 cli/dump: convert to new config framework
This conversion is trivial because the only configuration information
accessed by dump is that stored in the database (in order to dump
it). We do need to be careful to keep the write lock on the database
to ensure dump consistency.
2021-02-06 19:12:34 -04:00
David Bremner
acc6331baa CLI/count: switch to new configuration framework
The main effort is changing from the old argv style config list
iterators to the new more opaque ones provided by the library (and
backed by the database+file config cache).
2021-02-06 19:11:06 -04:00
David Bremner
fd6f8e6c30 lib/config: add config values iterator
This is intended to avoid duplicating the string splitting and
traversal code for all clients of the config API.
2021-02-06 19:08:12 -04:00
David Bremner
319efe21c9 CLI: add (unused) database argument to subcommands.
This will allow transitioning individual subcommands to the new
configuration framework. Eventually when they are all converted we can
remove the notmuch_config_t * argument.

For now, live with the parameter shadowing in some some subcommands;
it will go away when they are converted.
2021-02-06 19:05:19 -04:00
David Bremner
867d7352a7 CLI: generalize notmuch_config_mode_t
The renaming and extra values will make sense when we start to convert
subcommands to the new configuration framework. It will also avoid
collisions with a new enum for configuration keys to be introduced in
a future commit.
2021-02-06 19:00:30 -04:00
uncrustify
33382c2b5b cli: run uncrustify
This is the result of running

     $ uncrustify --replace --config devel/uncrustify.cfg *.c *.h

in the top level source directory
2019-06-14 07:41:27 -03:00
Tomi Ollila
38dacf009c append _unused to the expression defined using unused() macro
This way if variables defined using unused() macro are actually
used then code will not compile...

- removed unused usage around one argc and one argv since those
  were used

- changed one unused (char *argv[]) to unused (char **argv) to
  work with modified unused() macro definition
2019-06-11 07:25:04 -03:00
Daniel Kahn Gillmor
58ee5d1bb5 gmime-cleanup: drop unused gmime #defines and simplify g_mime_init ()
Several of these #defines were not actually used in the notmuch
codebase any longer.  And as of GMime 3.0, g_mime_init takes no
arguments, so we can also drop the bogus RFC2047 argument that we were
passing and then #defining away.

signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
2019-05-03 06:56:58 -03:00
Daniel Kahn Gillmor
b7ac4c05e1 gmime-cleanup: drop all arguments unused in GMime 3
This means dropping GMimeCryptoContext and notmuch_config arguments.

All the argument changes are to internal functions, so this is not an
API or ABI break.

We also get to drop the #define for g_mime_3_unused.

signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
2019-05-03 06:56:38 -03:00
Daniel Kahn Gillmor
096d45a878 gmime-cleanup: remove obsolete gpg_path configuration option and crypto contexts
Note that we do keep ignoring the gpg_path configuration option,
though, to avoid breakage of existing installations.  It is ignored
like any other unknown configuration option, but we at least document
that it is ignored so that people who find it in their legacy configs
can know that it's safe to drop.

signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
2019-05-03 06:55:04 -03:00
Daniel Kahn Gillmor
54982e520c fix typos 2018-01-04 20:35:58 -04:00
Daniel Kahn Gillmor
94dc81a91b cli/help,completion: added pointers to notmuch-properties(7) 2017-12-11 09:11:19 -04:00
Daniel Kahn Gillmor
fccebbaeef crypto: add --decrypt=nostash to avoid stashing session keys
Here's the configuration choice for people who want a cleartext index,
but don't want stashed session keys.

Interestingly, this "nostash" decryption policy is actually the same
policy that should be used by "notmuch show" and "notmuch reply",
since they never modify the index or database when they are invoked
with --decrypt.

We take advantage of this parallel to tune the behavior of those
programs so that we're not requesting session keys from GnuPG during
"show" and "reply" that we would then otherwise just throw away.
2017-12-08 08:08:47 -04:00
Daniel Kahn Gillmor
e4890b5bf9 crypto: new decryption policy "auto"
This new automatic decryption policy should make it possible to
decrypt messages that we have stashed session keys for, without
incurring a call to the user's asymmetric keys.
2017-12-08 08:07:53 -04:00
Daniel Kahn Gillmor
798aa789b5 lib: convert notmuch decryption policy to an enum
Future patches in this series will introduce new policies; this merely
readies the way for them.

We also convert --try-decrypt to a keyword argument instead of a boolean.
2017-12-08 08:07:02 -04:00
Daniel Kahn Gillmor
b62045a186 indexopts: change _try_decrypt to _decrypt_policy
This terminology makes it clearer what's going on at the API layer,
and paves the way for future changesets that offer more nuanced
decryption policy.
2017-12-08 08:06:03 -04:00
Daniel Kahn Gillmor
d3964e81ac indexing: Change from try_decrypt to decrypt
the command-line interface for indexing (reindex, new, insert) used
--try-decrypt; and the configuration records used index.try_decrypt.
But by comparison with "show" and "reply", there doesn't seem to be
any reason for the "try" prefix.

This changeset adjusts the command-line interface and the
configuration interface.

For the moment, i've left indexopts_{set,get}_try_decrypt alone.  The
subsequent changeset will address those.
2017-12-08 08:05:53 -04:00
Daniel Kahn Gillmor
de80ede3df cli/help: give a hint about notmuch-emacs-mua
"notmuch help" doesn't mention "notmuch-emacs-mua" even though we
support it through the try_external_command() mechanism.

In addition, "notmuch help emacs-mua" doesn't work, even though we
ship the appropriate manpage.

This changeset fixes both of these problems.
2017-12-07 08:20:00 -04:00
Daniel Kahn Gillmor
5bdb8549f6 cli: set up shared command-line arguments for indexing
We have an indexopts structure for manipulating indexing in different
ways, but we also have three command-line invocations that can trigger
indexing: new, insert, and reindex.

This changeset prepares a common parser that these subcommands can
share.

Note: if the deprecated crypto.gpg_path configuration option is set to
anything other than "gpg", we ignore it (and print a warning on
stderr, if built against gmime < 3.0).

At the moment, it's just --try-decrypt, but others will likely follow.
2017-10-21 19:58:11 -03:00
Jani Nikula
0f314c0c99 cli: convert notmuch_bool_t to stdbool
C99 stdbool turned 18 this year. There really is no reason to use our
own, except in the library interface for backward
compatibility. Convert the cli and test binaries to stdbool.
2017-10-09 22:24:02 -03:00