aboutsummaryrefslogtreecommitdiff
path: root/lib/message.cc
AgeCommit message (Collapse)Author
2026-01-15lib: move call to _n_m_invalidate_metadataDavid Bremner
It is wrong most of the time in _notmuch_message_remove_terms, but that function is too low level to know how to call _n_m_invalidate_metadata with the right argument, at least not without more extensive changes. This change merely makes the current behaviour more obvious, since the other calls cannot have relied on metadata being invalidated.
2025-08-09lib: return NOTMUCH_STATUS_OPERATION_INVALIDATED where appropriateAnton Khirnov
The overall goal is to allow clients to restart operations in situations where that is the response recommended by the underlying Xapian library. Amended-by: db, added above explanation
2025-07-24lib: handle DatabaseModifiedError in _notmuch_message_createAnton Khirnov
If an open database is modified sufficiently by other callers, the open instance becomes invalid and operations on it throw DatabaseModifiedError. Per Xapian documentation, the caller is then supposed to reopen the database and restart the query. This exception is currently not handled in _notmuch_message_create(), leading to the default handler abort()ing the process. Catch this exception in _notmuch_message_create() and return an error instead of crashing. Since the entire query becomes invalid - including results that have already been read by the caller - this situation cannot be handled by libnotmuch transparently. A new public function - notmuch_messages_status() - is added to allow the callers to check whether the messages iterator was exhausted or terminated early due to a runtime error. This also allows memory allocation failure to be signalled to the caller. Amended-By: David Bremner <david@tethera.net> [replace use of notmuch_messages_valid]
2023-07-22lib/message: check message type before deleting documentDavid Bremner
It isn't really clear how this worked before. Traversing the terms of a document after deleting it from the database seems likely to be undefined behaviour at best
2023-03-30lib/message-property: sync removed properties to the databaseKevin Boulain
_notmuch_message_remove_all_properties wasn't syncing the message back to the database but was still invalidating the metadata, giving the impression the properties had actually been removed. Also move the metadata invalidation to _notmuch_message_remove_terms to be closer to what's done in _notmuch_message_modify_property and _notmuch_message_remove_term.
2023-02-20lib: add better diagnostics for over long filenames.David Bremner
Previously we just crashed with an internal error. With this change, the caller can handle it better. Update notmuch-new so that it doesn't crash with "unknown error code" because of this change.
2022-12-27lib/message: move xapian call inside try/catch block in _n_m_deleteDavid Bremner
The call to delete_document can throw exceptions (and can happen in practice [1]), so catch the exception and extract the error message. As a side effect, also move the call to _n_m_has_term inside the try/catch. This should not change anything as that function already traps any Xapian exceptions. [1]: id:wwuk039sk2p.fsf@chaotikum.eu
2022-06-25lib: check for writable db in n_m_tags_maildir_flagsDavid Bremner
The database needs to be writable because the list of stored file names will change in general.
2022-06-25lib/message: check return status from _n_m_add_{path,folder}_termsDavid Bremner
Mainly to propagate information about Xapian exceptions.
2022-06-25lib/message: check return status of _n_m_{add,remove}_termDavid Bremner
Xapian exceptions are not something that can be ignored, in general.
2022-06-25lib/message: drop _notmuch_message_get_thread_id_onlyDavid Bremner
This function has been unused since commit 4083fd8.
2022-06-25lib/message: catch exceptions in _n_m_add_termDavid Bremner
Some code movement is needed to make sure the cache is only invalidated when the Xapian operation succeeds.
2022-05-26lib/message: use false from stdbool.hDavid Bremner
As far as I know, this is just a style / consistency thing, unless notmuch code starts defining FALSE inconsistently with false.
2022-05-26lib: fix uninitialized field in message objects.David Bremner
Initially reported by Eliza Vasquez [1] (via valgrind). [1]: id:87o7zxj086.fsf@eliza.
2021-06-05lib/message: use passed database for error handlingDavid Bremner
'message' should always be initialized if we reach here, but in case it is not, we still want to be able to log an error message.
2021-06-05lib/{open,message}: make some internal functions staticDavid Bremner
They are not used outside their file, so being extern seems like an oversight
2021-05-14lib/message: mark flag2tag as constDavid Bremner
This table is intended to be immutable
2021-04-18lib: directly traverse postlists in _n_message_deleteDavid Bremner
This is intended to fix the slow behaviour of "notmuch new" (and possibly "notmuch reindex") when large numbers of files are deleted. The underlying issue [1] seems to be the Xapian glass backend spending a large amount of time in db.has_positions when running queries with large-ish amounts of unflushed changes. This commit removes two uses of Xapian queries [2], and replaces them with an approximation of what Xapian would do after optimizing the queries. This avoids the calls to has_positions (which are in any case un-needed because we are only using boolean terms here). [1] Thanks to "andres" on IRC for narrowing down the performance bottleneck. [2] Thanks to Olly Betts of Xapian fame for talking me a through a fix that does not require people to update Xapian.
2021-03-20lib: support splitting mail from database location.David Bremner
Introduce a new configuration value for the mail root, and use it to locate mail messages in preference to the database.path (which previously implied the mail messages were also in this location. Initially only a subset of the CLI is tested in a split configuration. Further changes will be needed for the remainder of the CLI to work in split configurations.
2021-03-18lib: publish API for notmuch_database_reopenDavid Bremner
Include the (currently unused) mode argument which will specify which mode to re-open the database in. Functionality and docs to be finalized in a followup commit.
2021-03-13lib: run uncrustifyuncrustify
This is the result of running $ uncrustify --replace --config ../devel/uncrustify.cfg *.c *.h *.cc in the lib directory
2020-07-28lib: replace use of static_cast for writable databasesDavid Bremner
static_cast is a bit tricky to understand and error prone, so add a second pointer to (potentially the same) Xapian database object that we know has the right subclass.
2020-07-28lib: encapsulate the use of notmuch_database_t field 'mode'David Bremner
The plan is to change the underlying representation.
2020-07-22lib: fix exception messages for n_m_message_*David Bremner
The original generic handler had an extra '%s' in the format string. Update tests that failed to catch this because the template to print status strings checked 'stat', which was not set.
2020-07-20lib: fix return value for n_m_reindexDavid Bremner
Also update the documentation for the behaviour of n_m_get_thread_id that this fix relies on.
2020-07-20lib: handle xapian exception in n_m_remove_all_tagsDavid Bremner
At least the exception we already catch should be reported properly.
2020-07-20lib: add notmuch_message_has_maildir_flag_stDavid Bremner
Initially the new function is mainly tested indirectly via the wrapper.
2020-07-20test: add regression test for notmuch_message_has_maildir_flagDavid Bremner
This passes the NULL return inside _ensure_maildir_flags does not break anything. Probably this should be handled more explicitely.
2020-07-18lib: catch exceptions in n_m_get_flag, provide n_m_get_flag_stDavid Bremner
It's not very nice to return FALSE for an error, so provide notmuch_message_get_flag_st as a migration path. Bump LIBNOTMUCH_MINOR_VERSION because the API is extended.
2020-07-14lib: use COERCE_STATUS in n_m_{add,remove}_tagDavid Bremner
Currently I don't know of a good way of testing this, but at least in principle a Xapian exception in _notmuch_message_{add,remove}_term would cause an abort in the library.
2020-07-14lib: catch Xapian exceptions in n_m_remove_tagDavid Bremner
The churn here is again mainly re-indentation.
2020-07-14lib: catch Xapian exceptions in n_m_add_tagDavid Bremner
This is mostly just (horizontal) code movement due to wrapping everything in a try / catch.
2020-07-14lib: catch Xapian exceptions in n_m_count_filesDavid Bremner
This will require some care for the caller to check the sign, and not just add error returns into a running total.
2020-07-14lib: catch Xapian exceptions in n_m_get_tagsDavid Bremner
This allows the function to return an error value rather than crashing.
2020-07-14lib: use LOG_XAPIAN_EXCEPTION in n_m_get_dateDavid Bremner
This should not change functionality, but does slightly reduce code duplication. Perhaps more importantly it allows consistent changes to all of the similar exception handling in message.cc.
2020-07-13lib: catch exceptions in n_m_get_filenamesDavid Bremner
This is essentially copied from the change to notmuch_message_get_filename
2020-07-13lib/n_m_g_filename: catch Xapian exceptions, document NULL returnDavid Bremner
This is the same machinery as applied for notmuch_message_get_{thread,message}_id
2020-07-13lib/message: use LOG_XAPIAN_EXCEPTION in n_m_get_headerDavid Bremner
This is just for consistency, and a small reduction in the amount of boilerplate.
2020-07-03lib/message: catch exception in n_m_get_thread_idDavid Bremner
This allows us to return an error value from the library.
2020-07-03lib: catch error from closed db in n_m_get_message_idDavid Bremner
By catching it at the library top level, we can return an error value.
2020-05-04lib: replace STRNCMP_LITERAL in __message_remove_indexed_termsDavid Bremner
strncmp looks for a prefix that matches, which is very much not what we want here. This fixes the bug reported by Franz Fellner in id:1588595993-ner-8.651@TPL520
2019-06-14lib: run uncrustifyuncrustify
This is the result of running $ uncrustify --replace --config ../devel/uncrustify.cfg *.c *.h *.cc in the lib directory
2019-05-29indexing: record protected subject when indexing cleartextDaniel Kahn Gillmor
When indexing the cleartext of an encrypted message, record any protected subject in the database, which should make it findable and visible in search. Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
2019-05-25lib: support user prefix names in term generationDavid Bremner
This should not change the indexing process yet as nothing calls _notmuch_message_gen_terms with a user prefix name. On the other hand, it should not break anything either. _notmuch_database_prefix does a linear walk of the list of (built-in) prefixes, followed by a logarithmic time search of the list of user prefixes. The latter is probably not really noticable.
2019-05-23n_m_remove_indexed_terms: reduce number of Xapian API calls.David Bremner
Previously this functioned scanned every term attached to a given Xapian document. It turns out we know how to read only the terms we need to preserve (and we might have already done so). This commit replaces many calls to Xapian::Document::remove_term with one call to ::clear_terms, and a (typically much smaller) number of calls to ::add_term. Roughly speaking this is based on the assumption that most messages have more text than they have tags. According to the performance test suite, this yields a roughly 40% speedup on "notmuch reindex '*'"
2019-04-17lib: add 'body:' field, stop indexing headers twice.David Bremner
The new `body:` field (in Xapian terms) or prefix (in slightly sloppier notmuch) terms allows matching terms that occur only in the body. Unprefixed query terms should continue to match anywhere (header or body) in the message. This follows a suggestion of Olly Betts to use the facility (since Xapian 1.0.4) to add the same field with multiple prefixes. The double indexing of previous versions is thus replaced with a query time expension of unprefixed query terms to the various prefixed equivalent. Reindexing will be needed for 'body:' searches to work correctly; otherwise they will also match messages where the term occur in headers (demonstrated by the new tests in T530-upgrade.sh)
2018-09-06lib: calculate message depth in threadDavid Bremner
This will be used in reparenting messages without useful in-reply-to, but with useful references
2018-09-06lib: read reference terms into message struct.David Bremner
The plan is to use these in resolving threads.
2018-09-06lib/thread: sort sibling messages by dateDavid Bremner
For non-root messages, this should not should anything currently, as the messages are already added in date order. In the future we will add some non-root messages in a second pass out of order and the sorting will be useful. It does fix the order of multiple root-messages (although it is overkill for that).
2018-05-26lib: make notmuch_message_get_database() take a const notmuch_message_t*Daniel Kahn Gillmor
This is technically an API change, but it is not an ABI change, and it's merely a statement that limits what the library can do. This is in parallel to notmuch_query_get_database(), which also takes a const pointer.