summaryrefslogtreecommitdiff
path: root/lib/database.cc
AgeCommit message (Collapse)Author
2020-04-23build: drop support for xapian versions less than 1.4Tomi Ollila
Xapian 1.4 is over 3 years old now (1.4.0 released 2016-06-24), and 1.2 has been deprecated in Notmuch version 0.27 (2018-06-13). Xapian 1.4 supports compaction, field processors and retry locking; conditionals checking compaction and field processors were removed but user may want to disable retry locking at configure time so it is kept.
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-25lib/database: index user headers.David Bremner
This essentially involves calling _notmuch_message_gen_terms once for each user defined header.
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-25lib: cache user prefixes in database objectDavid Bremner
This will be used to avoid needing a database access to resolve a db prefix from the corresponding UI prefix (e.g. when indexing). Arguably the setup of the separate header map does not belong here, since it is about indexing rather than querying, but we currently don't have any other indexing setup to do.
2019-05-25lib: setup user headers in query parserDavid Bremner
These tests will need to be updated if the Xapian query print/debug format changes.
2019-05-03gmime-cleanup: drop unused gmime #defines and simplify g_mime_init ()Daniel Kahn Gillmor
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-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)
2019-03-31lib: update commentary about path/folder termsDavid Bremner
We missed this when we changed to binary fields.
2019-03-31lib: add clarification about the use of "prefix" in the docs.David Bremner
2019-03-31lib: drop comment about only indexing one file.David Bremner
Although the situation is complicated by the value fields (which are taken from a single file), this comment is now more false than true.
2018-05-07lib: add thread subqueries.David Bremner
This change allows queries of the form thread:{from:me} and thread:{from:jian} and not thread:{from:dave} This is still somewhat brute-force, but it's a big improvement over both the shell script solution and the previous proposal [1], because it does not build the whole thread structure just generate a query. A further potential optimization is to replace the calls to notmuch with more specialized Xapian code; in particular it's not likely that reading all of the message metadata is a win here. [1]: id:20170820213240.20526-1-david@tethera.net
2017-12-28Revert "lib: add thread subqueries."David Bremner
This reverts commit 4f5bbaf7e2cecfe5022ba4b28915cccfb7ccb12d.
2017-12-25lib: add thread subqueries.David Bremner
This change allows queries of the form thread:{from:me} and thread:{from:jian} and not thread:{from:dave} This is still somewhat brute-force, but it's a big improvement over both the shell script solution and the previous proposal [1], because it does not build the whole thread structure just generate a query. A further potential optimization is to replace the calls to notmuch with more specialized Xapian code; in particular it's not likely that reading all of the message metadata is a win here. [1]: id:20170820213240.20526-1-david@tethera.net
2017-10-20crypto: make shared crypto code behave library-likeDaniel Kahn Gillmor
If we're going to reuse the crypto code across both the library and the client, then it needs to report error states properly and not write to stderr.
2017-10-09lib: convert notmuch_bool_t to stdbool internallyJani 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 lib internally to stdbool.
2017-08-22database: move striping of trailing '/' into helper functionYuri Volchkov
Stripping trailing character is not that uncommon operation. Particularly, the next patch has to perform it as well. Lets move it to the separate function to avoid code duplication. Also the new function has a little improvement: if the character to strip is repeated several times in the end of a string, function strips them all. Signed-off-by: Yuri Volchkov <yuri.volchkov@gmail.com>
2017-08-01lib: isolate n_d_add_message and helper functions into own fileDavid Bremner
'database.cc' is becoming a monster, and it's hard to follow what the various static functions are used for. It turns out that about 1/3 of this file notmuch_database_add_message and helper functions not used by any other function. This commit isolates this code into it's own file. Some side effects of this refactoring: - find_doc_ids becomes the non-static (but still private) _notmuch_database_find_doc_ids - a few instances of 'string' have 'std::' prepended, avoiding the need for 'using namespace std;' in the new file.
2017-05-09lib: Add regexp expansion for for tags and pathsDavid Bremner
From a UI perspective this looks similar to what was already provided for from, subject, and mid, but the implementation is quite different. It uses the database's list of terms to construct a term based query equivalent to the passed regular expression.
2017-05-09lib: Add regexp searching for mid: prefixDavid Bremner
The bulk of the change is passing in the field options to the regexp field processor, so that we can properly handle the fallback (non-regexp case).
2017-03-22lib: replace deprecated n_q_count_messages with status returning versionDavid Bremner
This function was deprecated in notmuch 0.21. We re-use the name for a status returning version, and deprecate the _st name. One or two remaining uses of the (removed) non-status returning version fixed at the same time
2017-03-22lib: replace deprecated n_q_search_messages with status returning versionDavid Bremner
This function was deprecated in notmuch 0.21. We re-use the name for a status returning version, and deprecate the _st name.
2017-03-10lib/database: reduce try block scope to things that really need itJani Nikula
No need to maintain the pure C stuff within a try block, it's arguably confusing. This also reduces indent for a bunch of code. No functional changes.
2017-03-03lib: add mid: as a synonym for id:David Bremner
mid: is the url scheme suggested by URL 2392. We also plan to introduce more flexible searches for mid: than are possible with id: (in order not to break assumptions about the special behaviour of id:, e.g. identifying at most one message).
2017-03-03lib: regexp matching in 'subject' and 'from'David Bremner
the idea is that you can run % notmuch search subject:/<your-favourite-regexp>/ % notmuch search from:/<your-favourite-regexp>/ or % notmuch search subject:"your usual phrase search" % notmuch search from:"usual phrase search" This feature is only available with recent Xapian, specifically support for field processors is needed. It should work with bindings, since it extends the query parser. This is easy to extend for other value slots, but currently the only value slots are date, message_id, from, subject, and last_mod. Date is already searchable; message_id is left for a followup commit. This was originally written by Austin Clements, and ported to Xapian field processors (from Austin's custom query parser) by yours truly.
2017-03-03lib: create field processors from prefix tableDavid Bremner
This is a bit more code than hardcoding the two existing field processors, but it should make it easy to add more.
2017-02-25lib: add _notmuch_database_reopenDavid Bremner
The main expected use is to recover from a Xapian::DatabaseChanged exception.
2017-02-23Merge branch 'release'David Bremner
Merge in g_hash_table read-after-free fix
2017-02-22lib: fix g_hash_table related read-after-free bugDavid Bremner
The two g_hash_table functions (insert, add) have different behaviour with respect to existing keys. g_hash_table_insert frees the new key, while g_hash_table_add (which is really g_hash_table_replace in disguise) frees the existing key. With this change 'ref' is live until the end of the function (assuming single-threaded access to 'hash'). We can't guarantee it will continue to be live in the future (i.e. there may be a future key duplication) so we copy it with the allocation context passed to parse_references (in practice this is the notmuch_message_t object whose parents we are finding). Thanks to Tomi for the simpler approach to the problem based on reading the fine glib manual.
2017-02-18lib: Let Xapian manage the memory for FieldProcessorsDavid Bremner
It turns out this is exactly what release() is for; Xapian will deallocate the objects when it's done with them.
2017-02-18lib: merge internal prefix tablesDavid Bremner
Replace multiple tables with some flags in a single table. This makes the code in notmuch_database_open_verbose a bit shorter, and it should also make it easier to add other options to fields, e.g. regexp searching.
2016-10-25lib: replace deprecated xapian call 'flush()' with 'commit()'David Bremner
This will make notmuch incompatible with Xapian before 1.1.0, which is more than 6 years old this point.
2016-10-06require xapian >= 1.2.6David Bremner
It seems that no-one tried to compile without Xapian compact support since March of 2015, since that's when I introduced a syntax error in that branch of the ifdef. Given the choice of maintaining this underused branch of code, or bumping the Xapian dependency to a version from 2011, it seems reasonable to do the latter.
2016-09-28lib/database.cc: fix misleading indentationTomi Ollila
Found by gcc 6.1.1 -Wmisleading-indentation option (set by -Wall).
2016-09-21add property: query prefix to search for specific propertiesDaniel Kahn Gillmor
We want to be able to query the properties directly, like: notmuch count property:foo=bar which should return a count of messages where the property with key "foo" has value equal to "bar".
2016-09-21lib: read "property" terms from messages.David Bremner
This is a first step towards providing an API to attach arbitrary (key,value) pairs to messages and retrieve all of the values for a given key.
2016-08-18lib: reword comment about XFOLDER: prefixDavid Bremner
I believe the current one is misleading, because in my experiments Xapian did not add : when prefix and term were both upper case. Indeed, it's hard to see how it could, because prefixes are added at a layer above Xapian in our code. See _notmuch_message_add_term for an example. Also try to explain why this is a good idea. As far as I can ascertain, this is more of an issue for a system trying to work with an unknown set of prefixes. Since notmuch has a fixed set of prefixes, and we can hopefully be trusted not to add XGOLD and XGOLDEN as prefixes, it is harder for problems to arise.
2016-08-09lib: provide _notmuch_database_log_appendDavid Bremner
_notmuch_database_log clears the log buffer each time. Rather than introducing more complicated semantics about for this function, provide a second function that does not clear the buffer. This is mainly a convenience function for callers constructing complex or multi-line log messages. The changes to query.cc are to make sure that the common code path of the new function is tested.
2016-06-29Use the Xapian::DB_RETRY_LOCK flag when availableIstvan Marko
Xapian 1.3 has introduced the DB_RETRY_LOCK flag (Xapian bug 275). Detect it in configure and optionally use it. With this flag commands that need the write lock will wait for their turn instead of aborting when it's not immediately available. Amended by db: allow disabling in configure
2016-06-10lib: fix memory leak of field processor objectsDavid Bremner
The field processor objects need to be deallocated explicitly just like the range processors (or a talloc destructor defined).
2016-06-07lib: document config metadataDavid Bremner
This probably should have been part of 3458e3c89c, but I missed it.
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.
2016-06-05lib: whitespace cleanupTomi Ollila
Cleaned the following whitespace in lib/* files: lib/index.cc: 1 line: trailing whitespace lib/database.cc 5 lines: 8 spaces at the beginning of line lib/notmuch-private.h: 4 lines: 8 spaces at the beginning of line lib/message.cc: 1 line: trailing whitespace lib/sha1.c: 1 line: empty lines at the end of file lib/query.cc: 2 lines: 8 spaces at the beginning of line lib/gen-version-script.sh: 1 line: trailing whitespace
2016-05-25lib: add support for named queriesDavid Bremner
This relies on the optional presense of xapian field processors, and the library config API.
2016-05-08lib: optionally support single argument date: queriesDavid Bremner
This relies on the FieldProcessor API, which is only present in xapian >= 1.3.
2016-04-12lib: clean up _notmuch_database_split_pathJani Nikula
Make the logic it a bit easier to read. No functional changes.
2016-04-12lib: fix handling of one character long directory names at top levelJani Nikula
The code to skip multiple slashes in _notmuch_database_split_path() skips back one character too much. This is compensated by a +1 in the length parameter to the strndup() call. Mostly this works fine, but if the path is to a file under a top level directory with one character long name, the directory part is mistaken to be part of the file name (slash == path in code). The returned directory name will be the empty string and the basename will be the full path, breaking the indexing logic in notmuch new. Fix the multiple slash skipping to keep the slash variable pointing at the last slash, and adjust strndup() accordingly. The bug was introduced in commit e890b0cf4011fd9fd77ebd87343379e4a778888b Author: Carl Worth <cworth@cworth.org> Date: Sat Dec 19 13:20:26 2009 -0800 database: Store the parent ID for each directory document. just a little over two months after the initial commit in the Notmuch code history, making this the longest living bug in Notmuch to date.
2015-11-23forbid atomic transactions on writable, upgradable databasesSteven Allen
We can't (but currently do) allow upgrades within transactions because upgrades need their own transactions. We don't want to re-use the current transaction because bailing out of an upgrade would mean loosing all previous changes (because our "atomic" transactions don't commit before hand). This gives us two options: 1. Fail at the beginning of upgrade (tell the user to end the transaction, upgrade, and start over). 2. Don't allow the user to start the transaction. I went with the latter because: 1. There is no reason to call `begin_atomic` unless you intend to to write to the database and anyone intending to write to the database should upgrade it first. 2. This means that nothing inside an atomic transaction can ever fail with NOTMUCH_STATUS_UPGRADE_REQUIRED.
2015-10-05lib: migrate notmuch_database_upgrade to new query_search APIDavid Bremner
Here we depend on the error path cleaning up query
2015-10-05lib: add versions of n_q_count_{message,threads} with status returnDavid Bremner
Although I think it's a pretty bad idea to continue using the old API, this allows both a more gentle transition for clients of the library, and allows us to break one monolithic change into a series