[PATCH 8/9] lib/database: index user headers.
David Bremner
david at tethera.net
Sun Apr 28 16:10:48 PDT 2019
There is a O(log(#user headers)) penalty for the second lookup of the
prefix name.
---
lib/database.cc | 6 ++++++
lib/index.cc | 27 +++++++++++++++++++++++++++
lib/notmuch-private.h | 5 +++++
test/T750-user-header.sh | 17 +++++++++++++++++
4 files changed, 55 insertions(+)
diff --git a/lib/database.cc b/lib/database.cc
index a2a33d24..ff1ca2b3 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -322,6 +322,12 @@ _setup_query_field_default (const prefix_t *prefix, notmuch_database_t *notmuch)
notmuch->query_parser->add_boolean_prefix (prefix->name, prefix->prefix);
}
+notmuch_string_map_iterator_t *
+_notmuch_database_user_headers (notmuch_database_t *notmuch)
+{
+ return _notmuch_string_map_iterator_create (notmuch->user_header, "", false);
+}
+
const char *
_user_prefix (void *ctx, const char* name)
{
diff --git a/lib/index.cc b/lib/index.cc
index efd9da4c..c2c31e4a 100644
--- a/lib/index.cc
+++ b/lib/index.cc
@@ -595,6 +595,31 @@ _index_encrypted_mime_part (notmuch_message_t *message,
}
+static notmuch_status_t
+_notmuch_message_index_user_headers (notmuch_message_t *message, GMimeMessage *mime_message)
+{
+
+ notmuch_database_t *notmuch = notmuch_message_get_database (message);
+ notmuch_string_map_iterator_t *iter = _notmuch_database_user_headers (notmuch);
+
+ for (; _notmuch_string_map_iterator_valid (iter);
+ _notmuch_string_map_iterator_move_to_next (iter)) {
+
+ const char *prefix_name = _notmuch_string_map_iterator_key (iter);
+
+ const char *header_name = _notmuch_string_map_iterator_value (iter);
+
+ const char *header = g_mime_object_get_header (GMIME_OBJECT (mime_message), header_name);
+ if (header)
+ _notmuch_message_gen_terms (message, prefix_name, header);
+ }
+
+ if (iter)
+ _notmuch_string_map_iterator_destroy (iter);
+ return NOTMUCH_STATUS_SUCCESS;
+
+}
+
notmuch_status_t
_notmuch_message_index_file (notmuch_message_t *message,
notmuch_indexopts_t *indexopts,
@@ -625,6 +650,8 @@ _notmuch_message_index_file (notmuch_message_t *message,
subject = g_mime_message_get_subject (mime_message);
_notmuch_message_gen_terms (message, "subject", subject);
+ status = _notmuch_message_index_user_headers (message, mime_message);
+
_index_mime_part (message, indexopts, g_mime_message_get_mime_part (mime_message));
return NOTMUCH_STATUS_SUCCESS;
diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h
index cf08411e..e46df9a8 100644
--- a/lib/notmuch-private.h
+++ b/lib/notmuch-private.h
@@ -652,6 +652,11 @@ _notmuch_string_map_iterator_value (notmuch_string_map_iterator_t *iterator);
void
_notmuch_string_map_iterator_destroy (notmuch_string_map_iterator_t *iterator);
+/* Create an iterator for user headers. Destroy with
+ * _notmuch_string_map_iterator_destroy. Actually in database.cc*/
+notmuch_string_map_iterator_t *
+_notmuch_database_user_headers (notmuch_database_t *notmuch);
+
/* tags.c */
notmuch_tags_t *
diff --git a/test/T750-user-header.sh b/test/T750-user-header.sh
index 2d6cc60b..204c052a 100755
--- a/test/T750-user-header.sh
+++ b/test/T750-user-header.sh
@@ -91,4 +91,21 @@ Query((Tmail AND (XUList:notmuchmail at 1 PHRASE 2 XUList:org at 2)))
EOF
test_expect_equal_file EXPECTED OUTPUT
+test_begin_subtest "index user header"
+notmuch config set index.header.List "List-Id"
+notmuch reindex '*'
+notmuch search --output=files List:notmuch | notmuch_search_files_sanitize | sort > OUTPUT
+cat <<EOF > EXPECTED
+MAIL_DIR/bar/baz/05:2,
+MAIL_DIR/bar/baz/23:2,
+MAIL_DIR/bar/baz/24:2,
+MAIL_DIR/bar/cur/20:2,
+MAIL_DIR/bar/new/21:2,
+MAIL_DIR/bar/new/22:2,
+MAIL_DIR/foo/cur/08:2,
+MAIL_DIR/foo/new/03:2,
+MAIL_DIR/new/04:2,
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
test_done
--
2.20.1
More information about the notmuch
mailing list