Projects STRLCPY neomutt Commits 06aaa05b
🤬
  • feat(notmuch): allow specifying notmuch configuration file

    Since `notmuch` 0.32, `libnotmuch` has an API to open the database with
    a configuration file. The options are a fully qualified path, empty
    string for no configuration file, and NULL for auto-detection of notmuch
    configuration. The `notmuch` backend relies on the auto-detection for
    opening the database with a fallback to no configuration. We have no
    mechanism for user-specified configurations.
    
    To allow user specification, this commit introduces a new configuration
    variable, `nm_config_file`. Users have the option of three values:
    
     1. A path
     2. An empty string for no configuration file
     3. `auto` for auto-detecting a config. file
    
    Allowing users to express the three possible options we can pass to
    `libnotmuch`. The `auto` keyword allows us to workaround the constraints
    of the configuration system without relying on validator and internal
    variable hacks.
    
    However, this change requires working around NeoMutt's configuration
    system as path variables map empty strings to `NULL`. While not ideal,
    it's a single conditional.
  • Loading...
  • Austin Ray committed with Richard Russon 2 years ago
    06aaa05b
    1 parent e26b521f
  • ■ ■ ■ ■ ■ ■
    docs/manual.xml.head
    skipped 16237 lines
    16238 16238   </thead>
    16239 16239   <tbody>
    16240 16240   <row>
     16241 + <entry><literal>nm_config_file</literal></entry>
     16242 + <entry>path</entry>
     16243 + <entry><literal>auto</literal></entry>
     16244 + <entry>
     16245 + Configuration file for the notmuch database. Either a path,
     16246 + <literal>auto</literal> for detecting a config. file, or
     16247 + empty for no configuration file. Only useful for notmuch
     16248 + 0.32+.
     16249 + </entry>
     16250 + </row>
     16251 + <row>
    16241 16252   <entry><literal>nm_db_limit</literal></entry>
    16242 16253   <entry>number</entry>
    16243 16254   <entry><literal>0</literal></entry>
    skipped 4176 lines
  • ■ ■ ■ ■ ■ ■
    notmuch/config.c
    skipped 95 lines
    96 96   
    97 97  static struct ConfigDef NotmuchVars[] = {
    98 98   // clang-format off
     99 + { "nm_config_file", DT_PATH, IP "auto", 0, NULL,
     100 + "(notmuch) Configuration file for notmuch. Use 'auto' to detect configuration."
     101 + },
    99 102   { "nm_db_limit", DT_NUMBER|DT_NOT_NEGATIVE, 0, 0, NULL,
    100 103   "(notmuch) Default limit for Notmuch queries"
    101 104   },
    skipped 69 lines
  • ■ ■ ■ ■ ■
    notmuch/db.c
    skipped 76 lines
    77 77  }
    78 78   
    79 79  /**
     80 + * get_nm_config_file - Gets the configuration file
     81 + * @retval ptr Config file path. Empty string if no config.
     82 + * @retval NULL Config file path set to `auto`.
     83 + */
     84 +static const char *get_nm_config_file(void)
     85 +{
     86 + const char *config_to_use = NULL;
     87 + const char *nm_config_file = cs_subset_path(NeoMutt->sub, "nm_config_file");
     88 + 
     89 + // Workaround the configuration system mapping "" to NULL.
     90 + if (nm_config_file == NULL)
     91 + {
     92 + config_to_use = "";
     93 + }
     94 + else if (!mutt_strn_equal(nm_config_file, "auto", 4))
     95 + {
     96 + config_to_use = nm_config_file;
     97 + }
     98 + 
     99 + return config_to_use;
     100 +}
     101 + 
     102 +/**
    80 103   * nm_db_do_open - Open a Notmuch database
    81 104   * @param filename Database filename
    82 105   * @param writable Read/write?
    skipped 20 lines
    103 126   {
    104 127  #if LIBNOTMUCH_CHECK_VERSION(5, 4, 0)
    105 128   // notmuch 0.32-0.32.2 didn't bump libnotmuch version to 5.4.
    106  - st = notmuch_database_open_with_config(filename, mode, NULL, NULL, &db, &msg);
    107  - if (st == NOTMUCH_STATUS_NO_CONFIG)
     129 + const char *config_file = get_nm_config_file();
     130 + 
     131 + st = notmuch_database_open_with_config(filename, mode, config_file, NULL, &db, &msg);
     132 + 
     133 + // Attempt opening database without configuration file. Don't if the user specified no config.
     134 + if (st == NOTMUCH_STATUS_NO_CONFIG && !mutt_str_equal(config_file, ""))
    108 135   {
    109  - mutt_debug(LL_DEBUG1, "nm: Could not find a Notmuch configuration file\n");
     136 + mutt_debug(LL_DEBUG1, "nm: Could not find notmuch configuration file: %s\n", config_file);
     137 + mutt_debug(LL_DEBUG1, "nm: Attempting to open notmuch db without configuration file.\n");
     138 + 
    110 139   FREE(&msg);
    111 140   
    112 141   st = notmuch_database_open_with_config(filename, mode, "", NULL, &db, &msg);
    skipped 254 lines
Please wait...
Page is in error, reload to recover