aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/notmuch-private.h
Commit message (Collapse)AuthorAge
* lib: Move message ID compression to _notmuch_message_create_for_message_idGravatar Austin Clements2014-10-11
| | | | | | | | Previously, this was performed by notmuch_database_add_message. This happens to be the only caller currently (which is why this was safe), but we're about to introduce more callers, and it makes more sense to put responsibility for ID compression in the lower-level function rather than requiring each caller to handle it.
* lib: Start all function names in notmuch-private.h withGravatar Charles Celerier2014-07-13
| | | | | | | | | | | | | | | | | As noted in devel/STYLE, every private library function should start with _notmuch. This patch corrects function naming that did not adhere to this style in lib/notmuch-private.h. In particular, the old function names that now begin with _notmuch are notmuch_sha1_of_file notmuch_sha1_of_string notmuch_message_file_close notmuch_message_file_get_header notmuch_message_file_open notmuch_message_get_author notmuch_message_set_author Signed-off-by: Charles Celerier <cceleri@cs.stanford.edu>
* lib: replace the header parser with gmimeGravatar Jani Nikula2014-04-05
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The notmuch library includes a full blown message header parser. Yet the same message headers are parsed by gmime during indexing. Switch to gmime parsing completely. These are the main changes: * Gmime stops header parsing at the first invalid header, and presumes the message body starts from there. The current parser is quite liberal in accepting broken headers. The change means we will be much pickier about accepting invalid messages. * The current parser converts tabs used in header folding to spaces. Gmime preserve the tabs. Due to a broken python library used in mailman, there are plenty of mailing lists that produce headers with tabs in header folding, and we'll see plenty of tabs. (This change has been mitigated in preparatory patches.) * For pure header parsing, the current parser is likely faster than gmime, which parses the whole message rather than just the headers. Since we parse the message and its headers using gmime for indexing anyway, this avoids and extra header parsing round when adding new messages. In case of duplicate messages, we'll end up parsing the full message although just headers would be sufficient. All in all this should still speed up 'notmuch new'. * Calls to notmuch_message_get_header() may be slightly slower than previously for headers that are not indexed in the database, due to parsing of the whole message. Within the notmuch code base, notmuch reply is the only such user.
* lib: make folder: prefix literalGravatar Jani Nikula2014-03-11
| | | | | | | | | | | | | | | | | | | | | In xapian terms, convert folder: prefix from probabilistic to boolean prefix, matching the paths, relative from the maildir root, of the message files, ignoring the maildir new and cur leaf directories. folder:foo matches all message files in foo, foo/new, and foo/cur. folder:foo/new does *not* match message files in foo/new. folder:"" matches all message files in the top level maildir and its new and cur subdirectories. This change constitutes a database change: bump the database version and add database upgrade support for folder: terms. The upgrade also adds path: terms. Finally, fix the folder search test for literal folder: search, as some of the folder: matching capabilities are lost in the probabilistic to boolean prefix change.
* lib: fix clang buildGravatar Jani Nikula2013-09-01
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Long story short, fix build on recent (3.2+) clang. The long story for posterity follows. gcc 4.6 added new warnings about structs with greater visibility than their fields. The warnings were silenced by adjusting visibility in commit d5523ead90b6be2b07d4af745b8ed9b980a6b9f1 Author: Carl Worth <cworth@cworth.org> Date: Wed May 11 13:23:13 2011 -0700 Mark some structures in the library interface with visibility=default attribute. Later on, commit 3b76adf9e2c026dd03b820f4c6eab50e25444113 Author: Austin Clements <amdragon@MIT.EDU> Date: Sat Jan 14 19:17:33 2012 -0500 lib: Add support for automatically excluding tags from queries changed visibility of struct _notmuch_string_list for the same reason, and commit 1a53f9f116fa7c460cda3df532be921baaafb082 Author: Mark Walters <markwalters1009@gmail.com> Date: Thu Mar 1 22:30:38 2012 +0000 lib: Add the exclude flag to notmuch_query_search_threads split the struct _notmuch_string_list and its typedef notmuch_string_list_t as a way to make a forward declaration for _notmuch_thread_create(). The subtle difference was that the struct definition now had 'visible' in it, while the typedef didn't, and it was within the #pragma GCC visibility push(hidden) block. This went unnoticed, as the then common versions of clang didn't care about this. A later change in clang (I did not dig into when this change was introduced) caused the following error: CXX -O2 lib/database.o In file included from lib/database.cc:21: In file included from ./lib/database-private.h:33: ./lib/notmuch-private.h:479:8: error: visibility does not match previous declaration struct visible _notmuch_string_list { ^ ./lib/notmuch-private.h:67:33: note: expanded from macro 'visible' ^ ./lib/notmuch-private.h:52:13: note: previous attribute is here ^ 1 error generated. make: *** [lib/database.o] Error 1 This is slightly misleading due to the reference to the #pragma. The real culprit is the typedef within the #pragma. We could just add 'visible' to the typedef, or move the typedef outside of the #pragma, and be done with it, but juggle the declarations a bit to accommodate moving the typedef back with the struct, and keep the visibility attribute in one place. The problem was originally reported by Simonas Kazlauskas <s@kazlauskas.me> in id:20130418102507.GA23688@godbox but I was only able to reproduce and investigate now that I upgraded clang.
* lib: Document which strings are returned in UTF-8Gravatar Austin Clements2013-08-13
| | | | | Any string that ultimately comes from notmuch_message_file_get_header is in UTF-8.
* lib: add --exclude=all optionGravatar Mark Walters2013-05-13
| | | | | | Adds a exclude all option to the lib which means that excluded messages are completely ignored (as if they had actually been deleted).
* lib: Eliminate _notmuch_message_list_appendGravatar Austin Clements2013-02-18
| | | | | This API invited micro-optimized and complicated list pointer manipulation and is no longer used.
* lib: Separate list of all messages from top-level messagesGravatar Austin Clements2013-02-18
| | | | | | | | | | | | Previously, thread.cc built up a list of all messages, then proceeded to tear it apart to transform it into a list of top-level messages. Now we simply build a new list of top-level messages. This simplifies the interface to _notmuch_message_add_reply, eliminates the pointer acrobatics from _resolve_thread_relationships, and will enable us to do things with the list of all messages in the following patches.
* Fix the COERCE_STATUS macroGravatar Justus Winter2012-09-27
| | | | | | | | | | Fix the COERCE_STATUS macro to handle _internal_error being declared as void function. Note that the function _internal_error does not return. Evaluating to NOTMUCH_STATUS_SUCCESS is done purely to appease the compiler. Signed-off-by: Justus Winter <4winter@informatik.uni-hamburg.de>
* lib: Make notmuch_database_get_directory return NULL if the directory is not ↵Gravatar Austin Clements2012-05-23
| | | | | | | | | | | | | | | found Using the new support from _notmuch_directory_create, this makes notmuch_database_get_directory a read-only operation that simply returns the directory object if it exists or NULL otherwise. This also means that notmuch_database_get_directory can work on read-only databases. This change breaks the directory mtime workaround in notmuch-new.c by fixing the exact issue it was working around. This permits mtime update races to prevent scans of changed directories, which non-deterministically breaks a few tests. The next patch fixes this.
* lib: Perform the same transformation to _notmuch_database_filename_to_direntryGravatar Austin Clements2012-05-23
| | | | | | Now _notmuch_database_filename_to_direntry takes a flags argument and can indicate if the necessary directory documents do not exist. Again, callers have been updated, but retain their original behavior.
* lib: Perform the same transformation to _notmuch_database_find_directory_idGravatar Austin Clements2012-05-23
| | | | | | | Now _notmuch_database_find_directory_id takes a flags argument, which it passes through to _notmuch_directory_create and can indicate if the directory does not exist. Again, callers have been updated, but retain their original behavior.
* lib: Make directory document creation optional for _notmuch_directory_createGravatar Austin Clements2012-05-23
| | | | | | | | | | | Previously this function would create directory documents if they didn't exist. As a result, it could only be used on writable databases. This adds an argument to make creation optional and to make this function work on read-only databases. We use a flag argument to avoid a bare boolean and to permit future expansion. Both callers have been updated, but currently retain the old behavior. We'll take advantage of the new argument in the following patches.
* lib: work around talloc_steal usage from C++ codeGravatar Jani Nikula2012-04-15
| | | | | | | | | | | | | | | | Implicit typecast from 'void *' to 'T *' is okay in C, but not in C++. In talloc_steal, an explicit cast is provided for type safety in some GCC versions. Otherwise, a cast is required. Provide a template function for this to maintain type safety, and redefine talloc_steal to use it. The template must be outside the extern "C" block (NOTMUCH_BEGIN_DECLS and NOTMUCH_END_DECLS), but keep it within the GCC visibility #pragma. No functional changes, apart from making the library build with compilers other than recent GCC. Signed-off-by: Jani Nikula <jani@nikula.org>
* lib: Add the exclude flag to notmuch_query_search_threadsGravatar Mark Walters2012-03-02
| | | | | | | | | | | Add the NOTMUCH_MESSAGE_FLAG_EXCLUDED flag to notmuch_query_search_threads. Implemented by inspecting the tags directly in _notmuch_thread_create/_thread_add_message rather than as a Xapian query for speed reasons. Note notmuch_thread_get_matched_messages now returns the number of non-excluded matching messages. This API is not totally desirable but fixing it means breaking binary compatibility so we delay that.
* lib: Make notmuch_query_search_messages set the exclude flagGravatar Mark Walters2012-03-02
| | | | | | | | | | Add a flag NOTMUCH_MESSAGE_FLAG_EXCLUDED which is set by notmuch_query_search_messages for excluded messages. Also add an option omit_excluded_messages to the search that we do not want the excludes at all. This exclude flag will be added to notmuch_query_search threads in the next patch.
* lib: Add support for automatically excluding tags from queriesGravatar Austin Clements2012-01-16
| | | | | | This is useful for tags like "deleted" and "spam" that people generally want to exclude from query results. These exclusions will be overridden if a tag is explicitly mentioned in a query.
* Store "from" and "subject" headers in the database.Gravatar Austin Clements2011-11-14
| | | | | | | | | | | | | | This is a rebase and cleanup of Istvan Marko's patch from id:m3pqnj2j7a.fsf@zsu.kismala.com Search retrieves these headers for every message in the search results. Previously, this required opening and parsing every message file. Storing them directly in the database significantly reduces IO and computation, speeding up search by between 50% and 10X. Taking full advantage of this requires a database rebuild, but it will fall back to the old behavior for messages that do not have headers stored in the database.
* xutil.c: remove duplicate copies, create new library libutil.a to contain xutil.Gravatar David Bremner2011-10-30
| | | | | | | We keep the lib/xutil.c version. As a consequence, also factor out _internal_error and associated macros. It might be overkill to make a new file error_util.c for this, but _internal_error does not really belong in database.cc.
* lib: Remove message document directly after removing the last file name.Gravatar Austin Clements2011-09-23
| | | | | | | | | | | | Previously, notmuch_database_remove_message would remove the message file name, sync the change to the message document, re-find the message document, and then delete it if there were no more file names. An interruption after sync'ing would result in a file-name-less, permanently un-removable zombie message that would produce errors and odd results in searches. We could wrap this in an atomic section, but it's much simpler to eliminate the round-about approach and just delete the message document instead of sync'ing it if we removed the last filename.
* Mark some structures in the library interface with visibility=default attribute.Gravatar Carl Worth2011-05-11
| | | | | | | | | | | | | As of gcc 4.6, there are new warnings from -Wattributes along the lines of: warning: ‘_notmuch_messages’ declared with greater visibility than the type of its field ‘_notmuch_messages::iterator’ [-Wattributes] To squelch these, we decorate all such containing structs with __attribute__((visibility("default"))). We take care to let only the C++ compiler see this, (since the C compiler would otherwise warn about ignored visibility attributes on types).
* Implement an internal generic string list and use it.Gravatar Austin Clements2011-03-21
| | | | | | | | | | | | This replaces the guts of the filename list and tag list, making those interfaces simple iterators over the generic string list. The directory, message filename, and tags-related code now build generic string lists and then wraps them in specific iterators. The real wins come in later patches, when we use these for even more generic functionality. As a nice side-effect, this also eliminates the annoying dependency on GList in the tag list.
* Add support for folder-based searching.Gravatar Carl Worth2011-01-15
| | | | | | | | A new "folder:" prefix in the query string can now be used to match the directories in which mail files are stored. The addition of this feature causes the recently added search-by-folder tests to now pass.
* Optimize thread search using matched docid sets.Gravatar Austin Clements2010-12-07
| | | | | | | | | | | | | | | | | This reduces thread search's 1+2t Xapian queries (where t is the number of matched threads) to 1+t queries and constructs exactly one notmuch_message_t for each message instead of 2 to 3. notmuch_query_search_threads eagerly fetches the docids of all messages matching the user query instead of lazily constructing message objects and fetching thread ID's from term lists. _notmuch_thread_create takes a seed docid and the set of all matched docids and uses a single Xapian query to expand this docid to its containing thread, using the matched docid set to determine which messages in the thread match the user query instead of using a second Xapian query. This reduces the amount of time required to load my inbox from 4.523 seconds to 3.025 seconds (1.5X faster).
* notmuch_message_tags_to_maildir_flags: Do nothing outside of "new" and "cur"Gravatar Carl Worth2010-11-11
| | | | | | | | | | | Some people use notmuch with non-maildir files, (for example, email messages in MH format, or else cool things like using sluk[*] to suck down feeds into a format that notmuch can index). To better support uses like that, don't do any renaming for files that are not in a directory named either "new" or "cur". [*] https://github.com/krl/sluk/
* lib: Add new, public notmuch_message_get_filenamesGravatar Carl Worth2010-11-11
| | | | | | | | | | | | | | | | | | This augments the existing notmuch_message_get_filename by allowing the caller access to all filenames in the case of multiple files for a single message. To support this, we split the iterator (notmuch_filenames_t) away from the list storage (notmuch_filename_list_t) where previously these were a single object (notmuch_filenames_t). Then, whenever the user asks for a file or filename, the message object lazily creates a complete notmuch_filename_list_t and then: For notmuch_message_get_filename, returns the first filename in the list. For notmuch_message_get_filenames, creates and returns a new iterator for the filename list.
* lib: Add new implementation of notmuch_filenames_tGravatar Carl Worth2010-11-11
| | | | | | | | | | | | The new implementation is simply a talloc-based list of strings. The former support (a list of database terms with a common prefix) is implemented by simply pre-iterating over the terms and populating the list. This should provide no performance disadvantage as callers of thigns like notmuch_directory_get_child_files are very likely to always iterate over all filenames anyway. This new implementation of notmuch_filenames_t is in preparation for adding API to query all of the filenames for a single message.
* lib: Rework interface for maildir_flags synchronizationGravatar Carl Worth2010-11-11
| | | | | | | | | | | | | Instead of having an API for setting a library-wide flag for synchronization (notmuch_database_set_maildir_sync) we instead implement maildir synchronization with two new library functions: notmuch_message_maildir_flags_to_tags and notmuch_message_tags_to_maildir_flags These functions are nicely documented here, (though the implementation does not quite match the documentation yet---as plainly evidenced by the current results of the test suite).
* Maildir synchronizationGravatar Michal Sojka2010-11-10
| | | | | | | | | | | | | | | | | | | | | | | | | | This patch allows bi-directional synchronization between maildir flags and certain tags. The flag-to-tag mapping is defined by flag2tag array. The synchronization works this way: 1) Whenever notmuch new is executed, the following happens: o New messages are tagged with configured new_tags. o For new or renamed messages with maildir info present in the file name, the tags defined in flag2tag are either added or removed depending on the flags from the file name. 2) Whenever notmuch tag (or notmuch restore) is executed, a new set of flags based on the tags is constructed for every message and a new file name is prepared based on the old file name but with the new flags. If the flags differs and the old message was in 'new' directory then this is replaced with 'cur' in the new file name. If the new and old file names differ, the file is renamed and notmuch database is updated accordingly. The rename happens before the database is updated. In case of crash between rename and database update, the next run of notmuch new brings the database in sync with the mail store again.
* lib: Add GCC visibility(hidden) pragmas to private header files.Gravatar Carl Worth2010-11-01
| | | | | | This prevents any of the private functions from being leaked out through the library interface (at least when compiling with a recent-enough gcc to support the visibility pragma).
* Add support (and tests) for messages with really long message IDs.Gravatar Carl Worth2010-06-04
| | | | | | | | | | | | | | | | | | | | | | | Scott Henson reported an internal error that occurred when he tried to add a message that referenced another message with a message ID well over 300 characters in length. The bug here was running into a Xapian limit for the length of metadata key names, (which is even more restrictive than the Xapian limit for the length of terms). We fix this by noticing long message ID values and instead using a message ID of the form "notmuch-sha1-<sha1_sum_of_message_id>". That is, we use SHA1 to generate a compressed, (but still unique), version of the message ID. We add support to the test suite to exercise this fix. The tests add a message referencing the long message ID, then add the message with the long message ID, then finally add another message referencing the long ID. Each of these tests exercise different code paths where the special handling is implemented. A final test ensures that all three messages are stitched together into a single thread---guaranteeing that the three code paths all act consistently.
* Avoid database corruption by not adding partially-constructed mail documents.Gravatar Carl Worth2010-06-04
| | | | | | | | | | | | | | | | | Previously we were using Xapian's add_document to allocate document ID values for notmuch_message_t objects. This had the drawback of adding a partially constructed mail document to the database. If notmuch was subsequently interrupted before fully populating this document, then later runs would be quite confused when seeing the partial documents. There are reports from the wild of people hitting internal errors of the form "Message ... has no thread ID" for example, (which is currently an unrecoverable error). We fix this by manually allocating document IDs without adding documents. With this change, we never call Xapian's add_document method, but only replace_document with either the current document ID of a message or a new one that we have allocated.
* Make Received: header special in notmuch_message_file_get_headerGravatar Dirk Hohndel2010-04-26
| | | | | | | | | | | | With this patch the Received: header becomes special in the way we treat headers - this is the only header for which we concatenate all the instances we find (instead of just returning the first one). This will be used in the From guessing code for replies as we need to be able to walk ALL of the Received: headers in a message to have a good chance to guess which mailbox this email was delivered to. Signed-off-by: Dirk Hohndel <hohndel@infradead.org>
* Add authors member to messageGravatar Dirk Hohndel2010-04-26
| | | | | | | message->authors contains the author's name (as we want to print it) get / set methods are declared in notmuch-private.h Signed-off-by: Dirk Hohndel <hohndel@infradead.org>
* Name thread based on matching msgs instead of first msg.Gravatar Jesse Rosenthal2010-04-21
| | | | | | | | | | | | | | | | | | | | | | At the moment all threads are named based on the name of the first message in the thread. However, this can cause problems if people either start new threads by replying-all (as unfortunately, many out there do) or change the subject of their mails to reflect a shift in a thread on a list. This patch names threads based on (a) matches for the query, and (b) the search order. If the search order is oldest-first (as in the default inbox) it chooses the oldest matching message as the subject. If the search order is newest-first it chooses the newest one. Reply prefixes ("Re: ", "Aw: ", "Sv: ", "Vs: ") are ignored (case-insensitively) so a Re: won't change the subject. Note that this adds a "sort" argument to _notmuch_thread_create and _thread_add_matched_message, so that when constructing the thread we can be aware of the sort order. Signed-off-by: Jesse Rosenthal <jrosenthal@jhu.edu>
* lib: Rename iterator functions to prepare for reverse iteration.Gravatar Carl Worth2010-03-09
| | | | | | | | We rename 'has_more' to 'valid' so that it can function whether iterating in a forward or reverse direction. We also rename 'advance' to 'move_to_next' to setup parallel naming with the proposed functions 'move_to_first', 'move_to_last', and 'move_to_previous'.
* lib: Split the database upgrade into two phases for safer operation.Gravatar Carl Worth2010-01-09
| | | | | | | | | The first phase copies data from the old format to the new format without deleting anything. This allows an old notmuch to still use the database if the upgrade process gets interrupted. The second phase performs the deletion (after updating the database version number). If the second phase is interrupted, there will be some unused data in the database, but it shouldn't cause any actual harm.
* lib: Implement versioning in the database and provide upgrade function.Gravatar Carl Worth2010-01-07
| | | | | | | | | | | | | | | | | | | | | | | | The recent support for renames in the database is our first time (since notmuch has had more than a single user) that we have a database format change. To support smooth upgrades we now encode a database format version number in the Xapian metadata. Going forward notmuch will emit a warning if used to read from a database with a newer version than it natively supports, and will refuse to write to a database with a newer version. The library also provides functions to query the database format version: notmuch_database_get_version to ask if notmuch wants a newer version than that: notmuch_database_needs_upgrade and a function to actually perform that upgrade: notmuch_database_upgrade
* Prefer READ_ONLY consistently over READONLY.Gravatar Carl Worth2010-01-07
| | | | | | Previously we had NOTMUCH_DATABASE_MODE_READ_ONLY but NOTMUCH_STATUS_READONLY_DATABASE which was ugly and confusing. Rename the latter to NOTMUCH_STATUS_READ_ONLY_DATABASE for consistency.
* lib: Consolidate checks for read-only database.Gravatar Carl Worth2010-01-07
| | | | | | | | | | | Previously, many checks were deep in the library just before a cast operation. These have now been replaced with internal errors and new checks have instead been added at the beginning of all top-levelentry points requiring a read-write database. The new checks now also use a single function for checking and printing the error message. This will give us a convenient location to extend the check, (such as based on database version as well).
* lib: Implement new notmuch_directory_t API.Gravatar Carl Worth2010-01-06
| | | | | | | This new directory ojbect provides all the infrastructure needed to detect when files or directories are deleted or renamed. There's still code needed on top of this (within "notmuch new") to actually do that detection.
* database: Abstract _filename_to_direntry from _add_messageGravatar Carl Worth2010-01-06
| | | | | | The code to map a filename to a direntry is something that we're going to want in a future _remove_message function, so put it in a new function _notmuch_database_filename_to_direntry .
* database: Allowing storing multiple filenames for a single message ID.Gravatar Carl Worth2010-01-06
| | | | | | The library interface is unchanged so far, (still just notmuch_database_add_message), but internally, the old _set_filename function is now _add_filename instead.
* database: Store mail filename as a new 'direntry' term, not as 'data'.Gravatar Carl Worth2010-01-06
| | | | | | | | | | Instead of storing the complete message filename in the data portion of a mail document we now store a 'direntry' term that contains the document ID of a directory document and also the basename of the message filename within that directory. This will allow us to easily store multple filenames for a single message, and will also allow us to find mail documents for files that previously existed in a directory but that have since been deleted.
* database: Split _find_parent_id into _split_path and _find_directory_idGravatar Carl Worth2010-01-06
| | | | | | Some pending commits want the _split_path functionality separate from mapping a directory to a document ID. The split_path function now returns the basename as well as the directory name.
* database: Export _notmuch_database_find_parent_id for internal use.Gravatar Carl Worth2010-01-06
| | | | | | We'll soon have mail documents referring to their parent directory's directory documents, so we'll need access to _find_parent_id in files such as message.cc.
* lib: Abstract the extraction of a relative path from set_filenameGravatar Carl Worth2010-01-06
| | | | | | We'll soon be having multiple entry points that accept a filename path, so we want common code for getting a relative path from a potentially absolute path.
* lib: Add missing value to notmuch_private_status_t enum.Gravatar Carl Worth2010-01-06
| | | | | | And fix the initialization such that the private enum will always have distinct values from the public enum even if we similarly miss the addition of a new public value in the future.
* Nuke the remainings of _notmuch_message_add_thread_id.Gravatar Fernando Carrijo2009-12-09
| | | | | | | | | | The function _notmuch_message_add_thread_id has been removed from the private interface of notmuch. There's no reason for one to keep a declaration of its prototype in the code base. Also, lets update a commentary that referenced that function and escaped from previous scrutiny. Signed-off-by: Fernando Carrijo <fcarrijo@yahoo.com.br>