summaryrefslogtreecommitdiff
path: root/lib/thread.cc
AgeCommit message (Collapse)Author
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.
2010-04-22Revert "thread: Simplify code for assigning the subject."Carl Worth
This reverts commit 36e4459a328b8449b3e9d510be81a332a9b35aaa. With the two previous reverts, this fixes the recent message-sorting regression, so the test suite now passes again.
2010-04-22Revert "thread: Fix sort of search when constructing threads."Carl Worth
This reverts commit f43990ce134d838cdb2cdd5d0752a602e81cfdd9.
2010-04-22Revert "thread: Removed unsed sort argument from _thread_add_matched_message"Carl Worth
This reverts commit 7fb56f9dc5d8e66f717f5e48ecbfbc11c8190182.
2010-04-21thread: Removed unsed sort argument from _thread_add_matched_messageCarl Worth
The reworked solution for naming a thread based on the subject of oldest/newest matching message no longer needs this argument.
2010-04-21thread: Fix sort of search when constructing threads.Carl Worth
The thread-naming feature depends on the matched messages being passed down in a precise order, (the order of the top-level search). We fix the feature by passing that sort order down.
2010-04-21thread: Simplify code for assigning the subject.Carl Worth
We know that matched messages are always added in order, so we can always just grab the subject from the first message. This is the same approach that was used previously in _thread_add_message. That is, the recent feature of renaming a thread based on the subject of the "first" matched message is as simple as moving the subject assignment from _thread_add_message to _thread_add_matched_message.
2010-04-21Name thread based on matching msgs instead of first msg.Jesse Rosenthal
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>
2010-04-15lib: search_threads: Fix nested search to handle original search of "*"Carl Worth
When constructing a thread, we usually run a nested query to find all messages in the thread that match the original search string. However, we need to have special-case handling of an original search string of "*" now that that is a supported means of specifying all messages. The special-case ends up bein quite simple---we do less work, (just skipping the nested search since we know that all messages must match). I had been wanting to write this identical code to more efficiently handle "notmuch search thread:<foo>" which was previously running two identical searches. So that case is now more efficient as well.
2010-04-06fix obvious cut and paste errorDirk Hohndel
the wrong variable is checked for success of an allocation Signed-off-by: Dirk Hohndel <hohndel@infradead.org>
2010-03-31emacs: Fix the notmuch-search-authors-width variable.Carl Worth
This variable existed previously, but wasn't actually used for anything.
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'.
2009-11-27correct message flag enum value so that it matches the typeBart Trojanowski
As per Carl's request, this patch corrects the only value defined under the notmuch_message_flag_t enum typedef to match the name of the type. Signed-off-by: Bart Trojanowski <bart@jukie.net>
2009-11-27have _notmuch_thread_create mark which messages matched the queryBart Trojanowski
When _notmuch_thread_create() is given a query string, it can return more messages than just those matching the query. To distinguish those that matched the query expression, the MATCHING_SEARCH flag is set appropriately. Signed-off-by: Bart Trojanowski <bart@jukie.net>
2009-11-23lib/query: Drop the first and max_messages arguments from search_messages.Carl Worth
These only existed to support the chunky-searching hack, but that was recently dropped anyway.
2009-11-18TypsosIngmar Vanhassel
2009-11-17notmuch search: Change default search order to be newest messages first.Carl Worth
This is what most people want for a _search_ command. It's often different for actually reading mail in an inbox, (where it makes more sense to have results displayed in chronological order), but in such a case, ther user is likely using an interface that can simply pass the --sort=oldest-first option to "notmuch search". Here we're also change the sort enum from NOTMUCH_SORT_DATE and NOTMUCH_SORT_DATE_REVERSE to NOTMUCH_SORT_OLDEST_FIRST and NOTMUCH_SORT_NEWEST_FIRST. Similarly we replace the --reverse option to "notmuch search" with two options: --sort=oldest-first and --sort=newest-first. Finally, these changes are all tracked in the emacs interface, (which has no change in its behavior).
2009-11-17Fix "too many open files" bug by closing message files when done with them.Keith Packard
The message file header parsing code parses only enough of the file to find the desired header fields, then it leaves the file open until the next header parsing call or when the message is no longer in use. If a large number of messages end up being active, this will quickly run out of file descriptors. Here, we add support to explicitly close the message file within a message, (_notmuch_message_close) and call that from thread construction code. Signed-off-by: Keith Packard <keithp@keithp.com> Edited-by: Carl Worth <cworth@cworth.org>: Many portions of Keith's original patch have since been solved other ways, (such as the code that changed the handling of the In-Reply-To header). So the final version is clean enough that I think even Keith would be happy to have his name on it.
2009-11-17get_in_reply_to: Implement via the database, not by opening mail file.Carl Worth
This reduces our reliance on open message_file objects, (so is a step toward fixing the "too many open files" bug), but more importantly, it means we don't load a self-referencing in-reply-to header, (since we weed those out before adding any replyto terms to the database).
2009-11-15notmuch show: Implement proper thread ordering/nesting of messages.Carl Worth
We now properly analyze the in-reply-to headers to create a proper tree representing the actual thread and present the messages in this correct thread order. Also, there's a new "depth:" value added to the "message{" header so that clients can format the thread as desired, (such as by indenting replies).
2009-11-15_thread_add_messages: Remove unused variable.Carl Worth
I'm not sure how I let this warning go by unfixed for a while. Fix it now.