NeoMutt  2023-11-03-85-g512e01
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
config.c
Go to the documentation of this file.
1
29#include "config.h"
30#include <stddef.h>
31#include <stdbool.h>
32#include <stdint.h>
33#include "private.h"
34#include "mutt/lib.h"
35#include "config/lib.h"
36#include "query.h"
37
38#ifdef USE_NOTMUCH
45static bool is_valid_notmuch_url(const char *url)
46{
47 return mutt_istr_startswith(url, NmUrlProtocol) && (url[NmUrlProtocolLen] == '/');
48}
49#endif
50
56static int nm_default_url_validator(const struct ConfigSet *cs, const struct ConfigDef *cdef,
57 intptr_t value, struct Buffer *err)
58{
59#ifdef USE_NOTMUCH
60 const char *url = (const char *) value;
61 if (!is_valid_notmuch_url(url))
62 {
63 buf_printf(err, _("nm_default_url must be: notmuch://<absolute path> . Current: %s"), url);
64 return CSR_ERR_INVALID;
65 }
66#endif
67 return CSR_SUCCESS;
68}
69
83 const struct ConfigDef *cdef,
84 intptr_t value, struct Buffer *err)
85{
86#ifdef USE_NOTMUCH
87 const char *timebase = (const char *) value;
88 if (!nm_query_window_check_timebase(timebase))
89 {
91 // L10N: The values 'hour', 'day', 'week', 'month', 'year' are literal.
92 // They should not be translated.
93 err, _("Invalid nm_query_window_timebase value (valid values are: "
94 "hour, day, week, month, year)"));
95 return CSR_ERR_INVALID;
96 }
97#endif
98 return CSR_SUCCESS;
99}
100
104static struct ConfigDef NotmuchVars[] = {
105 // clang-format off
106 { "nm_config_file", DT_PATH|DT_PATH_FILE, IP "auto", 0, NULL,
107 "(notmuch) Configuration file for notmuch. Use 'auto' to detect configuration."
108 },
109 { "nm_config_profile", DT_STRING, 0, 0, NULL,
110 "(notmuch) Configuration profile for notmuch."
111 },
112 { "nm_db_limit", DT_NUMBER|DT_NOT_NEGATIVE, 0, 0, NULL,
113 "(notmuch) Default limit for Notmuch queries"
114 },
115 { "nm_default_url", DT_STRING, 0, 0, nm_default_url_validator,
116 "(notmuch) Path to the Notmuch database"
117 },
118 { "nm_exclude_tags", DT_STRING, 0, 0, NULL,
119 "(notmuch) Exclude messages with these tags"
120 },
121 { "nm_flagged_tag", DT_STRING, IP "flagged", 0, NULL,
122 "(notmuch) Tag to use for flagged messages"
123 },
124 { "nm_open_timeout", DT_NUMBER|DT_NOT_NEGATIVE, 5, 0, NULL,
125 "(notmuch) Database timeout"
126 },
127 { "nm_query_type", DT_STRING, IP "messages", 0, NULL,
128 "(notmuch) Default query type: 'threads' or 'messages'"
129 },
130 { "nm_query_window_current_position", DT_NUMBER, 0, 0, NULL,
131 "(notmuch) Position of current search window"
132 },
133 { "nm_query_window_current_search", DT_STRING, 0, 0, NULL,
134 "(notmuch) Current search parameters"
135 },
136 { "nm_query_window_duration", DT_NUMBER|DT_NOT_NEGATIVE, 0, 0, NULL,
137 "(notmuch) Time duration of the current search window"
138 },
139 { "nm_query_window_enable", DT_BOOL, false, 0, NULL,
140 "(notmuch) Enable query windows"
141 },
142 { "nm_query_window_or_terms", DT_STRING, 0, 0, NULL,
143 "(notmuch) Additional notmuch search terms for messages to be shown regardless of date"
144 },
145 { "nm_query_window_timebase", DT_STRING, IP "week", 0, nm_query_window_timebase_validator,
146 "(notmuch) Units for the time duration"
147 },
148 { "nm_record_tags", DT_STRING, 0, 0, NULL,
149 "(notmuch) Tags to apply to the 'record' mailbox (sent mail)"
150 },
151 { "nm_replied_tag", DT_STRING, IP "replied", 0, NULL,
152 "(notmuch) Tag to use for replied messages"
153 },
154 { "nm_unread_tag", DT_STRING, IP "unread", 0, NULL,
155 "(notmuch) Tag to use for unread messages"
156 },
157 { "virtual_spool_file", DT_BOOL, false, 0, NULL,
158 "(notmuch) Use the first virtual mailbox as a spool file"
159 },
160
161 { "vfolder_format", DT_DEPRECATED|DT_STRING, 0, IP "2018-11-01" },
162
163 { "nm_default_uri", DT_SYNONYM, IP "nm_default_url", IP "2021-02-11" },
164 { "virtual_spoolfile", DT_SYNONYM, IP "virtual_spool_file", IP "2021-02-11" },
165 { NULL },
166 // clang-format on
167};
168
173{
174 bool rc = false;
175
176#if defined(USE_NOTMUCH)
178#endif
179
180 return rc;
181}
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:173
Convenience wrapper for the config headers.
bool cs_register_variables(const struct ConfigSet *cs, struct ConfigDef vars[], uint32_t flags)
Register a set of config items.
Definition: set.c:279
#define CSR_ERR_INVALID
Value hasn't been set.
Definition: set.h:38
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:35
#define IP
Definition: set.h:54
static int nm_query_window_timebase_validator(const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
Validate the "nm_query_window_timebase" config variable - Implements ConfigDef::validator() -.
Definition: config.c:82
static int nm_default_url_validator(const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
Validate the "nm_default_url" config variable - Implements ConfigDef::validator() -.
Definition: config.c:56
bool config_init_notmuch(struct ConfigSet *cs)
Register notmuch config variables - Implements module_init_config_t -.
Definition: config.c:172
Convenience wrapper for the library headers.
#define _(a)
Definition: message.h:28
size_t mutt_istr_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix, ignoring case.
Definition: string.c:240
static bool is_valid_notmuch_url(const char *url)
Checks that a URL is in required form.
Definition: config.c:45
static struct ConfigDef NotmuchVars[]
Config definitions for the Notmuch library.
Definition: config.c:104
const int NmUrlProtocolLen
Length of NmUrlProtocol string.
Definition: notmuch.c:95
const char NmUrlProtocol[]
Protocol string for Notmuch URLs.
Definition: notmuch.c:93
bool nm_query_window_check_timebase(const char *timebase)
Checks if a given timebase string is valid.
Definition: query.c:148
Notmuch query functions.
GUI display the mailboxes in a side panel.
String manipulation buffer.
Definition: buffer.h:34
Definition: set.h:64
Container for lots of config items.
Definition: set.h:252
#define DT_BOOL
boolean option
Definition: types.h:30
#define DT_DEPRECATED
Config item shouldn't be used any more.
Definition: types.h:78
#define DT_PATH_FILE
Path is a file.
Definition: types.h:58
#define DT_PATH
a path to a file/directory
Definition: types.h:36
#define DT_STRING
a string
Definition: types.h:41
#define DT_SYNONYM
synonym for another variable
Definition: types.h:42
#define DT_NO_FLAGS
No flags are set.
Definition: types.h:47
#define DT_NOT_NEGATIVE
Negative numbers are not allowed.
Definition: types.h:51
#define DT_NUMBER
a number
Definition: types.h:35