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