lib/database: index user headers.
authorDavid Bremner <david@tethera.net>
Tue, 26 Feb 2019 02:10:29 +0000 (22:10 -0400)
committerDavid Bremner <david@tethera.net>
Sat, 25 May 2019 10:21:13 +0000 (07:21 -0300)
This essentially involves calling _notmuch_message_gen_terms once for
each user defined header.

lib/database.cc
lib/index.cc
lib/notmuch-private.h
test/T750-user-header.sh

index b3fe6373e645e2c68147f8f90347645e3c0bb81b..4c4c9edc0b870241125ae8a06c2b2a76b322d3e0 100644 (file)
@@ -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)
 {
index 418224880a2ff9a9b9dc565e9182a8a9538097c1..f216ae5deb44becd81874bc5309cbb4ac4762e5b 100644 (file)
@@ -572,6 +572,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,
@@ -601,6 +626,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;
index cf08411e78d031a180b4019c183430093db34e14..e46df9a82d719ea4c0e6442dee4f3767203e6a19 100644 (file)
@@ -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 *
index 2d6cc60b6f293772299fd4c38615ffa725133995..204c052a41db099170a6cdba8a0f9a8bdc4fb0d9 100755 (executable)
@@ -91,4 +91,21 @@ Query((Tmail AND (XUList:notmuchmail@1 PHRASE 2 XUList:org@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