aboutsummaryrefslogtreecommitdiff
path: root/notmuch-insert.c
AgeCommit message (Collapse)Author
2022-02-19CLI/insert: escape envelope fromDavid Bremner
The idea is to do as little parsing and modification of the delivered message as possible. Luckily the position of the "envelope header" lets us escape it by replacing the first 5 characters of the stream with a regular header name (with ':').
2022-02-19CLI/insert: split copy_fdDavid Bremner
This helps maintainability and enables code-reuse of our home-brewed buffered-write code. This commit is mostly code movement.
2021-10-23CLI: move indexopts variable out of shared options blockDavid Bremner
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-09-04CLI: make variable n_requested_db_uuid file scope.David Bremner
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-05-14CLI: make static message strings constDavid Bremner
This is both a bit clearer and avoids the possibility of modification.
2021-04-06CLI: drop notmuch_config_t from subcommand interface.David Bremner
At this point it is unused in all subcommands.
2021-03-20CLI/insert: support split database and mail rootDavid Bremner
The new test is in T055-path-config because it uses the helper function split_config, and because it seems easier to put the database path related tests in one place.
2021-03-13cli: run uncrustifyuncrustify
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-02-06CLI: use configured hook directoryDavid Bremner
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-06CLI/insert: convert to new config framework.David Bremner
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-06CLI: add (unused) database argument to subcommands.David Bremner
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.
2019-06-14cli: run uncrustifyuncrustify
This is the result of running $ uncrustify --replace --config devel/uncrustify.cfg *.c *.h in the top level source directory
2019-05-03gmime-cleanup: drop all arguments unused in GMime 3Daniel Kahn Gillmor
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>
2018-03-24cli/insert: add --world-readable flagDaniel Kahn Gillmor
In some cases (e.g. when building a publicly-visible e-mail archive) it doesn't make any sense to restrict visibility of the message to the current user account. This adds a --world-readable boolean option for "notmuch insert", so that those who want to archive their mail publicly can feed their archiver with: notmuch insert --world-readable Other local delivery agents (postfix's local, and dovecot's lda) all default to delivery in mode 0600 rather than relying on the user's umask, so this fix doesn't change the default. Also, this does not override the user's umask. if the umask is already set tight, it will not become looser as the result of passing --world-readable. Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
2017-12-13cli: use the negating boolean support for new and insert --no-hooksJani Nikula
This lets us use the positive hooks variable in code, increasing clarity.
2017-11-08cli: allow empty strings for notmuch insert --folder argumentJani Nikula
Now that it's easy to add argument specific modifiers in opt descriptions, add a new .allow_empty field to allow empty strings for individual string arguments while retaining strict checks elsewhere. Use this for notmuch insert --folder, where the empty string means top level folder.
2017-10-21cli/insert: add --try-decrypt=(true|false)Daniel Kahn Gillmor
Enable override of the index.try_decrypt setting on a per-message basis when invoking "notmuch insert". We also update the documentation and tab completion, and add more tests.
2017-10-09cli: convert notmuch_bool_t to stdboolJani Nikula
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-04cli: use designated initializers for opt descJani Nikula
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-04cli: strip trailing "/" from the final maildir path in notmuch insertJani Nikula
Several subtle interconnected changes here: - If the folder name passed as argument is the empty string "" or slash "/", the final maildir path would end up having "//" in it. We should strip the final maildir path, not folder. - The folder variable should really be const char *, another reason not to modify it. - The maildir variable is only const to let us point it at db_path directly. To be able to strip the maildir variable, always allocate it. Default folder to the empty string "", and don't treat folder not being present on the command line as anything special. As a side effect, we also create the cur/new/tmp in the top level directory if they're not there and --create-folder is given.
2017-08-23database: add n_d_index_file (deprecates n_d_add_message)Daniel Kahn Gillmor
We need a way to pass parameters to the indexing functionality on the first index, not just on reindexing. The obvious place is in notmuch_database_add_message. But since modifying the argument list would break both API and ABI, we needed a new name. I considered notmuch_database_add_message_with_params(), but the functionality we're talking about doesn't always add a message. It tries to index a specific file, possibly adding a message, but possibly doing other things, like adding terms to an existing message, or failing to deal with message objects entirely (e.g. because the file didn't contain a message). So i chose the function name notmuch_database_index_file. I confess i'm a little concerned about confusing future notmuch developers with the new name, since we already have a private _notmuch_message_index_file function, and the two do rather different things. But i think the added clarity for people linking against the future libnotmuch and the capacity for using index parameters makes this a worthwhile tradeoff. (that said, if anyone has another name that they strongly prefer, i'd be happy to go with it) This changeset also adjusts the tests so that we test whether the new, preferred function returns bad values (since the deprecated function just calls the new one). We can keep the deprecated n_d_add_message function around as long as we like, but at the next place where we're forced to break API or ABI we can probably choose to drop the name relatively safely. NOTE: there is probably more cleanup to do in the ruby and go bindings to complete the deprecation directly. I don't know those languages well enough to attempt a fix; i don't know how to test them; and i don't know the culture around those languages about API additions or deprecations.
2017-08-22insert: strip trailing / in folder pathYuri Volchkov
This patch fixes the "Insert message into folder with trailing /" test. The problem was insufficient path canonization. From database's point of view, "Sent" and "Sent/" are different folders. If user runs (note the last '/'): notmuch insert --folder=maildir/Sent/ < test.msg notmuch will create an extra XDIRECTORY record for the folder 'Sent/'. This means that database will have _TWO_ records for _ONE_ physical folder: 'Sent' and 'Sent/'. However, the 'notmuch new' command will update only records related to the first one (the correct one). Now, if user moved the email file (e.g. from 'Sent/new' to 'Sent/cur'), 'notmuch new' will add a record about the new file, but will not delete the old record. Signed-off-by: Yuri Volchkov <yuri.volchkov@gmail.com>
2016-12-07cli/insert: return EX_TEMPFAIL for some errorsDavid Bremner
Attempt to distinguish between errors indicating misconfiguration or programmer error, which we consider "permanent", in the sense that automatic retries are unlikely to be useful, and those indicating transient error conditions. We consider XAPIAN_EXCEPTION transient because it covers the important special case of locking failure.
2016-12-07cli/insert: delay database open until after writing mail fileDavid Bremner
The idea is to get the mail written to disk, even if we can't open the database (e.g. because some other process has a write lock, and notmuch is compiled for non-blocking opens).
2016-06-05Use https instead of http where possibleDaniel Kahn Gillmor
Many of the external links found in the notmuch source can be resolved using https instead of http. This changeset addresses as many as i could find, without touching the e-mail corpus or expected outputs found in tests.
2015-08-14cli: add global option "--uuid"David Bremner
The function notmuch_exit_if_unmatched_db_uuid is split from notmuch_process_shared_options because it needs an open notmuch database. There are two exceptional cases in uuid handling. 1) notmuch config and notmuch setup don't currently open the database, so it doesn't make sense to check the UUID. 2) notmuch compact opens the database inside the library, so we either need to open the database just to check uuid, or change the API.
2015-06-01cli: define shared options, use for --help and --versionDavid Bremner
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-05-31cli: change "setup" to "set up" where used as a verbJ. Lewis Muir
The word "setup" is a noun, not a verb. Change occurrences of "setup" where used as a verb to "set up".
2014-10-28cli/insert: add post-insert hookJani Nikula
The post-new hook might no longer be needed or run very often if notmuch insert is being used. Therefore a post-insert hook is needed (arguably pre-insert not so much, so don't add one). Also add the --no-hooks option to skip hooks.
2014-10-28cli: cast timeval fields to long for formatJani Nikula
This hides platform differences between struct timeval field types.
2014-10-18cli/insert: require succesful message indexing for success statusJani Nikula
Add --keep option to keep any remaining stuff in index or file. We could distinguish between failures to index and failures to apply tags or maildir sync, but for simplicity just have one.
2014-10-18cli/insert: add fail path to add_file_to_databaseJani Nikula
Handle failures gracefully in add_file_to_database, renamed simply add_file while at it. Add keep option to not remove the message from database if tagging or tag syncing to maildir flags fails. Expand the function documentation to cover the changes.
2014-09-24cli/insert: rehash file writing functionsJani Nikula
Make the function calls make more sense as independent building blocks of the big picture, with clear inputs and outputs. Split up write_message into two. Improve function documentation. Cleanup and clarify the error paths.
2014-09-24cli/insert: abstract temporary filename generationJani Nikula
This will clean up the usage. There's the slight functional change of potentially ending up doing extra gethostname and getpid calls, but this is neglible.
2014-09-24cli/insert: use a single recursive mkdir functionJani Nikula
Combine make_directory() and make_directory_and_parents() into a single recursive mkdir_recursive() function. Clarify the code and improve error handling. Improve error messages. Switch to using the new function in maildir_create_folder(). Constify talloc context.
2014-09-24cli/insert: clean up sync_dirJani Nikula
Clarify the code slightly, improve error messages. Apart from the error message changes, no functional changes.
2014-09-24cli/insert: rename file copy functionJani Nikula
The copying has nothing to do with stdin, so call it copy_fd instead. While at it, improve documentation and reverse the parameters, as destination is traditionally the first parameter.
2014-09-24cli/insert: move add_file_to_database to a better placeJani Nikula
Move add_file_to_database around to keep the filesystem related functions grouped together, improving readability. No functional changes.
2014-09-24cli/insert: rename check_folder_name to is_valid_folder_nameJani Nikula
An "is something" predicate conveys the meaning better. While at it, improve the function documentation and error message. Besides the error message change, no functional changes.
2014-09-16cli: refactor insertPeter Wang
Change insert_message into write_message and move its responsibilities for indexing the message into the main function, to simplify the control flow.
2014-03-06cli: make sure notmuch new and insert don't add invalid tagsJani Nikula
Check new.tags configuration values before doing anything, and bail out on invalid values.
2014-01-18cli: clean up exit status code returned by the cli commandsJani Nikula
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-03insert: respect maildir.synchronize_flagsJani Nikula
Don't synchronize maildir flags if the user doesn't want it.
2013-07-04insert: add --create-folder optionPeter Wang
Allow the insert command to create the maildir folder into which the new message should be delivered.
2013-07-01insert: add --folder optionPeter Wang
Allow the new message to be inserted into a folder within the Maildir hierarchy instead of the top-level folder.
2013-06-29cli: add insert commandPeter Wang
The notmuch insert command reads a message from standard input, writes it to a Maildir folder, and then incorporates the message into the notmuch database. Essentially it moves the functionality of notmuch-deliver into notmuch. Though it could be used as an alternative to notmuch new, the reason I want this is to allow my notmuch frontend to add postponed or sent messages to the mail store and notmuch database, without resorting to another tool (e.g. notmuch-deliver) nor directly modifying the maildir.