summaryrefslogtreecommitdiff
path: root/lib/message.cc
AgeCommit message (Collapse)Author
2013-09-03tags_to_maildir_flags: Don't rename if no flags changeLouis Rilling
notmuch_message_tags_to_maildir_flags() unconditionally moves messages from maildir directory "new/" to maildir directory "cur/", which makes messages lose their "new" status in the MUA. However some users want to keep this "new" status after, for instance, an auto-tagging of new messages. However, as Austin mentioned and according to the maildir specification, messages living in "new/" are not allowed to have flags, even if mutt allows it to happen. For this reason, this patch prevents moving messages from "new/" to "cur/", only if no flags have to be changed. It's hopefully enough to satisfy mutt (and maybe other MUAs showing the "new" status) users checking the "new" status. Changelog: * v2: Fix bool type as well as NULL returned despite having no errors (Austin Clements) * v4: Tag the related test (contributed by Michal Sojka) as working Signed-off-by: Louis Rilling <l.rilling@av7.net> [Condition for keeping messages in new/ was extended to satisfy all tests from the previous patch. -Michal Sojka] [Added by David Bremner, to keep the tests passing at each commit] update insert tests for new maildir synchronization rules As of id:1355952747-27350-4-git-send-email-sojkam1@fel.cvut.cz we are more conservative about moving messages from ./new to ./cur. This updates the insert tests to match
2013-05-03lib/message.cc: stale pointer bug (v3)Vladimir Marek
Xapian::TermIterator::operator* returns std::string which is destroyed as soon as (*i).c_str() finishes. The remembered pointer 'term' then references invalid memory. Signed-off-by: Vladimir Marek <vlmarek@volny.cz>
2013-02-18lib: Separate list of all messages from top-level messagesAustin Clements
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.
2012-12-01lib: fix warnings when building with clangJani Nikula
Building notmuch with CC=clang and CXX=clang++ produces the warnings: CC -O2 lib/tags.o lib/tags.c:43:5: warning: expression result unused [-Wunused-value] talloc_steal (tags, list); ^~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/talloc.h:345:143: note: expanded from: ...__location__); __talloc_steal_ret; }) ^~~~~~~~~~~~~~~~~~ 1 warning generated. CXX -O2 lib/message.o lib/message.cc:791:5: warning: expression result unused [-Wunused-value] talloc_reference (message, message->tag_list); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/talloc.h:932:36: note: expanded from: ...(_TALLOC_TYPEOF(ptr))_talloc_reference_loc((ctx),(ptr), __location__) ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 warning generated. Check talloc_reference() return value, and explicitly ignore talloc_steal() return value as it has no failure modes, to silence the warnings.
2012-06-10lib: Treat messages in new/ as maildir messages with no flags setAustin Clements
Previously, notmuch new only synchronized maildir flags to tags for files with a maildir "info" part. Since messages in new/ don't have an info part, notmuch would ignore them for flag-to-tag synchronization. This patch makes notmuch consider messages in new/ to be legitimate maildir messages that simply have no maildir flags set. The most visible effect of this is that such messages now automatically get the unread tag.
2012-06-10lib: Only synchronize maildir flags for messages in maildirsAustin Clements
Previously, we synchronized flags to tags for any message that looked like it had maildir flags in its file name, regardless of whether it was in a maildir-like directory structure. This was asymmetric with tag-to-flag synchronization, which only applied to messages in directories named new/ and cur/ (introduced by 95dd5fe5). This change makes our interpretation stricter and addresses this asymmetry by only synchronizing flags to tags for messages in directories named new/ or cur/. It also prepares us to treat messages in new/ as maildir messages, even though they lack maildir flags.
2012-06-10lib: Move _filename_is_in_maildirAustin Clements
This way notmuch_message_maildir_flags_to_tags can call it. It makes more sense for this to be just above all of the maildir synchronization code rather than mixed in the middle.
2012-05-23lib: Don't needlessly create directory docs in _notmuch_message_remove_filenameAustin Clements
Previously, if passed a filename with a directory that did not exist in the database, _notmuch_message_remove_filename would needlessly create that directory document. Fix it so that doesn't happen.
2012-05-23lib: Perform the same transformation to _notmuch_database_filename_to_direntryAustin Clements
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.
2011-11-21tags_to_maildir_flags: Cleanup double assignementLouis Rilling
The for loop right after already does the job. Signed-off-by: Louis Rilling <l.rilling@av7.net>
2011-11-21lib: Kill last usage of C++ type boolLouis Rilling
Signed-off-by: Louis Rilling <l.rilling@av7.net>
2011-11-14Store "from" and "subject" headers in the database.Austin Clements
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.
2011-10-04lib: make find_message{,by_filename) report errorsAli Polatel
Previously, the functions notmuch_database_find_message() and notmuch_database_find_message_by_filename() functions did not properly report error condition to the library user. For more information, read the thread on the notmuch mailing list starting with my mail "id:871uv2unfd.fsf@gmail.com" Make these functions accept a pointer to 'notmuch_message_t' as argument and return notmuch_status_t which may be used to check for any error condition. restore: Modify for the new notmuch_database_find_message() new: Modify for the new notmuch_database_find_message_by_filename()
2011-09-23lib: Remove message document directly after removing the last file name.Austin Clements
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.
2011-09-23lib: Indicate if there are more filenames after removal.Austin Clements
Make _notmuch_message_remove_filename return NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID if the message has more filenames and fix callers to handle this.
2011-09-12lib: Add missing status check in _notmuch_message_remove_filename.Austin Clements
Previously, this function would synchronize the folder list even if removing the file name failed. Now it returns immediately if removing the file name fails.
2011-06-29Fix folder: coherence issueMark Anderson
Add removal of all ZXFOLDER terms to removal of all XFOLDER terms for each message filename removal. The existing filename-list reindexing will put all the needed terms back in. Test search-folder-coherence now passes. Signed-off-by:Mark Anderson <ma.skies@gmail.com>
2011-06-23fix sum moar typos [comments in source code]Pieter Praet
Various typo fixes in comments within the source code. Signed-off-by: Pieter Praet <pieter@praet.org> Edited-by: Carl Worth <cworth@cworth.org> Restricted to just source-code comments, (and fixed fix of "descriptios" to "descriptors" rather than "descriptions").
2011-05-11Mark some structures in the library interface with visibility=default attribute.Carl Worth
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).
2011-05-11Remove some variables which were set but not used.Carl Worth
gcc (at least as of version 4.6.0) is kind enough to point these out to us, (when given -Wunused-but-set-variable explicitly or implicitly via -Wunused or -Wall). One of these cases was a legitimately unused variable. Two were simply variables (named ignored) we were assigning only to squelch a warning about unused function return values. I don't seem to be getting those warnings even without setting the ignored variable. And the gcc docs. say that the correct way to squelch that warning is with a cast to (void) anyway.
2011-03-21Add the tag list to the unified message metadata pass.Austin Clements
Now each caller of notmuch_message_get_tags only gets a new iterator, instead of a whole new list. In principle this could cause problems with iterating while modifying tags, but through the magic of talloc references, we keep the old tag list alive even after the cache in the message object is invalidated. This reduces my index search from the 3.102 seconds before the unified metadata pass to 1.811 seconds (1.7X faster). Combined with the thread search optimization in b3caef1f0659dac8183441357c8fee500a940889, that makes this query 2.5X faster than when I started.
2011-03-21Add the file name list to the unified message metadata pass.Austin Clements
Even if the caller never uses the file names, there is little cost to simply fetching the file name terms. However, retrieving the full paths requires additional database work, so the expansion from terms to full paths is performed lazily. This also simplifies clearing the filename cache, since that's now handled by the generic metadata cache code. This further reduces my inbox search from 3.102 seconds before the unified metadata pass to 2.206 seconds (1.4X faster).
2011-03-21Add a generic function to get a list of terms with some prefix.Austin Clements
Replace _notmuch_convert_tags with this and simplify _create_filenames_for_terms_with_prefix. This will also come in handy shortly to get the message file name list.
2011-03-21Implement an internal generic string list and use it.Austin Clements
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.
2011-03-21Use a single unified pass to fetch scalar message metadata.Austin Clements
This performs a single pass over a message's term list to fetch the thread ID, message ID, and reply-to, rather than requiring a pass for each. Xapian decompresses the term list anew for each iteration, so this reduces the amount of time spent decompressing message metadata. This reduces my inbox search from 3.102 seconds to 2.555 seconds (1.2X faster).
2011-01-26lib: Save and restore term position in message while indexing.Carl Worth
This fixes the recently addead search-position-overlap bug as demonstrated in the test of the same name.
2011-01-15Add support for folder-based searching.Carl Worth
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.
2011-01-15Correct some minor typos in a commentCarl Worth
Nothing too important here. Just some misspellings I noticed while reading nearby code.
2010-12-07Optimize thread search using matched docid sets.Austin Clements
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).
2010-11-11lib: Fix missing initialization of status field.0.5Carl Worth
This could have been a problematic bug. Fortuinately "gcc -O2" warns about it.
2010-11-11lib: Add two missing static qualifiersCarl Worth
The debian packaging is nice enough to notice when we accidentally leak private symbols to the public interface.
2010-11-11tags_to_maildir_flags: Fix to preserve existing, unsupported flagsCarl Worth
This is to prevent notmuch from destroying any information the user has encoded as flags in the maildir filename. Tests are also added to the test suite to verify the documented behavior.
2010-11-11notmuch_message_tags_to_maildir_flags: Do nothing outside of "new" and "cur"Carl Worth
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/
2010-11-11notmuch_message_tags_to_maildir_flags: Don't exit on failure to rename.Carl Worth
It is totally legitimate for a non-maildir directory to be named "new" (and not have a directory next to it named "cur"). To support this case at least, be silent about any rename failure.
2010-11-11notmuch_message_tags_to_maildir_flags: Fix to rename multiple filesCarl Worth
This function was documented as modifying every filename associated with the message. Fix it to actually do that.
2010-11-11maildir_flags_to_tags: Avoid interpreting "no info" as "no flags set".Carl Worth
If a filename has no maildir info at all, (that is, it does not contain the sequence ":2,"), we consider this distinct from a filename with an empty maildir info, (the ":2," separator is present, but no flags characters follow). Specifically, we regard a missing info field as providing no information, so tags will remain unchanged. On the other hand, an info field that is present but has no flags set will cause various tags to be cleared, (or in the case of "unread", added). This fixes the "remove info" case of the maildir-sync tests in the test suite.
2010-11-11Fix notmuch_message_tags_to_maildir_flags to effect rename immediatelyCarl Worth
We have tests to ensure that when the notmuch library renames a file that that rename takes place immediately in the database, (without requiring something like "notmuch new" to notice the change). This was working when the code was first added, but recently broke in the reworking of the maildir-synchronization interface since the tags_to_maildir_flags function can no longer assume that it is being called as part of _notmuch_message_sync. Fortunately, the fix is as simple as adding an explicit call to _notmuch_message_sync.
2010-11-11Fix notmuch_message_maildir_flags_to_tags to iterate over filenamesCarl Worth
As documented, this function now iterates over all filenames for the message, computing a logical OR of the flags set on the filenames, then uses the final result to set tags on the message. This change fixes 3 of the 10 maildir-sync tests that have been failing since being added.
2010-11-11lib: Add new, public notmuch_message_get_filenamesCarl Worth
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.
2010-11-11lib: Remove the notion of TAGS_INVALIDCarl Worth
This rather ugly hack was recently obviated by the removal of the notmuch_database_set_maildir_sync function. Now, clients must make explicit calls to do any syncrhonization between maildir flags and tags. So the library no longer needs to worry about doing inconsistent synchronization while a message is only partially added.
2010-11-11lib: Rework interface for maildir_flags synchronizationCarl Worth
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).
2010-11-11lib: Remove the synchronization of 'T' flag with "deleted" tag.Carl Worth
Tags in a notmuch database affect all messages with the identical message-ID. But maildir tags affect individual files. And since multiple files can contain the identical message-ID, there is not a one-to-one correspondence between messages affected by tags and flags. This is particularly dangerous with the 'T' (== "trashed") maildir flag and the corresponding "deleted" tag in the notmuch database. Since these flags/tags are often used to trigger irreversible deletion operations, the lack of one-to-one correspondence can be potentially dangerous. For example, consider the following sequence: 1. A third-party application is used to identify duplicate messages in the mail store, and mark all-but-one of each duplicate with the 'T' flag for subsequent deletion. 2. A "notmuch new" operation reads that 'T' flag, adding the "deleted" flag to the corresponding messages within the notmuch database. 3. A subsequent notmuch operation, (such as a "notmuch dump; notmuch restore" cycle) synchronized the "deleted" tag back to the mail store, applying the 'T' flag to all(!) filenames with duplicate message IDs. 4. A third-party application reads the 'T' flags and irreversibly deletes all mail messages which had any duplicates(!). In order to avoid this scenario, we simply refuse to synchronize the 'T' flag with the "deleted" tag. Instead, applications can set 'T' and act on it to delete files, or can set "deleted" and act on it to delete files. But in either case the semantics are clear and there is never dangerous propagation through the one-to-many mapping of notmuch message objects to files.
2010-11-10Make maildir synchronization configurableMichal Sojka
This adds group [maildir] and key 'synchronize_flags' to the configuration file. Its value enables (true) or diables (false) the synchronization between notmuch tags and maildir flags. By default, the synchronization is disabled.
2010-11-10Maildir synchronizationMichal Sojka
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.
2010-11-01lib: Eliminate some redundant includes of xapian.hCarl Worth
Most files including this already include database-private.h which includes xapian.h already.
2010-06-04Avoid database corruption by not adding partially-constructed mail documents.Carl Worth
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.
2010-06-04Fix misnamed function in internal documentation.Carl Worth
The documentation for several functions mentioned _notmuch_message_set_sync which doesn't exist. Fix these to reference _notmuch_message_sync instead.
2010-04-26Add authors member to messageDirk Hohndel
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>
2010-03-09lib: Silence a compiler warning.Carl Worth
The original code was harmless, but apparently some compilers aren't able to think deep enough to catch that.
2010-03-09lib: Rename iterator functions to prepare for reverse iteration.Carl Worth
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'.