mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-12-22 17:34:54 +01:00
lib/database: index user headers.
This essentially involves calling _notmuch_message_gen_terms once for each user defined header.
This commit is contained in:
parent
75bdce7952
commit
adb53b0737
4 changed files with 55 additions and 0 deletions
|
@ -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)
|
||||
{
|
||||
|
|
27
lib/index.cc
27
lib/index.cc
|
@ -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;
|
||||
|
|
|
@ -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 *
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue