Re: [PATCH] cli: remove unused argument descriptions
[notmuch-archives.git] / 68 / 94d5a2abfc7fd3f8299a30b627eddc6f253289
1 Return-Path: <prvs=jrosenthal=716b2ef31@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 29DCA4196F0\r
6         for <notmuch@notmuchmail.org>; Sat, 17 Apr 2010 10:59:27 -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: -4.2\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-4.2 tagged_above=-999 required=5\r
12         tests=[BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3] autolearn=ham\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 VCTDsYSgEI31 for <notmuch@notmuchmail.org>;\r
16         Sat, 17 Apr 2010 10:59:25 -0700 (PDT)\r
17 Received: from ipex4.johnshopkins.edu (ipex4.johnshopkins.edu\r
18         [128.220.161.141])\r
19         by olra.theworths.org (Postfix) with ESMTP id 7AA61431FC1\r
20         for <notmuch@notmuchmail.org>; Sat, 17 Apr 2010 10:59:25 -0700 (PDT)\r
21 X-IronPort-AV: E=Sophos;i="4.52,227,1270440000"; d="scan'208";a="355778977"\r
22 Received: from c-69-255-36-229.hsd1.md.comcast.net (HELO lucky)\r
23         ([69.255.36.229])\r
24         by ipex4.johnshopkins.edu with ESMTP/TLS/AES256-SHA;\r
25         17 Apr 2010 13:59:24 -0400\r
26 Received: from jkr by lucky with local (Exim 4.69)\r
27         (envelope-from <jrosenthal@jhu.edu>)\r
28         id 1O3CIc-0006Hf-MV; Sat, 17 Apr 2010 13:59:22 -0400\r
29 From: Jesse Rosenthal <jrosenthal@jhu.edu>\r
30 To: notmuch@notmuchmail.org\r
31 Subject: [PATCH v2] Name thread based on matching msgs instead of first msg.\r
32 In-Reply-To: <87sk7rloo4.fsf@jhu.edu>\r
33 References: <87sk7rloo4.fsf@jhu.edu>\r
34 Date: Sat, 17 Apr 2010 13:59:22 -0400\r
35 Message-ID: <87eiieez9h.fsf@jhu.edu>\r
36 MIME-Version: 1.0\r
37 Content-Type: text/plain; charset=us-ascii\r
38 X-BeenThere: notmuch@notmuchmail.org\r
39 X-Mailman-Version: 2.1.13\r
40 Precedence: list\r
41 List-Id: "Use and development of the notmuch mail system."\r
42         <notmuch.notmuchmail.org>\r
43 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
44         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
45 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
46 List-Post: <mailto:notmuch@notmuchmail.org>\r
47 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
48 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
49         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
50 X-List-Received-Date: Sat, 17 Apr 2010 17:59:27 -0000\r
51 \r
52 At the moment all threads are named based on the name of the first message\r
53 in the thread. However, this can cause problems if people either start\r
54 new threads by replying-all (as unfortunately, many out there do) or\r
55 change the subject of their mails to reflect a shift in a thread on a\r
56 list.\r
57 \r
58 This patch names threads based on (a) matches for the query, and (b) the\r
59 search order. If the search order is oldest-first (as in the default\r
60 inbox) it chooses the oldest matching message as the subject. If the\r
61 search order is newest-first it chooses the newest one.\r
62 \r
63 Reply prefixes ("Re: ", "Aw: ", "Sv: ", "Vs: ") are ignored\r
64 (case-insensitively) so a Re: won't change the subject.\r
65 \r
66 Note that this adds a "sort" argument to _notmuch_thread_create and\r
67 _thread_add_matched_message, so that when constructing the thread we can\r
68 be aware of the sort order.\r
69 \r
70 Signed-off-by: Jesse Rosenthal <jrosenthal@jhu.edu>\r
71 ---\r
72 This patch is rebased against current master, and offered for inclusion\r
73 in 0.3.\r
74 \r
75 This patch is necessary for me to keep track of my mail, based on the\r
76 emailing habits of my correspondents. If others much prefer the original\r
77 behavior, I would still request that this feature be a configurable\r
78 option, even if not the default.\r
79 \r
80  lib/notmuch-private.h |    3 ++-\r
81  lib/query.cc          |    3 ++-\r
82  lib/thread.cc         |   32 ++++++++++++++++++++++++++++----\r
83  3 files changed, 32 insertions(+), 6 deletions(-)\r
84 \r
85 diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h\r
86 index d52d84d..94cce1b 100644\r
87 --- a/lib/notmuch-private.h\r
88 +++ b/lib/notmuch-private.h\r
89 @@ -205,7 +205,8 @@ notmuch_thread_t *\r
90  _notmuch_thread_create (void *ctx,\r
91                         notmuch_database_t *notmuch,\r
92                         const char *thread_id,\r
93 -                       const char *query_string);\r
94 +                       const char *query_string,\r
95 +                       notmuch_sort_t sort);\r
96  \r
97  /* message.cc */\r
98  \r
99 diff --git a/lib/query.cc b/lib/query.cc\r
100 index 10f8dc8..3e20f59 100644\r
101 --- a/lib/query.cc\r
102 +++ b/lib/query.cc\r
103 @@ -299,7 +299,8 @@ notmuch_threads_get (notmuch_threads_t *threads)\r
104      return _notmuch_thread_create (threads->query,\r
105                                    threads->query->notmuch,\r
106                                    threads->thread_id,\r
107 -                                  threads->query->query_string);\r
108 +                                  threads->query->query_string,\r
109 +                                  threads->query->sort);\r
110  }\r
111  \r
112  void\r
113 diff --git a/lib/thread.cc b/lib/thread.cc\r
114 index 3aa9d48..5bf8354 100644\r
115 --- a/lib/thread.cc\r
116 +++ b/lib/thread.cc\r
117 @@ -129,7 +129,8 @@ _thread_add_message (notmuch_thread_t *thread,\r
118  \r
119  static void\r
120  _thread_add_matched_message (notmuch_thread_t *thread,\r
121 -                            notmuch_message_t *message)\r
122 +                            notmuch_message_t *message,\r
123 +                            notmuch_sort_t sort)\r
124  {\r
125      time_t date;\r
126      notmuch_message_t *hashed_message;\r
127 @@ -142,6 +143,28 @@ _thread_add_matched_message (notmuch_thread_t *thread,\r
128      if (date > thread->newest || ! thread->matched_messages)\r
129         thread->newest = date;\r
130  \r
131 +    const char *subject;\r
132 +    const char *cleaned_subject;\r
133 +\r
134 +    subject = notmuch_message_get_header (message, "subject");\r
135 +\r
136 +    if ((strncasecmp (subject, "Re: ", 4) == 0) ||\r
137 +       (strncasecmp (subject, "Aw: ", 4) == 0) ||\r
138 +       (strncasecmp (subject, "Vs: ", 4) == 0) ||\r
139 +       (strncasecmp (subject, "Sv: ", 4) == 0)) {\r
140 +\r
141 +       cleaned_subject = talloc_strndup (thread,\r
142 +                                         subject + 4,\r
143 +                                         strlen(subject) - 4);\r
144 +    } else {\r
145 +       cleaned_subject = talloc_strdup (thread, subject);\r
146 +    }\r
147 +\r
148 +    if ((sort == NOTMUCH_SORT_OLDEST_FIRST && date <= thread->newest) ||\r
149 +       (sort != NOTMUCH_SORT_OLDEST_FIRST && date == thread->newest)) {\r
150 +       thread->subject = talloc_strdup (thread, cleaned_subject);\r
151 +    }\r
152 +\r
153      thread->matched_messages++;\r
154  \r
155      if (g_hash_table_lookup_extended (thread->message_hash,\r
156 @@ -209,7 +232,8 @@ notmuch_thread_t *\r
157  _notmuch_thread_create (void *ctx,\r
158                         notmuch_database_t *notmuch,\r
159                         const char *thread_id,\r
160 -                       const char *query_string)\r
161 +                       const char *query_string,\r
162 +                       notmuch_sort_t sort)\r
163  {\r
164      notmuch_thread_t *thread;\r
165      const char *thread_id_query_string;\r
166 @@ -296,7 +320,7 @@ _notmuch_thread_create (void *ctx,\r
167         _thread_add_message (thread, message);\r
168  \r
169         if (! matched_is_subset_of_thread)\r
170 -           _thread_add_matched_message (thread, message);\r
171 +           _thread_add_matched_message (thread, message, sort);\r
172  \r
173         _notmuch_message_close (message);\r
174      }\r
175 @@ -323,7 +347,7 @@ _notmuch_thread_create (void *ctx,\r
176              notmuch_messages_move_to_next (messages))\r
177         {\r
178             message = notmuch_messages_get (messages);\r
179 -           _thread_add_matched_message (thread, message);\r
180 +           _thread_add_matched_message (thread, message, sort);\r
181             _notmuch_message_close (message);\r
182         }\r
183  \r
184 -- \r
185 1.6.3.3\r
186 \r