X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=notmuch-config.c;h=91a24a76567c87dd69864733b125601fd1b1b082;hp=9531d254c47b4c08df23ff11fa8f4b605d6dc346;hb=2c4384a5763bdab308b8c417afa8d5f8e393b9a5;hpb=c1889aa331c4581094facffa0d826db62947eda4 diff --git a/notmuch-config.c b/notmuch-config.c index 9531d254..91a24a76 100644 --- a/notmuch-config.c +++ b/notmuch-config.c @@ -24,6 +24,8 @@ #include #include +#include "unicode-util.h" + static const char toplevel_config_comment[] = " .notmuch-config - Configuration file for the notmuch mail system\n" "\n" @@ -303,15 +305,15 @@ out: * returned and *is_new_ret will be set to 1 on return so that * the caller can recognize this case. * - * These default configuration settings are determined as - * follows: + * These default configuration settings are determined as + * follows: * * database_path: $MAILDIR, otherwise $HOME/mail * * user_name: $NAME variable if set, otherwise * read from /etc/passwd * - * user_primary_mail: $EMAIL variable if set, otherwise + * user_primary_mail: $EMAIL variable if set, otherwise * constructed from the username and * hostname of the current machine. * @@ -790,6 +792,43 @@ _item_split (char *item, char **group, char **key) return 0; } +/* These are more properly called Xapian fields, but the user facing + docs call them prefixes, so make the error message match */ +static bool +validate_field_name (const char *str) +{ + const char *key; + + if (! g_utf8_validate (str, -1, NULL)) { + fprintf (stderr, "Invalid utf8: %s\n", str); + return false; + } + + key = g_utf8_strrchr (str, -1, '.'); + if (! key ) { + INTERNAL_ERROR ("Impossible code path on input: %s\n", str); + } + + key++; + + if (! *key) { + fprintf (stderr, "Empty prefix name: %s\n", str); + return false; + } + + if (! unicode_word_utf8 (key)) { + fprintf (stderr, "Non-word character in prefix name: %s\n", key); + return false; + } + + if (key[0] >= 'a' && key[0] <= 'z') { + fprintf (stderr, "Prefix names starting with lower case letters are reserved: %s\n", key); + return false; + } + + return true; +} + #define BUILT_WITH_PREFIX "built_with." typedef struct config_key { @@ -802,6 +841,7 @@ typedef struct config_key { static struct config_key config_key_table[] = { {"index.decrypt", true, false, NULL}, + {"index.header.", true, true, validate_field_name}, {"query.", true, true, NULL}, };