NeoMutt  2021-02-05-666-ge300cd
Teaching an old dog new tricks
DOXYGEN
config.c
Go to the documentation of this file.
1 
29 #include "config.h"
30 #include <stddef.h>
31 #include <config/lib.h>
32 #include <stdbool.h>
33 #include <stdint.h>
34 #include "mutt/lib.h"
35 #include "notmuch/private.h"
36 #include "notmuch/query.h"
37 
43 static bool is_valid_notmuch_url(const char *url)
44 {
45  return mutt_istr_startswith(url, NmUrlProtocol) && (url[NmUrlProtocolLen] == '/');
46 }
47 
51 static int nm_default_url_validator(const struct ConfigSet *cs, const struct ConfigDef *cdef,
52  intptr_t value, struct Buffer *err)
53 {
54  const char *url = (const char *) value;
55  if (!is_valid_notmuch_url(url))
56  {
58  err, _("nm_default_url must be: notmuch://<absolute path> . Current: %s"), url);
59  return CSR_ERR_INVALID;
60  }
61 
62  return CSR_SUCCESS;
63 }
64 
75 static int nm_query_window_timebase_validator(const struct ConfigSet *cs,
76  const struct ConfigDef *cdef,
77  intptr_t value, struct Buffer *err)
78 {
79  const char *timebase = (const char *) value;
80  if (!nm_query_window_check_timebase(timebase))
81  {
83  // L10N: The values 'hour', 'day', 'week', 'month', 'year' are literal.
84  // They should not be translated.
85  err, _("Invalid nm_query_window_timebase value (valid values are: "
86  "hour, day, week, month, year)"));
87  return CSR_ERR_INVALID;
88  }
89 
90  return CSR_SUCCESS;
91 }
92 
93 static struct ConfigDef NotmuchVars[] = {
94  // clang-format off
95  { "nm_db_limit", DT_NUMBER|DT_NOT_NEGATIVE, 0, 0, NULL,
96  "(notmuch) Default limit for Notmuch queries"
97  },
98  { "nm_default_url", DT_STRING, 0, 0, nm_default_url_validator,
99  "(notmuch) Path to the Notmuch database"
100  },
101  { "nm_exclude_tags", DT_STRING, 0, 0, NULL,
102  "(notmuch) Exclude messages with these tags"
103  },
104  { "nm_flagged_tag", DT_STRING, IP "flagged", 0, NULL,
105  "(notmuch) Tag to use for flagged messages"
106  },
107  { "nm_open_timeout", DT_NUMBER|DT_NOT_NEGATIVE, 5, 0, NULL,
108  "(notmuch) Database timeout"
109  },
110  { "nm_query_type", DT_STRING, IP "messages", 0, NULL,
111  "(notmuch) Default query type: 'threads' or 'messages'"
112  },
113  { "nm_query_window_current_position", DT_NUMBER, 0, 0, NULL,
114  "(notmuch) Position of current search window"
115  },
116  { "nm_query_window_current_search", DT_STRING, 0, 0, NULL,
117  "(notmuch) Current search parameters"
118  },
119  { "nm_query_window_duration", DT_NUMBER|DT_NOT_NEGATIVE, 0, 0, NULL,
120  "(notmuch) Time duration of the current search window"
121  },
122  { "nm_query_window_enable", DT_BOOL, false, 0, NULL,
123  "(notmuch) Enable query windows"
124  },
125  { "nm_query_window_or_terms", DT_STRING, 0, 0, NULL,
126  "(notmuch) Additional notmuch search terms for messages to be shown regardless of date"
127  },
128  { "nm_query_window_timebase", DT_STRING, IP "week", 0, nm_query_window_timebase_validator,
129  "(notmuch) Units for the time duration"
130  },
131  { "nm_record_tags", DT_STRING, 0, 0, NULL,
132  "(notmuch) Tags to apply to the 'record' mailbox (sent mail)"
133  },
134  { "nm_replied_tag", DT_STRING, IP "replied", 0, NULL,
135  "(notmuch) Tag to use for replied messages"
136  },
137  { "nm_unread_tag", DT_STRING, IP "unread", 0, NULL,
138  "(notmuch) Tag to use for unread messages"
139  },
140  { "vfolder_format", DT_STRING|DT_NOT_EMPTY|R_INDEX, IP "%2C %?n?%4n/& ?%4m %f", 0, NULL,
141  "(notmuch) printf-like format string for the browser's display of virtual folders"
142  },
143  { "virtual_spool_file", DT_BOOL, false, 0, NULL,
144  "(notmuch) Use the first virtual mailbox as a spool file"
145  },
146 
147  { "nm_default_uri", DT_SYNONYM, IP "nm_default_url", },
148  { "virtual_spoolfile", DT_SYNONYM, IP "virtual_spool_file", },
149 
150  { NULL },
151  // clang-format on
152 };
153 
158 {
159  return cs_register_variables(cs, NotmuchVars, 0);
160 }
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:35
Container for lots of config items.
Definition: set.h:259
#define IP
Definition: set.h:54
#define CSR_ERR_INVALID
Value hasn&#39;t been set.
Definition: set.h:38
#define DT_NOT_EMPTY
Empty strings are not allowed.
Definition: types.h:46
bool nm_query_window_check_timebase(const char *timebase)
Checks if a given timebase string is valid.
Definition: query.c:149
String manipulation buffer.
Definition: buffer.h:33
#define _(a)
Definition: message.h:28
#define DT_NOT_NEGATIVE
Negative numbers are not allowed.
Definition: types.h:47
static bool is_valid_notmuch_url(const char *url)
Checks that a URL is in required form.
Definition: config.c:43
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
Definition: set.h:63
Convenience wrapper for the config headers.
Notmuch query functions.
static int nm_default_url_validator(const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
Ensure nm_default_url is of the form notmuch://[absolute path] - Implements ConfigDef::validator() -...
Definition: config.c:51
bool cs_register_variables(const struct ConfigSet *cs, struct ConfigDef vars[], uint32_t flags)
Register a set of config items.
Definition: set.c:276
bool config_init_notmuch(struct ConfigSet *cs)
Register notmuch config variables - Implements module_init_config_t -.
Definition: config.c:157
#define DT_STRING
a string
Definition: types.h:41
size_t mutt_istr_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix, ignoring case.
Definition: string.c:172
const char NmUrlProtocol[]
Definition: notmuch.c:93
#define DT_SYNONYM
synonym for another variable
Definition: types.h:42
const int NmUrlProtocolLen
Definition: notmuch.c:94
Convenience wrapper for the library headers.
Notmuch private types.
#define DT_NUMBER
a number
Definition: types.h:35
#define DT_BOOL
boolean option
Definition: types.h:30
#define R_INDEX
Redraw the index menu (MENU_MAIN)
Definition: types.h:65
static int nm_query_window_timebase_validator(const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
Ensures nm_query_window_timebase matches allowed values - Implements ConfigDef::validator() -Allowed ...
Definition: config.c:75