]> git.notmuchmail.org Git - notmuch/blobdiff - notmuch-config.c
cli: partial whitespace cleanup in notmuch-config.c
[notmuch] / notmuch-config.c
index 9531d254c47b4c08df23ff11fa8f4b605d6dc346..91a24a76567c87dd69864733b125601fd1b1b082 100644 (file)
@@ -24,6 +24,8 @@
 #include <netdb.h>
 #include <assert.h>
 
+#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},
 };