Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 25 / 90baa3a0fc6cd7068fb8ceff20b28273072c68
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 1533A6DE1BCA\r
6  for <notmuch@notmuchmail.org>; Tue, 19 Jan 2016 18:53:35 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.022\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.022 tagged_above=-999 required=5\r
12  tests=[AWL=-0.022] 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 IGSIn38-4Bl8 for <notmuch@notmuchmail.org>;\r
16  Tue, 19 Jan 2016 18:53:33 -0800 (PST)\r
17 Received: from che.mayfirst.org (che.mayfirst.org [209.234.253.108])\r
18  by arlo.cworth.org (Postfix) with ESMTP id 6127E6DE1A34\r
19  for <notmuch@notmuchmail.org>; Tue, 19 Jan 2016 18:53:17 -0800 (PST)\r
20 Received: from fifthhorseman.net (unknown [38.109.115.130])\r
21  by che.mayfirst.org (Postfix) with ESMTPSA id 60763F99F\r
22  for <notmuch@notmuchmail.org>; Tue, 19 Jan 2016 21:53:14 -0500 (EST)\r
23 Received: by fifthhorseman.net (Postfix, from userid 1000)\r
24  id 121F6208CC; Tue, 19 Jan 2016 18:53:11 -0800 (PST)\r
25 From: Daniel Kahn Gillmor <dkg@fifthhorseman.net>\r
26 To: Notmuch Mail <notmuch@notmuchmail.org>\r
27 Subject: [PATCH v2 15/16] added notmuch_message_reindex\r
28 Date: Tue, 19 Jan 2016 21:52:48 -0500\r
29 Message-Id: <1453258369-7366-16-git-send-email-dkg@fifthhorseman.net>\r
30 X-Mailer: git-send-email 2.7.0.rc3\r
31 In-Reply-To: <1453258369-7366-1-git-send-email-dkg@fifthhorseman.net>\r
32 References: <1453258369-7366-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: Wed, 20 Jan 2016 02:53:35 -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  lib/message.cc | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-\r
54  lib/notmuch.h  | 14 +++++++++\r
55  2 files changed, 104 insertions(+), 1 deletion(-)\r
56 \r
57 diff --git a/lib/message.cc b/lib/message.cc\r
58 index 8d72ea2..3b35418 100644\r
59 --- a/lib/message.cc\r
60 +++ b/lib/message.cc\r
61 @@ -529,7 +529,9 @@ static void\r
62  _notmuch_message_remove_terms (notmuch_message_t *message, const char *prefix)\r
63  {\r
64      Xapian::TermIterator i;\r
65 -    size_t prefix_len = strlen (prefix);\r
66 +    size_t prefix_len = 0;\r
67 +\r
68 +    prefix_len = strlen (prefix);\r
69  \r
70      while (1) {\r
71         i = message->doc.termlist_begin ();\r
72 @@ -1667,3 +1669,90 @@ _notmuch_message_database (notmuch_message_t *message)\r
73  {\r
74      return message->notmuch;\r
75  }\r
76 +\r
77 +notmuch_status_t\r
78 +notmuch_message_reindex (notmuch_message_t *message,\r
79 +                        notmuch_indexopts_t *indexopts)\r
80 +{\r
81 +    notmuch_database_t *notmuch = NULL;\r
82 +    notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS, status;\r
83 +    notmuch_tags_t *tags = NULL;\r
84 +    notmuch_filenames_t *filenames, *orig_filenames = NULL;\r
85 +    const char *filename = NULL, *tag = NULL;\r
86 +    notmuch_message_t *newmsg = NULL;\r
87 +    notmuch_bool_t readded = FALSE, skip;\r
88 +    const char *autotags[] = {\r
89 +                   "attachment",\r
90 +                   "encrypted",\r
91 +                   "signed",\r
92 +                   "index-decrypted",\r
93 +                   "index-decryption-failed" };\r
94 +\r
95 +    if (message == NULL)\r
96 +       return NOTMUCH_STATUS_NULL_POINTER;\r
97 +    \r
98 +    notmuch = _notmuch_message_database (message);\r
99 +\r
100 +    /* cache tags and filenames */\r
101 +    tags = notmuch_message_get_tags(message);\r
102 +    filenames = notmuch_message_get_filenames(message);\r
103 +    orig_filenames = notmuch_message_get_filenames(message);\r
104 +    \r
105 +    /* walk through filenames, removing them until the message is gone */\r
106 +    for ( ; notmuch_filenames_valid (filenames);\r
107 +         notmuch_filenames_move_to_next (filenames)) {\r
108 +       filename = notmuch_filenames_get (filenames);\r
109 +\r
110 +       ret = notmuch_database_remove_message (notmuch, filename);\r
111 +       if (ret != NOTMUCH_STATUS_SUCCESS &&\r
112 +           ret != NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID)\r
113 +           return ret;\r
114 +    }\r
115 +    if (ret != NOTMUCH_STATUS_SUCCESS)\r
116 +       return ret;\r
117 +    \r
118 +    /* re-add the filenames with the associated indexopts */\r
119 +    for (; notmuch_filenames_valid (orig_filenames);\r
120 +        notmuch_filenames_move_to_next (orig_filenames)) {\r
121 +       filename = notmuch_filenames_get (orig_filenames);\r
122 +\r
123 +       status = notmuch_database_add_message_with_indexopts(notmuch,\r
124 +                                                            filename,\r
125 +                                                            indexopts,\r
126 +                                                            readded ? NULL : &newmsg);\r
127 +       if (status == NOTMUCH_STATUS_SUCCESS ||\r
128 +           status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID) {\r
129 +           if (!readded) {\r
130 +               /* re-add tags */\r
131 +               for (; notmuch_tags_valid (tags);\r
132 +                    notmuch_tags_move_to_next (tags)) {\r
133 +                   tag = notmuch_tags_get (tags);\r
134 +                   skip = FALSE;\r
135 +                   \r
136 +                   for (size_t i = 0; i < ARRAY_SIZE(autotags); i++)\r
137 +                       if (strcmp (tag, autotags[i]) == 0)\r
138 +                           skip = TRUE;\r
139 +                   \r
140 +                   if (!skip) {\r
141 +                       status = notmuch_message_add_tag (newmsg, tag);\r
142 +                       if (status != NOTMUCH_STATUS_SUCCESS)\r
143 +                           ret = status;\r
144 +                   }\r
145 +               }\r
146 +               readded = TRUE;\r
147 +           }\r
148 +       } else {\r
149 +           /* if we failed to add this filename, go ahead and try the\r
150 +            * next one as though it were first, but report the\r
151 +            * error... */\r
152 +           ret = status;\r
153 +       }\r
154 +    }\r
155 +    if (newmsg)\r
156 +       notmuch_message_destroy (newmsg);\r
157 +                       \r
158 +    /* should we also destroy the incoming message object?  at the\r
159 +     * moment, we leave that to the caller */\r
160 +    return ret;\r
161 +}\r
162 +\r
163 diff --git a/lib/notmuch.h b/lib/notmuch.h\r
164 index 854a451..e6287cd 100644\r
165 --- a/lib/notmuch.h\r
166 +++ b/lib/notmuch.h\r
167 @@ -1377,6 +1377,20 @@ notmuch_filenames_t *\r
168  notmuch_message_get_filenames (notmuch_message_t *message);\r
169  \r
170  /**\r
171 + * Re-index the e-mail corresponding to 'message' using the supplied index options\r
172 + *\r
173 + * Returns the status of the re-index operation.  (see the return\r
174 + * codes documented in notmuch_database_add_message)\r
175 + *\r
176 + * After reindexing, the user should discard the message object passed\r
177 + * in here by calling notmuch_message_destroy, since it refers to the\r
178 + * original message, not to the reindexed message.\r
179 + */\r
180 +notmuch_status_t\r
181 +notmuch_message_reindex (notmuch_message_t *message,\r
182 +                        notmuch_indexopts_t *indexopts);\r
183 +\r
184 +/**\r
185   * Message flags.\r
186   */\r
187  typedef enum _notmuch_message_flag {\r
188 -- \r
189 2.7.0.rc3\r
190 \r