[PATCH] configure: add --without-api-docs option
[notmuch-archives.git] / c3 / 8e58d9424f9c5d39b514b49a6ab9327dc9f334
1 Return-Path: <dkg@fifthhorseman.net>\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 arlo.cworth.org (Postfix) with ESMTP id BF9286DE091F\r
6  for <notmuch@notmuchmail.org>; Fri,  8 Jul 2016 03:13:16 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12  autolearn=disabled\r
13 Received: from arlo.cworth.org ([127.0.0.1])\r
14  by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
15  with ESMTP id RsaQ-QlS0tUS for <notmuch@notmuchmail.org>;\r
16  Fri,  8 Jul 2016 03:13:08 -0700 (PDT)\r
17 Received: from che.mayfirst.org (che.mayfirst.org [162.247.75.118])\r
18  by arlo.cworth.org (Postfix) with ESMTP id 121A16DE01BA\r
19  for <notmuch@notmuchmail.org>; Fri,  8 Jul 2016 03:13:07 -0700 (PDT)\r
20 Received: from fifthhorseman.net (unknown [88.128.80.54])\r
21  by che.mayfirst.org (Postfix) with ESMTPSA id 8414CF99A\r
22  for <notmuch@notmuchmail.org>; Fri,  8 Jul 2016 06:13:06 -0400 (EDT)\r
23 Received: by fifthhorseman.net (Postfix, from userid 1000)\r
24  id C9C402174C; Fri,  8 Jul 2016 11:27:34 +0200 (CEST)\r
25 From: Daniel Kahn Gillmor <dkg@fifthhorseman.net>\r
26 To: Notmuch Mail <notmuch@notmuchmail.org>\r
27 Subject: [PATCH v4 15/16] added notmuch_message_reindex\r
28 Date: Fri,  8 Jul 2016 11:27:26 +0200\r
29 Message-Id: <1467970047-8013-16-git-send-email-dkg@fifthhorseman.net>\r
30 X-Mailer: git-send-email 2.8.1\r
31 In-Reply-To: <1467970047-8013-1-git-send-email-dkg@fifthhorseman.net>\r
32 References: <1467970047-8013-1-git-send-email-dkg@fifthhorseman.net>\r
33 X-BeenThere: notmuch@notmuchmail.org\r
34 X-Mailman-Version: 2.1.20\r
35 Precedence: list\r
36 List-Id: "Use and development of the notmuch mail system."\r
37  <notmuch.notmuchmail.org>\r
38 List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,\r
39  <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
40 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
41 List-Post: <mailto:notmuch@notmuchmail.org>\r
42 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
43 List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
44  <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
45 X-List-Received-Date: Fri, 08 Jul 2016 10:13:16 -0000\r
46 \r
47 This new function asks the database to reindex a given message, using\r
48 the supplied indexopts.\r
49 \r
50 This can be used, for example, to index the cleartext of an encrypted\r
51 message.\r
52 \r
53 My initial inclination for this implementation was to remove all the\r
54 indexed terms for a given message's body, and then to add them back\r
55 in.\r
56 \r
57 Unfortunately, that doesn't appear to be possible due to the way we're\r
58 using xapian.  I could find no way to distinguish terms which were\r
59 added during indexing of the message body from other terms associated\r
60 with the document.  As a result, we just save the tags and properties,\r
61 remove the message from the database entirely, and add it back into\r
62 the database in full, re-adding tags and properties as needed.\r
63 ---\r
64  lib/message.cc | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-\r
65  lib/notmuch.h  |  14 ++++++++\r
66  2 files changed, 121 insertions(+), 1 deletion(-)\r
67 \r
68 diff --git a/lib/message.cc b/lib/message.cc\r
69 index 9d3e807..ab807b7 100644\r
70 --- a/lib/message.cc\r
71 +++ b/lib/message.cc\r
72 @@ -557,7 +557,9 @@ void\r
73  _notmuch_message_remove_terms (notmuch_message_t *message, const char *prefix)\r
74  {\r
75      Xapian::TermIterator i;\r
76 -    size_t prefix_len = strlen (prefix);\r
77 +    size_t prefix_len = 0;\r
78 +\r
79 +    prefix_len = strlen (prefix);\r
80  \r
81      while (1) {\r
82         i = message->doc.termlist_begin ();\r
83 @@ -1847,3 +1849,107 @@ _notmuch_message_frozen (notmuch_message_t *message)\r
84  {\r
85      return message->frozen;\r
86  }\r
87 +\r
88 +notmuch_status_t\r
89 +notmuch_message_reindex (notmuch_message_t *message,\r
90 +                        notmuch_indexopts_t *indexopts)\r
91 +{\r
92 +    notmuch_database_t *notmuch = NULL;\r
93 +    notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS, status;\r
94 +    notmuch_tags_t *tags = NULL;\r
95 +    notmuch_message_properties_t *properties = NULL;\r
96 +    notmuch_filenames_t *filenames, *orig_filenames = NULL;\r
97 +    const char *filename = NULL, *tag = NULL, *propkey = NULL;\r
98 +    notmuch_message_t *newmsg = NULL;\r
99 +    notmuch_bool_t readded = FALSE, skip;\r
100 +    const char *autotags[] = {\r
101 +                   "attachment",\r
102 +                   "encrypted",\r
103 +                   "signed" };\r
104 +    const char *autoproperties[] = { "index-decryption" };\r
105 +\r
106 +    if (message == NULL)\r
107 +       return NOTMUCH_STATUS_NULL_POINTER;\r
108 +    \r
109 +    notmuch = _notmuch_message_database (message);\r
110 +\r
111 +    /* cache tags, properties, and filenames */\r
112 +    tags = notmuch_message_get_tags (message);\r
113 +    properties = notmuch_message_get_properties (message, "", FALSE);\r
114 +    filenames = notmuch_message_get_filenames (message);\r
115 +    orig_filenames = notmuch_message_get_filenames (message);\r
116 +    \r
117 +    /* walk through filenames, removing them until the message is gone */\r
118 +    for ( ; notmuch_filenames_valid (filenames);\r
119 +         notmuch_filenames_move_to_next (filenames)) {\r
120 +       filename = notmuch_filenames_get (filenames);\r
121 +\r
122 +       ret = notmuch_database_remove_message (notmuch, filename);\r
123 +       if (ret != NOTMUCH_STATUS_SUCCESS &&\r
124 +           ret != NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID)\r
125 +           return ret;\r
126 +    }\r
127 +    if (ret != NOTMUCH_STATUS_SUCCESS)\r
128 +       return ret;\r
129 +    \r
130 +    /* re-add the filenames with the associated indexopts */\r
131 +    for (; notmuch_filenames_valid (orig_filenames);\r
132 +        notmuch_filenames_move_to_next (orig_filenames)) {\r
133 +       filename = notmuch_filenames_get (orig_filenames);\r
134 +\r
135 +       status = notmuch_database_add_message_with_indexopts(notmuch,\r
136 +                                                            filename,\r
137 +                                                            indexopts,\r
138 +                                                            readded ? NULL : &newmsg);\r
139 +       if (status == NOTMUCH_STATUS_SUCCESS ||\r
140 +           status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID) {\r
141 +           if (!readded) {\r
142 +               /* re-add tags */\r
143 +               for (; notmuch_tags_valid (tags);\r
144 +                    notmuch_tags_move_to_next (tags)) {\r
145 +                   tag = notmuch_tags_get (tags);\r
146 +                   skip = FALSE;\r
147 +                   \r
148 +                   for (size_t i = 0; i < ARRAY_SIZE (autotags); i++)\r
149 +                       if (strcmp (tag, autotags[i]) == 0)\r
150 +                           skip = TRUE;\r
151 +                   \r
152 +                   if (!skip) {\r
153 +                       status = notmuch_message_add_tag (newmsg, tag);\r
154 +                       if (status != NOTMUCH_STATUS_SUCCESS)\r
155 +                           ret = status;\r
156 +                   }\r
157 +               }\r
158 +               /* re-add properties */\r
159 +               for (; notmuch_message_properties_valid (properties);\r
160 +                    notmuch_message_properties_move_to_next (properties)) {\r
161 +                   propkey = notmuch_message_properties_key (properties);\r
162 +                   skip = FALSE;\r
163 +\r
164 +                   for (size_t i = 0; i < ARRAY_SIZE (autoproperties); i++)\r
165 +                       if (strcmp (propkey, autoproperties[i]) == 0)\r
166 +                           skip = TRUE;\r
167 +\r
168 +                   if (!skip) {\r
169 +                       status = notmuch_message_add_property (newmsg, propkey,\r
170 +                                                              notmuch_message_properties_value (properties));\r
171 +                       if (status != NOTMUCH_STATUS_SUCCESS)\r
172 +                           ret = status;\r
173 +                   }\r
174 +               }\r
175 +               readded = TRUE;\r
176 +           }\r
177 +       } else {\r
178 +           /* if we failed to add this filename, go ahead and try the\r
179 +            * next one as though it were first, but report the\r
180 +            * error... */\r
181 +           ret = status;\r
182 +       }\r
183 +    }\r
184 +    if (newmsg)\r
185 +       notmuch_message_destroy (newmsg);\r
186 +                       \r
187 +    /* should we also destroy the incoming message object?  at the\r
188 +     * moment, we leave that to the caller */\r
189 +    return ret;\r
190 +}\r
191 diff --git a/lib/notmuch.h b/lib/notmuch.h\r
192 index 66b3503..9076a9b 100644\r
193 --- a/lib/notmuch.h\r
194 +++ b/lib/notmuch.h\r
195 @@ -1394,6 +1394,20 @@ notmuch_filenames_t *\r
196  notmuch_message_get_filenames (notmuch_message_t *message);\r
197  \r
198  /**\r
199 + * Re-index the e-mail corresponding to 'message' using the supplied index options\r
200 + *\r
201 + * Returns the status of the re-index operation.  (see the return\r
202 + * codes documented in notmuch_database_add_message)\r
203 + *\r
204 + * After reindexing, the user should discard the message object passed\r
205 + * in here by calling notmuch_message_destroy, since it refers to the\r
206 + * original message, not to the reindexed message.\r
207 + */\r
208 +notmuch_status_t\r
209 +notmuch_message_reindex (notmuch_message_t *message,\r
210 +                        notmuch_indexopts_t *indexopts);\r
211 +\r
212 +/**\r
213   * Message flags.\r
214   */\r
215  typedef enum _notmuch_message_flag {\r
216 -- \r
217 2.8.1\r
218 \r