Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / b9 / 3e9de6a1f5e763f69419c61be76764891ec129
1 Return-Path: <prvs=jrosenthal=691fa5400@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 798734196F0\r
6         for <notmuch@notmuchmail.org>; Mon, 22 Mar 2010 20:09:09 -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.8\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-2.8 tagged_above=-999 required=5\r
12         tests=[BAYES_05=-0.5, 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 vLuV6V4vbm4r for <notmuch@notmuchmail.org>;\r
16         Mon, 22 Mar 2010 20:09:08 -0700 (PDT)\r
17 Received: from ipex3.johnshopkins.edu (ipex3.johnshopkins.edu\r
18         [128.220.161.140])\r
19         by olra.theworths.org (Postfix) with ESMTP id 88734431FC1\r
20         for <notmuch@notmuchmail.org>; Mon, 22 Mar 2010 20:09:08 -0700 (PDT)\r
21 X-IronPort-AV: E=Sophos;i="4.51,292,1267419600"; d="scan'208";a="365426720"\r
22 Received: from c-69-255-36-229.hsd1.md.comcast.net (HELO lucky)\r
23         ([69.255.36.229])\r
24         by ipex3.johnshopkins.edu with ESMTP/TLS/AES256-SHA;\r
25         22 Mar 2010 23:09:07 -0400\r
26 Received: from jkr by lucky with local (Exim 4.69)\r
27         (envelope-from <jrosenthal@jhu.edu>)\r
28         id 1NtuUV-0000Kh-5Y; Mon, 22 Mar 2010 23:09:15 -0400\r
29 From: Jesse Rosenthal <jrosenthal@jhu.edu>\r
30 To: notmuch@notmuchmail.org\r
31 Date: Mon, 22 Mar 2010 23:09:15 -0400\r
32 Message-ID: <87sk7rloo4.fsf@jhu.edu>\r
33 MIME-Version: 1.0\r
34 Content-Type: text/plain; charset=us-ascii\r
35 Subject: [notmuch] [PATCH] Name thread based on matching msgs instead of\r
36         first msg.\r
37 X-BeenThere: notmuch@notmuchmail.org\r
38 X-Mailman-Version: 2.1.13\r
39 Precedence: list\r
40 List-Id: "Use and development of the notmuch mail system."\r
41         <notmuch.notmuchmail.org>\r
42 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
43         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
44 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
45 List-Post: <mailto:notmuch@notmuchmail.org>\r
46 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
47 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
48         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
49 X-List-Received-Date: Tue, 23 Mar 2010 03:09:09 -0000\r
50 \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 matches for the query, and the search\r
59 order. If the search order is oldest-first (as in the default inbox) it\r
60 chooses the oldest matching message as the subject. If the search order is\r
61 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  lib/notmuch-private.h |    3 ++-\r
71  lib/query.cc          |    3 ++-\r
72  lib/thread.cc         |   30 +++++++++++++++++++++++++++---\r
73  3 files changed, 31 insertions(+), 5 deletions(-)\r
74 \r
75 diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h\r
76 index d52d84d..94cce1b 100644\r
77 --- a/lib/notmuch-private.h\r
78 +++ b/lib/notmuch-private.h\r
79 @@ -205,7 +205,8 @@ notmuch_thread_t *\r
80  _notmuch_thread_create (void *ctx,\r
81                         notmuch_database_t *notmuch,\r
82                         const char *thread_id,\r
83 -                       const char *query_string);\r
84 +                       const char *query_string,\r
85 +                       notmuch_sort_t sort);\r
86  \r
87  /* message.cc */\r
88  \r
89 diff --git a/lib/query.cc b/lib/query.cc\r
90 index 9266d35..946f367 100644\r
91 --- a/lib/query.cc\r
92 +++ b/lib/query.cc\r
93 @@ -297,7 +297,8 @@ notmuch_threads_get (notmuch_threads_t *threads)\r
94      return _notmuch_thread_create (threads->query,\r
95                                    threads->query->notmuch,\r
96                                    threads->thread_id,\r
97 -                                  threads->query->query_string);\r
98 +                                  threads->query->query_string,\r
99 +                                  threads->query->sort);\r
100  }\r
101  \r
102  void\r
103 diff --git a/lib/thread.cc b/lib/thread.cc\r
104 index ec80f85..9ba7b70 100644\r
105 --- a/lib/thread.cc\r
106 +++ b/lib/thread.cc\r
107 @@ -129,7 +129,8 @@ _thread_add_message (notmuch_thread_t *thread,\r
108  \r
109  static void\r
110  _thread_add_matched_message (notmuch_thread_t *thread,\r
111 -                            notmuch_message_t *message)\r
112 +                            notmuch_message_t *message,\r
113 +                            notmuch_sort_t sort)\r
114  {\r
115      time_t date;\r
116      notmuch_message_t *hashed_message;\r
117 @@ -142,6 +143,28 @@ _thread_add_matched_message (notmuch_thread_t *thread,\r
118      if (date > thread->newest || ! thread->matched_messages)\r
119         thread->newest = date;\r
120  \r
121 +    const char *subject;\r
122 +    const char *cleaned_subject;\r
123 +\r
124 +    subject = notmuch_message_get_header (message, "subject");\r
125 +\r
126 +    if ((strncasecmp (subject, "Re: ", 4) == 0) ||\r
127 +       (strncasecmp (subject, "Aw: ", 4) == 0) ||\r
128 +       (strncasecmp (subject, "Vs: ", 4) == 0) ||\r
129 +       (strncasecmp (subject, "Sv: ", 4) == 0)) {\r
130 +\r
131 +       cleaned_subject = talloc_strndup (thread,\r
132 +                                         subject + 4,\r
133 +                                         strlen(subject) - 4);\r
134 +    } else {\r
135 +       cleaned_subject = talloc_strdup (thread, subject);\r
136 +    }\r
137 +\r
138 +    if ((sort == NOTMUCH_SORT_OLDEST_FIRST && date <= thread->newest) ||\r
139 +       (sort != NOTMUCH_SORT_OLDEST_FIRST && date == thread->newest)) {\r
140 +       thread->subject = talloc_strdup (thread, cleaned_subject);\r
141 +    }\r
142 +\r
143      thread->matched_messages++;\r
144  \r
145      if (g_hash_table_lookup_extended (thread->message_hash,\r
146 @@ -209,7 +232,8 @@ notmuch_thread_t *\r
147  _notmuch_thread_create (void *ctx,\r
148                         notmuch_database_t *notmuch,\r
149                         const char *thread_id,\r
150 -                       const char *query_string)\r
151 +                       const char *query_string,\r
152 +                       notmuch_sort_t sort)\r
153  {\r
154      notmuch_thread_t *thread;\r
155      const char *thread_id_query_string, *matched_query_string;\r
156 @@ -284,7 +308,7 @@ _notmuch_thread_create (void *ctx,\r
157          notmuch_messages_move_to_next (messages))\r
158      {\r
159         message = notmuch_messages_get (messages);\r
160 -       _thread_add_matched_message (thread, message);\r
161 +       _thread_add_matched_message (thread, message, sort);\r
162         _notmuch_message_close (message);\r
163      }\r
164  \r
165 -- \r
166 1.6.3.3\r
167 \r