[PATCH v2 03/11] lib: Document extent of some return values
[notmuch-archives.git] / 03 / 18a13c00c181abf972ea1723e637f45c8f4960
1 Return-Path: <sojkam1@fel.cvut.cz>\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 D17D44196F0\r
6         for <notmuch@notmuchmail.org>; Thu,  8 Apr 2010 23:07:31 -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: -0.5\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.5 tagged_above=-999 required=5\r
12         tests=[BAYES_05=-0.5] 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 FSO61bAfg+kS for <notmuch@notmuchmail.org>;\r
16         Thu,  8 Apr 2010 23:07:30 -0700 (PDT)\r
17 Received: from max.feld.cvut.cz (max.feld.cvut.cz [147.32.192.36])\r
18         by olra.theworths.org (Postfix) with ESMTP id 86D3E431FC1\r
19         for <notmuch@notmuchmail.org>; Thu,  8 Apr 2010 23:07:30 -0700 (PDT)\r
20 Received: from localhost (unknown [192.168.200.4])\r
21         by max.feld.cvut.cz (Postfix) with ESMTP id B6D7019F33A1;\r
22         Fri,  9 Apr 2010 08:07:29 +0200 (CEST)\r
23 X-Virus-Scanned: IMAP AMAVIS\r
24 Received: from max.feld.cvut.cz ([192.168.200.1])\r
25         by localhost (styx.feld.cvut.cz [192.168.200.4]) (amavisd-new,\r
26         port 10044)\r
27         with ESMTP id 8rWkfX9QYHWT; Fri,  9 Apr 2010 08:07:28 +0200 (CEST)\r
28 Received: from imap.feld.cvut.cz (imap.feld.cvut.cz [147.32.192.34])\r
29         by max.feld.cvut.cz (Postfix) with ESMTP id 6C7A819F3331;\r
30         Fri,  9 Apr 2010 08:07:28 +0200 (CEST)\r
31 Received: from steelpick.2x.cz (k335-30.felk.cvut.cz [147.32.86.30])\r
32         (Authenticated sender: sojkam1)\r
33         by imap.feld.cvut.cz (Postfix) with ESMTPSA id 66CB6FA003;\r
34         Fri,  9 Apr 2010 08:07:28 +0200 (CEST)\r
35 Received: from wsh by steelpick.2x.cz with local (Exim 4.71)\r
36         (envelope-from <sojkam1@fel.cvut.cz>)\r
37         id 1O07NH-0005ah-PQ; Fri, 09 Apr 2010 08:07:27 +0200\r
38 From: Michal Sojka <sojkam1@fel.cvut.cz>\r
39 To: Dirk Hohndel <hohndel@infradead.org>, notmuch <notmuch@notmuchmail.org>\r
40 Subject: Re: [RFC] reordering and cleanup of thread authors\r
41 In-Reply-To: <m31veru7vn.fsf@x200.gr8dns.org>\r
42 References: <m31veru7vn.fsf@x200.gr8dns.org>\r
43 Date: Fri, 09 Apr 2010 08:07:27 +0200\r
44 Message-ID: <87zl1d5fc0.fsf@steelpick.2x.cz>\r
45 MIME-Version: 1.0\r
46 Content-Type: text/plain; charset=us-ascii\r
47 X-BeenThere: notmuch@notmuchmail.org\r
48 X-Mailman-Version: 2.1.13\r
49 Precedence: list\r
50 List-Id: "Use and development of the notmuch mail system."\r
51         <notmuch.notmuchmail.org>\r
52 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
53         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
54 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
55 List-Post: <mailto:notmuch@notmuchmail.org>\r
56 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
57 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
58         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
59 X-List-Received-Date: Fri, 09 Apr 2010 06:07:32 -0000\r
60 \r
61 On Wed, 07 Apr 2010, Dirk Hohndel wrote:\r
62\r
63 > This is based in part on some discussion on IRC today.\r
64 > When a thread is displayed in the search results, previously the authors\r
65 > were always displayed in chronological order. But if only part of the\r
66 > thread matches the query, that may or may not be the intuitive thing to\r
67 > do.\r
68 \r
69 Hi Dirk,\r
70 \r
71 thanks for the patch. It is a very interesting feature. See my comments\r
72 below.\r
73 \r
74 >\r
75 > [...]\r
76 >\r
77 > +/*\r
78 > + * move authors of matched messages in the thread to \r
79 > + * the front of the authors list, but keep them in\r
80 > + * oldest first order within their group\r
81 > + */\r
82 > +static void\r
83 > +_thread_move_matched_author (notmuch_thread_t *thread,\r
84 > +                          const char *author)\r
85 > +{\r
86 > +    char *authorscopy;\r
87 > +    char *currentauthor;\r
88 > +    int idx,nmstart,author_len,authors_len;\r
89 > +\r
90 > +    if (thread->authors == NULL)\r
91 > +     return;\r
92 > +    if (thread->nonmatched_authors == NULL)\r
93 > +     thread->nonmatched_authors = thread->authors;\r
94 > +    author_len = strlen(author);\r
95 > +    authors_len = strlen(thread->authors);\r
96 > +    if (author_len == authors_len) {\r
97 > +     /* just one author */\r
98 > +     thread->nonmatched_authors += author_len;\r
99 > +     return;\r
100 > +    }\r
101 > +    currentauthor = strcasestr(thread->authors, author);\r
102 > +    if (currentauthor == NULL)\r
103 > +     return;\r
104 > +    idx = currentauthor - thread->nonmatched_authors;\r
105 > +    if (idx < 0) {\r
106 > +     /* already among matched authors */\r
107 > +     return;\r
108 > +    }\r
109 > +    if (thread->nonmatched_authors + author_len < thread->authors + authors_len) {\r
110 \r
111 What does the above condition exactly mean? I was not able to decode it\r
112 and it seems to be wrong. I expect that the "|" is used to delimit\r
113 matched and non-matched authors. If I run notmuch search\r
114 thread:XXXXXXXXXXXXXXXX, which matches all messages in the thread, I see\r
115 all authors delimited by "|", which I consider wrong.\r
116 \r
117 -Michal\r
118 \r
119 > +     /* we have to make changes, so let's get a temp copy */\r
120 > +     authorscopy = strdup(thread->authors);\r
121 > +     if (authorscopy == NULL)\r
122 > +         return;\r
123 > +     /* nmstart is the offset into where the non-matched authors start */\r
124 > +     nmstart = thread->nonmatched_authors - thread->authors;\r
125 > +     /* copy this author and add the "| " - the if clause above tells us there's more */\r
126 > +     strncpy(thread->nonmatched_authors,author,author_len);\r
127 > +     strncpy(thread->nonmatched_authors+author_len,"| ",2);\r
128 > +     thread->nonmatched_authors += author_len+2;     \r
129 > +     if (idx > 0) {\r
130 > +       /* we are actually moving authors around, not just changing the separator\r
131 > +        * first copy the authors that came BEFORE our author */\r
132 > +       strncpy(thread->nonmatched_authors, authorscopy+nmstart, idx-2);\r
133 > +       /* finally, if there are authors AFTER our author, copy those */\r
134 > +       if(author_len+nmstart+idx < authors_len) {\r
135 > +         strncpy(thread->nonmatched_authors + idx - 2,", ",2);\r
136 > +         strncpy(thread->nonmatched_authors + idx, authorscopy+nmstart + idx + author_len + 2, \r
137 > +                 authors_len - (nmstart + idx + author_len + 2));\r
138 > +       }\r
139 > +     }\r
140 > +     free(authorscopy);\r
141 > +    } else {\r
142 > +     thread->nonmatched_authors += author_len;\r
143 > +    }\r
144 > +    return;\r
145 > +}\r