Re: [PATCH 9/9] add has: query prefix to search for specific properties
[notmuch-archives.git] / a6 / d8113c89ffe795dcb8987e34fdecac41822c19
1 Return-Path: <prvs=372b3579b=jrosenthal@jhu.edu>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 1A9DA431FC2\r
6         for <notmuch@notmuchmail.org>; Wed, 29 Oct 2014 13:52:20 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -2.3\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id oO6o5cdHs9XU for <notmuch@notmuchmail.org>;\r
16         Wed, 29 Oct 2014 13:52:12 -0700 (PDT)\r
17 Received: from smtpauth.johnshopkins.edu (smtpauth.johnshopkins.edu\r
18         [162.129.8.200]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
19         (No client certificate requested)\r
20         by olra.theworths.org (Postfix) with ESMTPS id 5242D431FB6\r
21         for <notmuch@notmuchmail.org>; Wed, 29 Oct 2014 13:52:12 -0700 (PDT)\r
22 X-IronPort-AV: E=Sophos;i="5.07,279,1413259200"; d="scan'208";a="437698602"\r
23 Received: from guppy.hwcampus.jhu.edu (HELO localhost) ([10.161.32.234])\r
24         by ipex1.johnshopkins.edu with ESMTP/TLS/AES128-SHA;\r
25         29 Oct 2014 16:52:10 -0400\r
26 From: Jesse Rosenthal <jrosenthal@jhu.edu>\r
27 To: notmuch@notmuchmail.org\r
28 Subject: [v2 1/3] thread.cc: Avoid empty thread names if possible.\r
29 Date: Wed, 29 Oct 2014 16:51:43 -0400\r
30 Message-Id: <1414615905-22554-2-git-send-email-jrosenthal@jhu.edu>\r
31 X-Mailer: git-send-email 2.1.2\r
32 In-Reply-To: <1414615905-22554-1-git-send-email-jrosenthal@jhu.edu>\r
33 References: <1414615905-22554-1-git-send-email-jrosenthal@jhu.edu>\r
34 X-BeenThere: notmuch@notmuchmail.org\r
35 X-Mailman-Version: 2.1.13\r
36 Precedence: list\r
37 List-Id: "Use and development of the notmuch mail system."\r
38         <notmuch.notmuchmail.org>\r
39 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
40         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
41 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
42 List-Post: <mailto:notmuch@notmuchmail.org>\r
43 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
44 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
45         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
46 X-List-Received-Date: Wed, 29 Oct 2014 20:52:20 -0000\r
47 \r
48 Currently the thread is named based on either the oldest or newest\r
49 matching message (depending on the search order). If this message has\r
50 an empty subject, though, the thread will show up with an empty\r
51 subject in the search results. (See the thread starting with\r
52 `id:1412371140-21051-1-git-send-email-david@tethera.net` for an\r
53 example.)\r
54 \r
55 This changes the behavior so it will use a non-empty name for the\r
56 thread if possible. We name threads based on (a) non-empty matches for\r
57 the query, and (b) the search order. If the search order is\r
58 oldest-first (as in the default inbox) it chooses the oldest matching\r
59 non-empty message as the subject. If the search order is newest-first\r
60 it chooses the newest one.\r
61 ---\r
62  lib/thread.cc | 16 +++++++++++-----\r
63  1 file changed, 11 insertions(+), 5 deletions(-)\r
64 \r
65 diff --git a/lib/thread.cc b/lib/thread.cc\r
66 index 8922403..267f351 100644\r
67 --- a/lib/thread.cc\r
68 +++ b/lib/thread.cc\r
69 @@ -24,6 +24,8 @@\r
70  #include <gmime/gmime.h>\r
71  #include <glib.h> /* GHashTable */\r
72  \r
73 +#define EMPTY_STRING(s) ((s)[0] == '\0') \r
74 +\r
75  struct visible _notmuch_thread {\r
76      notmuch_database_t *notmuch;\r
77      char *thread_id;\r
78 @@ -330,11 +332,13 @@ _thread_set_subject_from_message (notmuch_thread_t *thread,\r
79      } else {\r
80         cleaned_subject = talloc_strdup (thread, subject);\r
81      }\r
82 +    \r
83 +    if (! EMPTY_STRING(cleaned_subject)) {\r
84 +       if (thread->subject)\r
85 +           talloc_free (thread->subject);\r
86  \r
87 -    if (thread->subject)\r
88 -       talloc_free (thread->subject);\r
89 -\r
90 -    thread->subject = talloc_strdup (thread, cleaned_subject);\r
91 +       thread->subject = talloc_strdup (thread, cleaned_subject);\r
92 +    }\r
93  }\r
94  \r
95  /* Add a message to this thread which is known to match the original\r
96 @@ -348,8 +352,10 @@ _thread_add_matched_message (notmuch_thread_t *thread,\r
97  {\r
98      time_t date;\r
99      notmuch_message_t *hashed_message;\r
100 +    const char *cur_subject;\r
101  \r
102      date = notmuch_message_get_date (message);\r
103 +    cur_subject = notmuch_thread_get_subject(thread);\r
104  \r
105      if (date < thread->oldest || ! thread->matched_messages) {\r
106         thread->oldest = date;\r
107 @@ -359,7 +365,7 @@ _thread_add_matched_message (notmuch_thread_t *thread,\r
108  \r
109      if (date > thread->newest || ! thread->matched_messages) {\r
110         thread->newest = date;\r
111 -       if (sort != NOTMUCH_SORT_OLDEST_FIRST)\r
112 +       if (sort != NOTMUCH_SORT_OLDEST_FIRST || EMPTY_STRING(cur_subject))\r
113             _thread_set_subject_from_message (thread, message);\r
114      }\r
115  \r
116 -- \r
117 2.1.2\r
118 \r