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 2D4186DE0BA2 for ; Mon, 3 Apr 2017 18:47:48 -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 BrDdxsuXniUD for ; Mon, 3 Apr 2017 18:47:47 -0700 (PDT) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by arlo.cworth.org (Postfix) with ESMTPS id EAF486DE0B0A for ; Mon, 3 Apr 2017 18:47:46 -0700 (PDT) Received: from remotemail by fethera.tethera.net with local (Exim 4.84_2) (envelope-from ) id 1cvDYi-0006RM-HD; Mon, 03 Apr 2017 21:47:00 -0400 Received: (nullmailer pid 26086 invoked by uid 1000); Tue, 04 Apr 2017 01:47:42 -0000 From: David Bremner To: David Bremner , notmuch@notmuchmail.org Cc: Daniel Kahn Gillmor Subject: [rfc patch v3 3/6] added notmuch_message_reindex Date: Mon, 3 Apr 2017 22:47:35 -0300 Message-Id: <20170404014738.25963-4-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:48 -0000 From: Daniel Kahn Gillmor This new function asks the database to reindex a given message. The parameter `indexopts` is currently ignored, but is intended to provide an extensible API to support e.g. changing the encryption or filtering status (e.g. whether and how certain non-plaintext parts are indexed). --- lib/message.cc | 46 +++++++++++++++++++++++++++++++++++++++++++++- lib/notmuch.h | 14 ++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/lib/message.cc b/lib/message.cc index a7bd38ac..193eedb2 100644 --- a/lib/message.cc +++ b/lib/message.cc @@ -579,7 +579,9 @@ void _notmuch_message_remove_terms (notmuch_message_t *message, const char *prefix) { Xapian::TermIterator i; - size_t prefix_len = strlen (prefix); + size_t prefix_len = 0; + + prefix_len = strlen (prefix); while (1) { i = message->doc.termlist_begin (); @@ -1916,3 +1918,45 @@ _notmuch_message_frozen (notmuch_message_t *message) { return message->frozen; } + +notmuch_status_t +notmuch_message_reindex (notmuch_message_t *message, + notmuch_param_t unused (*indexopts)) +{ + notmuch_database_t *notmuch = NULL; + notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS, status; + notmuch_private_status_t private_status; + notmuch_filenames_t *orig_filenames = NULL; + const char *filename = NULL; + + if (message == NULL) + return NOTMUCH_STATUS_NULL_POINTER; + + notmuch = _notmuch_message_database (message); + + orig_filenames = notmuch_message_get_filenames (message); + + private_status = _notmuch_message_remove_indexed_terms (message); + if (private_status) + return COERCE_STATUS(private_status, "error removing terms"); + + /* re-add the filenames with the associated indexopts */ + for (; notmuch_filenames_valid (orig_filenames); + notmuch_filenames_move_to_next (orig_filenames)) { + filename = notmuch_filenames_get (orig_filenames); + + status = notmuch_database_add_message(notmuch, + filename, + &message); + if (status != NOTMUCH_STATUS_SUCCESS && + status != NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID) { + /* if we failed to add this filename, go ahead and try the + * next one as though it were first, but report the + * error... */ + ret = status; + } + } + + /* XXX TODO destroy orig_filenames? */ + return ret; +} diff --git a/lib/notmuch.h b/lib/notmuch.h index 33e9fd24..11818018 100644 --- a/lib/notmuch.h +++ b/lib/notmuch.h @@ -1389,6 +1389,20 @@ notmuch_filenames_t * notmuch_message_get_filenames (notmuch_message_t *message); /** + * Re-index the e-mail corresponding to 'message' using the supplied index options + * + * Returns the status of the re-index operation. (see the return + * codes documented in notmuch_database_add_message) + * + * After reindexing, the user should discard the message object passed + * in here by calling notmuch_message_destroy, since it refers to the + * original message, not to the reindexed message. + */ +notmuch_status_t +notmuch_message_reindex (notmuch_message_t *message, + notmuch_param_t *indexopts); + +/** * Message flags. */ typedef enum _notmuch_message_flag { -- 2.11.0