summaryrefslogtreecommitdiff
path: root/lib/thread.cc
AgeCommit message (Collapse)Author
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-18lib/thread: replace use of deprecated notmuch_message_get_flagDavid Bremner
This adds one more reason why _notmuch_thread_create might return NULL, but those were not previously enumerated, so no promises are broken.
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: 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-03gmime-cleanup: pass NULL arguments explicitly where GMime 3.0 expects itDaniel Kahn Gillmor
Several GMime 2.6 functions sprouted a change in the argument order in GMime 3.0. We had a compatibility layer here to be able to handle compiling against both GMime 2.6 and 3.0. Now that we're using 3.0 only, rip out the compatibility layer for those functions with changed argument lists, and explicitly use the 3.0 argument lists. Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
2018-09-06lib/thread: change _resolve_thread_relationships to use depthsDavid Bremner
We (finally) implement the XXX comment. It requires a bit of care not to reparent all of the possible toplevel messages. _notmuch_messages_has_next is not ready to be a public function yet, since it punts on the mset case. We know in the one case it is called, the notmuch_messages_t is just a regular list / iterator.
2018-09-06lib/thread: rewrite _parent_or_toplevel to use depthsDavid Bremner
This is part 1/2 of changing the reparenting of alleged toplevel messages to use a "deep" reference rather than just the first one found.
2018-09-06lib/thread: initial use of references as for fallback parentingDavid Bremner
This is mainly to lay out the structure of the final code. The problem isn't really solved yet, although some very simple cases are better (hence the fixed test). We need two passes through the messages because we need to be careful not to re-parent too many messages and end up without any toplevel messages.
2018-09-06use EMPTY_STRING in _parent_via_in_reply_toDavid Bremner
This is a review suggestion [1] of Tomi. I decided not to squash it so that the code movement remains clear. [1]: id:m2pnxxgf5q.fsf@guru.guru-group.fi
2018-09-06lib/thread: refactor in_reply_to testDavid Bremner
This is not a complete win in code-size, but it makes the code (which is about to get more complicated) easier to follow.
2018-09-06lib: add _notmuch_message_list_emptyDavid Bremner
There is no public notmuch_message_list_t public interface, so to this is added to the private API. We use it immediately in thread.cc; future commits will use it further.
2018-09-06lib/thread: add macro for debug printing of threadingDavid Bremner
This is analogous to DEBUG_DATABASE_SANITY, and is intended to help debugging and to help users submit bug reports.
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-04-23lib: choose oldest message when breaking reference loopsDavid Bremner
This preserves a sensible thread order
2018-04-20lib: break reference loop by choosing arbitrary top level msgDavid Bremner
Other parts of notmuch (e.g. notmuch show) expect each thread to contain at least one top level message, and crash if this expectation is not met.
2017-12-21lib: return "" rather than NULL from notmuch_thread_get_authorsDavid Bremner
The current behaviour is at best under-documented. The modified test in T470-missing-headers.sh previously relied on printf doing the right thing with NULL, which seems icky. The use of talloc_strdup here is probably overkill, but it avoids having to enforce that thread->authors is never mutated outside _resolve_thread_authors_string.
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-01lib: add notmuch_thread_get_total_filesDavid Bremner
This is relatively inexpensive in terms of run time and implementation cost as we are already traversing the list of messages in a thread.
2017-05-13build: visibility=default for library structs is no longer neededJani Nikula
Commit d5523ead90b6 ("Mark some structures in the library interface with visibility=default attribute.") fixed some mixed visibility issues with structs. With the symbol default visibility reversed, this is no longer a problem.
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.
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-10-05lib: migrate thread.cc to new query_search APIDavid Bremner
here we rely on thread_id_query being attached to the local talloc context, so no new cleanup code is needed.
2015-09-04lib: note remaining uses of deprecated message search APIDavid Bremner
The two remaining cases in the lib seem to require more than a simple replacement of the old call, with the new call plus a check of the return value.
2015-01-19lib: Fix use after freeTodd
_thread_set_subject_from_message sometimes replaces the subject, making the cur_subject point to free'd memory ==6550== ERROR: AddressSanitizer: heap-use-after-free on address 0x601a0000bec0 at pc 0x4464a4 bp 0x7fffa40be910 sp 0x7fffa40be908 READ of size 1 at 0x601a0000bec0 thread T0 #0 0x4464a3 in _thread_add_matched_message /home/todd/.apps/notmuch/lib/thread.cc:369 #1 0x443c2c in notmuch_threads_get /home/todd/.apps/notmuch/lib/query.cc:496 #2 0x41d947 in do_search_threads /home/todd/.apps/notmuch/notmuch-search.c:131 #3 0x40a3fe in main /home/todd/.apps/notmuch/notmuch.c:345 #4 0x7f4e535b4ec4 in __libc_start_main /build/buildd/eglibc-2.19/csu/libc-start.c:287 #5 0x40abe6 in _start ??:? 0x601a0000bec0 is located 96 bytes inside of 134-byte region [0x601a0000be60,0x601a0000bee6) freed by thread T0 here: #0 0x7f4e54e6933a in __interceptor_free ??:? #1 0x7f4e54482fab in _talloc_free ??:? previously allocated by thread T0 here: #0 0x7f4e54e6941a in malloc ??:? #1 0x7f4e54485b5d in talloc_strdup ??:?
2015-01-19lib: Fix potential invalid read past an empty stringTodd
==22884== ERROR: AddressSanitizer: heap-buffer-overflow on address 0x601600008291 at pc 0x7ff6295680e5 bp 0x7fff4ab9aa40 sp 0x7fff4ab9aa08 READ of size 1 at 0x601600008291 thread T0 #0 0x7ff6295680e4 in __interceptor_strcmp ??:? #1 0x44763b in _thread_add_message /home/todd/.apps/notmuch/lib/thread.cc:255 #2 0x4459e8 in notmuch_threads_get /home/todd/.apps/notmuch/lib/query.cc:496 #3 0x41e2a7 in do_search_threads /home/todd/.apps/notmuch/notmuch-search.c:131 #4 0x40a408 in main /home/todd/.apps/notmuch/notmuch.c:345 #5 0x7ff627cb9ec4 in __libc_start_main /build/buildd/eglibc-2.19/csu/libc-start.c:287 #6 0x40abf3 in _start ??:? 0x601600008291 is located 0 bytes to the right of 97-byte region [0x601600008230,0x601600008291) allocated by thread T0 here: #0 0x7ff62956e41a in malloc ??:? #1 0x7ff628b8ab5d in talloc_strdup ??:?
2015-01-17thread.cc: Avoid empty thread names if possible.Jesse Rosenthal
Currently the thread is named based on either the oldest or newest matching message (depending on the search order). If this message has an empty subject, though, the thread will show up with an empty subject in the search results. (See the thread starting with `id:1412371140-21051-1-git-send-email-david@tethera.net` for an example.) This changes the behavior so it will use a non-empty name for the thread if possible. We name threads based on (a) non-empty 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 non-empty message as the subject. If the search order is newest-first it chooses the newest one.
2014-12-07lib: Use email address instead of empty real name.Jesse Rosenthal
Currently, if a From-header is of the form: "" <address@example.com> the empty string will be treated as a valid real-name, and the entry in the search results will be empty. The new behavior here is that we treat an empty real-name field as if it were null, so that the email address will be used in the search results instead. Signed-off-by: Jesse Rosenthal <jrosenthal@jhu.edu>
2014-07-13lib: Start all function names in notmuch-private.h withCharles Celerier
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>
2014-01-18lib: fix clang compiler warningJani Nikula
With some combination of clang and talloc, not using the return value of talloc_steal() produces a warning. Ignore it, as talloc_steal() has no failure modes per documentation.
2013-06-24lib: add NOTMUCH_EXCLUDE_FLAG to notmuch_exclude_tMark Walters
Add NOTMUCH_EXCLUDE_FLAG to notmuch_exclude_t so that it can cover all four values of search --exclude in the cli. Previously the way to avoid any message being marked excluded was to pass in an empty list of excluded tags: since we now have an explicit option we might as well honour it. The enum is in a slightly strange order as the existing FALSE/TRUE options correspond to the new NOTMUCH_EXCLUDE_FLAG/NOTMUCH_EXCLUDE_TRUE options so this means we do not need to bump the version number. Indeed, an example of this is that the cli count and show still use FALSE/TRUE and still work.
2013-05-13lib: add --exclude=all optionMark Walters
Adds a exclude all option to the lib which means that excluded messages are completely ignored (as if they had actually been deleted).
2013-03-29lib: Fix name reordering to handle commas without spacesAdam Wolfe Gordon
Notmuch automatically re-orders names of the format "Last, First" to "First Last" when the associated email address is First.Last@example.com. But, if a name is of the format "Last,First" then notmuch will format the name as "irst Last". Handle any number of spaces after the comma, including none.
2013-02-18lib: Add an iterator over all messages in a threadAustin Clements
Previously, getting the list of all messages in a thread required recursively traversing the thread's message hierarchy, which was both difficult and resulted in messages being out of order. This adds a public function to retrieve an iterator over all of the messages in a thread in oldest-first order.
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.
2013-02-18lib: Clean up error handling in _notmuch_thread_createAustin Clements
Previously, there were various opportunities for memory leaks in the error-handling paths of this function. Use a local talloc context and some reparenting to make eliminate these leaks, while keeping the control flow simple.
2012-03-02lib: Add the exclude flag to notmuch_query_search_threadsMark Walters
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.
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-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-01-26notmuch search: Clean up some memory leaks during search loop.Carl Worth
With talloc, we were already freeing all memory by the time we exited the loop, but that didn't help with excess use of memory inside the loop, (which was mostly from tallocing some objects with the incorrect parent). Thanks to Andrew Tridgell for sitting next to me and teaching me to use talloc_report_full to find these leaks.
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-12-07notmuch search: Fix to display authors in date order.Carl Worth
Previously, the authors of the thread were displayed in reverse-chronological order, which was fairly confusing.
2010-12-07lib: Set thread subject at the same time as setting thread->{oldest,newest}Carl Worth
We really want to change the thread subject at the same time we set the date, (if the sort order indicates this is necessary). The previous code for setting the thread subject was sensitive on the query sort when adding matching messages. An independent bug fix is about to change that query sort order, so we remove the dependency on it here.
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-11-01lib: Add some missing static qualifiers.Carl Worth
These various functions and data are all used only locally, so should be marked static. Ensuring we get these right will avoid us accidentally leaking unintended symbols through the library interface.
2010-04-27Fix SEGV in _thread_cleanup_author if author ends with ', 'Dirk Hohndel
Admittedly, an author name ending in ',' guarantees this is spam, and indeed this was triggered by a spam email, but that doesn't mean we shouldn't handle this case correctly. We now check that there is actually a component of the name (presumably the first name) after the comma in the author name. Signed-off-by: Dirk Hohndel <hohndel@infradead.org>
2010-04-27lib: Re-implement moving of thread authors.Carl Worth
Just before releasing 0.3 we received reports of crashes that were bisected to the commit adding thread-author moving. Sure enough, valgrind pointed to buffer overruns in _thread_move_matched_author. Rather than trying to make sense of all the by strncpy, strchr, +1, and +2 of that code, I reimplemented thread-author ordering with a pair of hash tables and an array. Valgrind is at least happy now on the test cases it was complaining about previously.
2010-04-26Simple attempt to display author names in a friendlier wayDirk Hohndel
This patch only addresses the typical Outlook/Exchange case where we have "Last, First" <first.last@company.com> or "Last, First MI" <first.mi.last@company.com>. In the future we should be more fexible as to the formats we recognize, but for now we address this one as it is the Exchange default setting and therefore the most common one. Signed-off-by: Dirk Hohndel <hohndel@infradead.org>
2010-04-26Reorder displayed names of thread authorsDirk Hohndel
When displaying threads as result of a search it makes sense to list those authors first who match the search. The matching authors are separated from the non-matching ones with a '|' instead of a ',' Imagine the default "+inbox" query. Those mails in the thread that match the query are actually "new" (whatever that means). And some people seem to think that it would be much better to see those author names first. For example, imagine a long and drawn out thread that once was started by me; you have long read the older part of the thread and removed the inbox tag. Whenever a new email comes in on this thread, prior to this patch the author column in the search display will first show "Dirk Hohndel" - I think it should first show the actual author(s) of the new mail(s). Signed-off-by: Dirk Hohndel <hohndel@infradead.org>
2010-04-24lib: Audit calls to notmuch_message_get_header to handle NULL returnCarl Worth
Sebastian Spaeth reported [*] a segfault within libnotmuch when running notmuch operations while an asyncronous offlineimap job had removed some files from the mail store. Avoid this by handling all cases where notmuch_message_get_header could return NULL. [*] See message id:87d3xqti3o.fsf@SSpaeth.de on notmuch@notmuchmail.org
2010-04-24lib: Simplify code to set subject from matched message.Carl Worth
Simply moving the code from _add_matched_message to a new _set_subject_from_message function.