X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=lib%2Fdatabase.cc;h=4c4c9edc0b870241125ae8a06c2b2a76b322d3e0;hp=d2732f5e507343f384ceaadff3af1d748f202d1c;hb=adb53b073791f710b93a8fc755b6b7b606bf7fd1;hpb=319dd95ebbd841320e269d34e67a824876f8426a diff --git a/lib/database.cc b/lib/database.cc index d2732f5e..4c4c9edc 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -322,6 +322,64 @@ _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) +{ + return talloc_asprintf(ctx, "XU%s:", name); +} + +static notmuch_status_t +_setup_user_query_fields (notmuch_database_t *notmuch) +{ + notmuch_config_list_t *list; + notmuch_status_t status; + + notmuch->user_prefix = _notmuch_string_map_create (notmuch); + if (notmuch->user_prefix == NULL) + return NOTMUCH_STATUS_OUT_OF_MEMORY; + + notmuch->user_header = _notmuch_string_map_create (notmuch); + if (notmuch->user_header == NULL) + return NOTMUCH_STATUS_OUT_OF_MEMORY; + + status = notmuch_database_get_config_list (notmuch, CONFIG_HEADER_PREFIX, &list); + if (status) + return status; + + for (; notmuch_config_list_valid (list); notmuch_config_list_move_to_next (list)) { + + prefix_t query_field; + + const char *key = notmuch_config_list_key (list) + + sizeof (CONFIG_HEADER_PREFIX) - 1; + + _notmuch_string_map_append (notmuch->user_prefix, + key, + _user_prefix (notmuch, key)); + + _notmuch_string_map_append (notmuch->user_header, + key, + notmuch_config_list_value (list)); + + query_field.name = talloc_strdup (notmuch, key); + query_field.prefix = _user_prefix (notmuch, key); + query_field.flags = NOTMUCH_FIELD_PROBABILISTIC + | NOTMUCH_FIELD_EXTERNAL; + + _setup_query_field_default (&query_field, notmuch); + } + + notmuch_config_list_destroy (list); + + return NOTMUCH_STATUS_SUCCESS; +} + #if HAVE_XAPIAN_FIELD_PROCESSOR static void _setup_query_field (const prefix_t *prefix, notmuch_database_t *notmuch) @@ -370,6 +428,26 @@ _find_prefix (const char *name) return ""; } +/* Like find prefix, but include the possibility of user defined + * prefixes specific to this database */ + +const char * +_notmuch_database_prefix (notmuch_database_t *notmuch, const char *name) +{ + unsigned int i; + + /*XXX TODO: reduce code duplication */ + for (i = 0; i < ARRAY_SIZE (prefix_table); i++) { + if (strcmp (name, prefix_table[i].name) == 0) + return prefix_table[i].prefix; + } + + if (notmuch->user_prefix) + return _notmuch_string_map_get (notmuch->user_prefix, name); + + return NULL; +} + static const struct { /* NOTMUCH_FEATURE_* value. */ _notmuch_features value; @@ -880,7 +958,7 @@ notmuch_database_open_verbose (const char *path, /* Initialize gmime */ if (! initialized) { - g_mime_init (GMIME_ENABLE_RFC2047_WORKAROUNDS); + g_mime_init (); initialized = 1; } @@ -986,6 +1064,7 @@ notmuch_database_open_verbose (const char *path, _setup_query_field (prefix, notmuch); } } + status = _setup_user_query_fields (notmuch); } catch (const Xapian::Error &error) { IGNORE_RESULT (asprintf (&message, "A Xapian exception occurred opening database: %s\n", error.get_msg().c_str()));