Commit graph

154 commits

Author SHA1 Message Date
Robin Jarry
793f298091 cli: add options --offset and --limit to notmuch show
notmuch search does not output header values. However, when browsing
through a large email corpus, it can be time saving to be able to
paginate without running notmuch show for each message/thread.

Add --offset and --limit options to notmuch show. This is inspired from
commit 796b629c3b ("cli: add options --offset and --limit to notmuch
search").

Update man page, shell completion and add a test case to ensure it works
as expected.

Cc: Tim Culverhouse <tim@timculverhouse.com>
Cc: Tomi Ollila <tomi.ollila@iki.fi>
Signed-off-by: Robin Jarry <robin@jarry.cc>
2022-11-05 13:18:15 -04:00
David Bremner
4612f3eb3d CLI/show: support --duplicate for structured output
This introduces a new mandatory key for message structures, namely
"duplicate". Per convention in devel/schemata this does _not_ increase
the format version. This means that clients are responsible for
checking that it exists, and not crashing if it does not.

The main functional change is teaching mime_node_open to understand a
'duplicate' argument.

Support for --duplicate in notmuch-reply would make sense, but we
defer it to a later commit.
2022-07-30 08:41:50 -03:00
David Bremner
cef5eaaef6 CLI/show: initial support for --duplicate for (raw output only)
Add command line argument --duplicate, analogous with that already
supported for notmuch-search.

Use of a seperate function for _get_filename is mainly a form of
documentation at this point.

md5sum is of course a weak hash, but it is good enough for
this (non-adversarial) test suite use.
2022-07-30 08:39:13 -03:00
David Bremner
417d202e64 CLI: stash pointer to database in sprinter structs
We already use an allocated (and presumably open) database as a talloc
context. Keeping the pointer in the allocated struct will allow us to
e.g. interrogate the configuration in a sprinter function without
threading the database all the way through the various levels of function.
2022-01-18 08:08:22 -04: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
Jani Nikula
f316f7ef6a cli: remove enum names from typedefs
There are some enum typedefs with the enum name:

    typedef enum _name_t { ... } name_t;

We don't need or use the enum names _name_t for anything, and not all
of the enum typedefs have them. We have the typedefs specifically to
use the typedef name.

Use the anonymous enum in the typedefs:

    typedef enum { ... } name_t;
2021-10-23 08:39:16 -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
731697d671 CLI: define and use format version 5
This is a bit of a cheat, since the format does not actually
change. On the other hand it is fairly common to do something like
this to shared libary SONAMEs when the ABI changes in some subtle way.
It does rely on the format-version argument being early enough on the
command line to generate a sensible error message.
2021-08-22 07:05:13 -07: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
1459217e17 CLI: rename notmuch_config_t to notmuch_conffile_t
The name is a compromise between keeping function names from getting
too long, and avoiding confusion with the newer notmuch_config library
API. Try to make clear that the residual functionality is only about
updating configuration files.
2021-04-06 21:32:36 -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
eb542106b6 CLI/config: drop obsolete notmuch_config_get_*
These are no longer used, replaced by notmuch_config_get.
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
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
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
f61d88c6f4 CLI: use configured hook directory
This enables support for hooks outside the database directory.
It relies strongly on configuration information being usable between
closing the database and destroying it.
2021-02-06 19:57:55 -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
dd6b507099 cli/config: add accessor for config file name
This is intended for use in temporary code transitioning to the new
configuration system. The name is chosen to avoid cluttering the
notmuch_config_* namespace further with non-library functions.
2021-02-06 19:25:35 -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
David Bremner
24ff33082a cli/dump: define GZPUTS and use it in notmuch-dump
Similarly to GZPRINTF, this is a drop in replacement that can be
improved where needd.
2020-04-13 17:14:50 -03:00
David Bremner
0d0918f604 cli/dump: define GZPRINTF macro and use it in place of gzprintf
This will at least catch errors, and can be replaced with more
sophisticated error handling where appropriate.
2020-04-13 17:14:50 -03:00
David Bremner
0211272843 status: add print_status_gzbytes
This is in the client code, rather than libnotmuch_util, because it
prints to stderr. Also it in pretends to generate notmuch status
codes.
2020-04-13 17:14:50 -03:00
Daniel Kahn Gillmor
7de3d77d2d mime-node: rename decrypted_child to unwrapped_child
When walking the MIME tree, we might need to extract a new MIME
object.  Thus far, we've only done it when decrypting
multipart/encrypted messages, but PKCS#7 (RFC 8551, S/MIME) has
several other transformations that warrant a comparable form of
unwrapping.

Make this member re-usable for PKCS#7 unwrappings as well as
multipart/encrypted decryptions.

This change is just a naming change, it has no effect on function.

Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
2020-03-22 22:20:52 -03:00
Daniel Kahn Gillmor
1b29822cf5 repair: set up codebase for repair functionality
This adds no functionality directly, but is a useful starting point
for adding new repair functionality.

Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
2019-09-01 08:20:25 -03: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
1c7fbbcc99 cli/show: emit payload subject instead of outside subject
Correctly fix the two outstanding tests so that the protected (hidden)
subject is properly reported.

Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
2019-05-29 08:05:01 -03:00
Daniel Kahn Gillmor
2c08beb254 cli: expose message-wide crypto status from mime-node
The mime node context (a per-message context) gains a cryptographic
status object, and the mime_node_t object itself can return a view on
that status to an interested party.

The status is not yet populated, and for now we can keep that view
read-only, so that it can only be populated/modified during MIME tree
traversal.
2019-05-26 08:20:23 -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
f32e52448b cli: add print_status_message()
This function is a parallel to print_status_query() or
print_status_database().  Thanks to David Bremner for the suggestion!
2018-05-26 07:32:14 -07: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
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
Daniel Kahn Gillmor
197d67959b crypto: move into libnotmuch_util
This prepares us for using the crypto object in both libnotmuch and
the client.
2017-10-20 07:58:10 -03:00
Daniel Kahn Gillmor
bfd669bb2e crypto: _notmuch_crypto_cleanup should return void
There's no chance that _notmuch_crypto_cleanup() will ever return
anything other than 0, and no one ever checks its return value anyway.
So make it return void instead of int.
2017-10-12 22:11:55 -03:00
Daniel Kahn Gillmor
3e9857a0b9 crypto: drop pretense of notmuch_crypto_context_t
notmuch_crypto_context_t was introduced (i think) as some sort of
abstraction layer to make notmuch somewhat independent of GMime.  But
it isn't even useful for GMime 3.0 or later -- we can drop the
pretense that it's some sort of abstraction in this case, and just
call it what it is, GMimeCryptoContext, which is useful for building
against older versions of GMime.

This also renames _notmuch_crypto_get_context() to
_notmuch_crypto_get_gmime_context().
2017-10-12 22:11:33 -03:00
Daniel Kahn Gillmor
88f2a72ef1 crypto: rename notmuch_crypto_t to _notmuch_crypto_t
The notmuch_crypto_t struct isn't used externally, and we have no
plans to explicitly export it.  Prefix its name (and associated
functions) with _ to make that intent clear.
2017-10-12 22:11:25 -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
Jani Nikula
4a6721970a cli: use designated initializers for opt desc
Several changes at once, just to not have to change the same lines
several times over:

- Use designated initializers to initialize opt desc arrays.

- Only initialize the needed fields.

- Remove arg_id (short options) as unused.

- Replace opt_type and output_var with several type safe output
  variables, where the output variable being non-NULL determines the
  type. Introduce checks to ensure only one is set. The downside is
  some waste of const space per argument; this could be saved by
  retaining opt_type and using a union, but that's still pretty
  verbose.

- Fix some variables due to the type safety. Mostly a good thing, but
  leads to some enums being changed to ints. This is pedantically
  correct, but somewhat annoying. We could also cast, but that defeats
  the purpose a bit.

- Terminate the opt desc arrays using {}.

The output variable type safety and the ability to add new fields for
just some output types or arguments are the big wins. For example, if
we wanted to add a variable to set when the argument is present, we
could do so for just the arguments that need it.

Beauty is in the eye of the beholder, but I think this looks nice when
defining the arguments, and reduces some of the verbosity we have
there.
2017-10-04 22:00:42 -03:00
Daniel Kahn Gillmor
23eed88e32 remove boolean "first" argument from format_part_sprinter
This argument seems to be unused, and format_part_sprinter isn't
required to meet any specific API so it seems cleaner and simpler to
drop it.
2017-08-16 21:56:58 -03:00
Daniel Kahn Gillmor
e5beec39d6 add "notmuch reindex" subcommand
This new subcommand takes a set of search terms, and re-indexes the
list of matching messages.
2017-08-01 21:17:47 -04:00
David Bremner
edb933b25d crypto: clean up unused definitions in gmime 3.0
based on the same patch from dkg as the previous commit.
2017-07-15 21:43:39 -03:00
Daniel Kahn Gillmor
e142de643d config: deprecate/drop crypto.gpg_path under gmime 2.6/3.0
gmime 3.0 no longer offers a means to set the path for gpg.

Users can set $PATH anyway if they want to pick a
differently-installed gpg (e.g. /usr/local/bin/gpg), so this isn't
much of a reduction in functionality.

The one main difference is for people who have tried to use "gpg2" to
make use of gpg 2.1, but that isn't usefully co-installable anyway.
2017-07-14 21:23:52 -03:00
David Bremner
e1b7d32db0 cli: implement structured output version 4
Since the error field is unused by the emacs front end, no changes are
needed other than bumping the format version number.

As it is, this is a bit overengineered, but it will reduce duplication
when we support gmime 3.0
2017-07-04 08:32:44 -03:00
David Bremner
331310c4ba cli/show: use single stream for printf / gmime object output
This is again motivated by the need to transition away from
GMimeStreamFile for output to stdout.

format_part_mbox is left alone for now, as this cannot be mixed in
with output using gmime object output.
2017-05-30 09:02:07 -03:00