X-Git-Url: https://git.notmuchmail.org/git?a=blobdiff_plain;f=lib%2Fthread.cc;h=e1da060e5158f5e1f0d8c4709645de1e6604efad;hb=b66ff567f6b65c7aafa1216294900303ad3aa4d4;hp=5bf83540d6cf72a9abda4879a06f369f5399b78f;hpb=21965718a57613f591464ca260c0f4340c574761;p=notmuch diff --git a/lib/thread.cc b/lib/thread.cc index 5bf83540..e1da060e 100644 --- a/lib/thread.cc +++ b/lib/thread.cc @@ -84,7 +84,7 @@ _thread_add_message (notmuch_thread_t *thread, { notmuch_tags_t *tags; const char *tag; - InternetAddressList *list; + InternetAddressList *list = NULL; InternetAddress *address; const char *from, *author; @@ -97,7 +97,9 @@ _thread_add_message (notmuch_thread_t *thread, message); from = notmuch_message_get_header (message, "from"); - list = internet_address_list_parse_string (from); + if (from) + list = internet_address_list_parse_string (from); + if (list) { address = internet_address_list_get_address (list, 0); if (address) { @@ -115,7 +117,7 @@ _thread_add_message (notmuch_thread_t *thread, if (! thread->subject) { const char *subject; subject = notmuch_message_get_header (message, "subject"); - thread->subject = talloc_strdup (thread, subject); + thread->subject = talloc_strdup (thread, subject ? subject : ""); } for (tags = notmuch_message_get_tags (message); @@ -128,25 +130,15 @@ _thread_add_message (notmuch_thread_t *thread, } static void -_thread_add_matched_message (notmuch_thread_t *thread, - notmuch_message_t *message, - notmuch_sort_t sort) +_thread_set_subject_from_message (notmuch_thread_t *thread, + notmuch_message_t *message) { - time_t date; - notmuch_message_t *hashed_message; - - date = notmuch_message_get_date (message); - - if (date < thread->oldest || ! thread->matched_messages) - thread->oldest = date; - - if (date > thread->newest || ! thread->matched_messages) - thread->newest = date; - const char *subject; const char *cleaned_subject; subject = notmuch_message_get_header (message, "subject"); + if (! subject) + return; if ((strncasecmp (subject, "Re: ", 4) == 0) || (strncasecmp (subject, "Aw: ", 4) == 0) || @@ -160,10 +152,27 @@ _thread_add_matched_message (notmuch_thread_t *thread, cleaned_subject = talloc_strdup (thread, subject); } - if ((sort == NOTMUCH_SORT_OLDEST_FIRST && date <= thread->newest) || - (sort != NOTMUCH_SORT_OLDEST_FIRST && date == thread->newest)) { - thread->subject = talloc_strdup (thread, cleaned_subject); - } + if (thread->subject) + talloc_free (thread->subject); + + thread->subject = talloc_strdup (thread, cleaned_subject); +} + +static void +_thread_add_matched_message (notmuch_thread_t *thread, + notmuch_message_t *message, + notmuch_sort_t sort) +{ + time_t date; + notmuch_message_t *hashed_message; + + date = notmuch_message_get_date (message); + + if (date < thread->oldest || ! thread->matched_messages) + thread->oldest = date; + + if (date > thread->newest || ! thread->matched_messages) + thread->newest = date; thread->matched_messages++; @@ -173,6 +182,12 @@ _thread_add_matched_message (notmuch_thread_t *thread, notmuch_message_set_flag (hashed_message, NOTMUCH_MESSAGE_FLAG_MATCH, 1); } + + if ((sort == NOTMUCH_SORT_OLDEST_FIRST && date <= thread->newest) || + (sort != NOTMUCH_SORT_OLDEST_FIRST && date == thread->newest)) + { + _thread_set_subject_from_message (thread, message); + } } static void