From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 5D22A6DE0AAB for ; Mon, 3 Apr 2017 18:47:54 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.005 X-Spam-Level: X-Spam-Status: No, score=-0.005 tagged_above=-999 required=5 tests=[AWL=0.006, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id aaOxZV2nv7_g for ; Mon, 3 Apr 2017 18:47:53 -0700 (PDT) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by arlo.cworth.org (Postfix) with ESMTPS id A26756DE0BBB for ; Mon, 3 Apr 2017 18:47:49 -0700 (PDT) Received: from remotemail by fethera.tethera.net with local (Exim 4.84_2) (envelope-from ) id 1cvDYl-0006S3-Np; Mon, 03 Apr 2017 21:47:03 -0400 Received: (nullmailer pid 26084 invoked by uid 1000); Tue, 04 Apr 2017 01:47:42 -0000 From: David Bremner To: David Bremner , 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 Message-Id: <20170404014738.25963-3-david@tethera.net> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170404014738.25963-1-david@tethera.net> References: <20170402131646.29884-1-david@tethera.net> <20170404014738.25963-1-david@tethera.net> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Apr 2017 01:47:54 -0000 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