From: David Bremner <david@tethera.net>
To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org
Subject: [rfc patch v3 2/6] lib: add _notmuch_message_remove_indexed_terms
Date: Mon, 3 Apr 2017 22:47:34 -0300 [thread overview]
Message-ID: <20170404014738.25963-3-david@tethera.net> (raw)
In-Reply-To: <20170404014738.25963-1-david@tethera.net>
Testing will be provided via use in notmuch_message_reindex
---
lib/message.cc | 44 ++++++++++++++++++++++++++++++++++++++++++++
lib/notmuch-private.h | 2 ++
lib/notmuch.h | 4 ++++
3 files changed, 50 insertions(+)
diff --git a/lib/message.cc b/lib/message.cc
index f8215a49..a7bd38ac 100644
--- a/lib/message.cc
+++ b/lib/message.cc
@@ -599,6 +599,50 @@ _notmuch_message_remove_terms (notmuch_message_t *message, const char *prefix)
}
}
+
+/* Remove all terms generated by indexing, i.e. not tags or
+ * properties, along with any automatic tags*/
+notmuch_private_status_t
+_notmuch_message_remove_indexed_terms (notmuch_message_t *message)
+{
+ Xapian::TermIterator i;
+
+ const std::string tag_prefix = _find_prefix ("tag");
+ const std::string property_prefix = _find_prefix ("property");
+
+ for (i = message->doc.termlist_begin ();
+ i != message->doc.termlist_end (); i++) {
+
+ const std::string term = *i;
+
+ if (term.compare (0, property_prefix.size (), property_prefix) == 0)
+ continue;
+
+ if (term.compare (0, tag_prefix.size (), tag_prefix) == 0 &&
+ term.compare (1, strlen("encrypted"), "encrypted") != 0 &&
+ term.compare (1, strlen("signed"), "signed") != 0 &&
+ term.compare (1, strlen("attachment"), "attachment") != 0)
+ continue;
+
+ try {
+ message->doc.remove_term ((*i));
+ message->modified = TRUE;
+ } catch (const Xapian::InvalidArgumentError) {
+ /* Ignore failure to remove non-existent term. */
+ } catch (const Xapian::Error &error) {
+ notmuch_database_t *notmuch = message->notmuch;
+
+ if (!notmuch->exception_reported) {
+ _notmuch_database_log(_notmuch_message_database (message), "A Xapian exception occurred creating message: %s\n",
+ error.get_msg().c_str());
+ notmuch->exception_reported = TRUE;
+ }
+ return NOTMUCH_PRIVATE_STATUS_XAPIAN_EXCEPTION;
+ }
+ }
+ return NOTMUCH_PRIVATE_STATUS_SUCCESS;
+}
+
/* Return true if p points at "new" or "cur". */
static bool is_maildir (const char *p)
{
diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h
index 8587e86c..1198d932 100644
--- a/lib/notmuch-private.h
+++ b/lib/notmuch-private.h
@@ -509,6 +509,8 @@ _notmuch_message_add_reply (notmuch_message_t *message,
notmuch_database_t *
_notmuch_message_database (notmuch_message_t *message);
+void
+_notmuch_message_remove_unprefixed_terms (notmuch_message_t *message);
/* sha1.c */
char *
diff --git a/lib/notmuch.h b/lib/notmuch.h
index fc00f96d..33e9fd24 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -1685,6 +1685,10 @@ notmuch_message_thaw (notmuch_message_t *message);
void
notmuch_message_destroy (notmuch_message_t *message);
+/* for testing */
+
+void
+notmuch_test_clear_terms(notmuch_message_t *message);
/**
* @name Message Properties
*
--
2.11.0
next prev parent reply other threads:[~2017-04-04 1:47 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-02 13:16 second round of indexing all files David Bremner
2017-04-02 13:16 ` [rfc patch v2 1/5] lib: add definitions for notmuch_param_t David Bremner
2017-04-02 13:16 ` [rfc patch v2 2/5] added notmuch_message_reindex David Bremner
2017-04-02 13:16 ` [rfc patch v2 3/5] add "notmuch reindex" subcommand David Bremner
2017-04-02 13:16 ` [rfc patch v2 4/5] test: add known broken test for duplicate message id David Bremner
2017-04-02 13:16 ` [rfc patch v2 5/5] lib: index message files with duplicate message-ids David Bremner
2017-04-04 1:47 ` third round of indexing all files David Bremner
2017-04-04 1:47 ` [rfc patch v3 1/6] lib: add definitions for notmuch_param_t David Bremner
2017-04-04 1:47 ` David Bremner [this message]
2017-04-04 1:47 ` [rfc patch v3 3/6] added notmuch_message_reindex David Bremner
2017-04-04 1:47 ` [rfc patch v3 4/6] add "notmuch reindex" subcommand David Bremner
2017-04-04 1:47 ` [rfc patch v3 5/6] test: add known broken test for duplicate message id David Bremner
2017-04-04 1:47 ` [rfc patch v3 6/6] lib: index message files with duplicate message-ids David Bremner
2017-04-04 11:10 ` third round of indexing all files David Bremner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170404014738.25963-3-david@tethera.net \
--to=david@tethera.net \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).