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 "conn/lib.h"
36 #include "auth.h"
37 
41 static int imap_auth_validator(const struct ConfigSet *cs, const struct ConfigDef *cdef,
42  intptr_t value, struct Buffer *err)
43 {
44  const struct Slist *imap_auth_methods = (const struct Slist *) value;
45  if (!imap_auth_methods || (imap_auth_methods->count == 0))
46  return CSR_SUCCESS;
47 
48  struct ListNode *np = NULL;
49  STAILQ_FOREACH(np, &imap_auth_methods->head, entries)
50  {
51  if (imap_auth_is_valid(np->data))
52  continue;
53 #ifdef USE_SASL
54  if (sasl_auth_validator(np->data))
55  continue;
56 #endif
57  mutt_buffer_printf(err, _("Option %s: %s is not a valid authenticator"),
58  cdef->name, np->data);
59  return CSR_ERR_INVALID;
60  }
61 
62  return CSR_SUCCESS;
63 }
64 
65 static struct ConfigDef ImapVars[] = {
66  // clang-format off
67  { "imap_check_subscribed", DT_BOOL, false, 0, NULL,
68  "(imap) When opening a mailbox, ask the server for a list of subscribed folders"
69  },
70  { "imap_condstore", DT_BOOL, false, 0, NULL,
71  "(imap) Enable the CONDSTORE extension"
72  },
73 #ifdef USE_ZLIB
74  { "imap_deflate", DT_BOOL, true, 0, NULL,
75  "(imap) Compress network traffic"
76  },
77 #endif
78  { "imap_authenticators", DT_SLIST|SLIST_SEP_COLON, 0, 0, imap_auth_validator,
79  "(imap) List of allowed IMAP authentication methods (colon-separated)"
80  },
81  { "imap_delim_chars", DT_STRING, IP "/.", 0, NULL,
82  "(imap) Characters that denote separators in IMAP folders"
83  },
84  { "imap_fetch_chunk_size", DT_LONG|DT_NOT_NEGATIVE, 0, 0, NULL,
85  "(imap) Download headers in blocks of this size"
86  },
87  { "imap_headers", DT_STRING|R_INDEX, 0, 0, NULL,
88  "(imap) Additional email headers to download when getting index"
89  },
90  { "imap_idle", DT_BOOL, false, 0, NULL,
91  "(imap) Use the IMAP IDLE extension to check for new mail"
92  },
93  { "imap_login", DT_STRING|DT_SENSITIVE, 0, 0, NULL,
94  "(imap) Login name for the IMAP server (defaults to `$imap_user`)"
95  },
96  { "imap_oauth_refresh_command", DT_STRING|DT_COMMAND|DT_SENSITIVE, 0, 0, NULL,
97  "(imap) External command to generate OAUTH refresh token"
98  },
99  { "imap_pass", DT_STRING|DT_SENSITIVE, 0, 0, NULL,
100  "(imap) Password for the IMAP server"
101  },
102  { "imap_pipeline_depth", DT_NUMBER|DT_NOT_NEGATIVE, 15, 0, NULL,
103  "(imap) Number of IMAP commands that may be queued up"
104  },
105  { "imap_rfc5161", DT_BOOL, true, 0, NULL,
106  "(imap) Use the IMAP ENABLE extension to select capabilities"
107  },
108  { "imap_server_noise", DT_BOOL, true, 0, NULL,
109  "(imap) Display server warnings as error messages"
110  },
111  { "imap_keepalive", DT_NUMBER|DT_NOT_NEGATIVE, 300, 0, NULL,
112  "(imap) Time to wait before polling an open IMAP connection"
113  },
114  { "imap_list_subscribed", DT_BOOL, false, 0, NULL,
115  "(imap) When browsing a mailbox, only display subscribed folders"
116  },
117  { "imap_passive", DT_BOOL, true, 0, NULL,
118  "(imap) Reuse an existing IMAP connection to check for new mail"
119  },
120  { "imap_peek", DT_BOOL, true, 0, NULL,
121  "(imap) Don't mark messages as read when fetching them from the server"
122  },
123  { "imap_poll_timeout", DT_NUMBER|DT_NOT_NEGATIVE, 15, 0, NULL,
124  "(imap) Maximum time to wait for a server response"
125  },
126  { "imap_qresync", DT_BOOL, false, 0, NULL,
127  "(imap) Enable the QRESYNC extension"
128  },
129  { "imap_user", DT_STRING|DT_SENSITIVE, 0, 0, NULL,
130  "(imap) Username for the IMAP server"
131  },
132 
133  { "imap_servernoise", DT_SYNONYM, IP "imap_server_noise", },
134 
135  { NULL },
136  // clang-format on
137 };
138 
142 bool config_init_imap(struct ConfigSet *cs)
143 {
144  return cs_register_variables(cs, ImapVars, 0);
145 }
#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_LONG
a number (long)
Definition: types.h:33
String manipulation buffer.
Definition: buffer.h:33
IMAP authenticator multiplexor.
#define _(a)
Definition: message.h:28
#define DT_NOT_NEGATIVE
Negative numbers are not allowed.
Definition: types.h:47
#define DT_SLIST
a list of strings
Definition: types.h:39
String list.
Definition: slist.h:46
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
Definition: set.h:63
#define DT_SENSITIVE
Contains sensitive value, e.g. password.
Definition: types.h:49
Convenience wrapper for the config headers.
struct ListHead head
Definition: slist.h:48
bool cs_register_variables(const struct ConfigSet *cs, struct ConfigDef vars[], uint32_t flags)
Register a set of config items.
Definition: set.c:276
const char * name
User-visible name.
Definition: set.h:65
size_t count
Definition: slist.h:49
#define DT_STRING
a string
Definition: types.h:41
bool imap_auth_is_valid(const char *authenticator)
Check if string is a valid imap authentication method.
Definition: auth.c:87
#define DT_COMMAND
A command.
Definition: types.h:50
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
#define SLIST_SEP_COLON
Definition: slist.h:35
char * data
String.
Definition: list.h:36
#define DT_SYNONYM
synonym for another variable
Definition: types.h:42
static int imap_auth_validator(const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
Validate the "imap_authenticators" config variable - Implements ConfigDef::validator() -...
Definition: config.c:41
Connection Library.
Convenience wrapper for the library headers.
A List node for strings.
Definition: list.h:34
bool sasl_auth_validator(const char *authenticator)
Validate an auth method against Cyrus SASL methods.
Definition: sasl.c:127
#define DT_NUMBER
a number
Definition: types.h:35
#define DT_BOOL
boolean option
Definition: types.h:30
bool config_init_imap(struct ConfigSet *cs)
Register imap config variables - Implements module_init_config_t -.
Definition: config.c:142
#define R_INDEX
Redraw the index menu (MENU_MAIN)
Definition: types.h:65