NeoMutt  2025-09-05-55-g97fc89
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
config.c
Go to the documentation of this file.
1
27
33
34#include "config.h"
35#include <stdbool.h>
36#include <stdint.h>
37#include <string.h>
38#include "mutt/lib.h"
39#include "config/lib.h"
40#include "email/lib.h"
41#include "expando/lib.h"
42#include "smtp.h"
43#ifdef USE_SASL_CYRUS
44#include "conn/lib.h"
45#endif
46
47extern const struct ExpandoDefinition IndexFormatDef[];
48
50static const struct ExpandoDefinition *const IndexFormatDefNoPadding = &(IndexFormatDef[3]);
51
52extern const struct ExpandoDefinition NntpFormatDef[];
53
57static int wrapheaders_validator(const struct ConfigDef *cdef, intptr_t value,
58 struct Buffer *err)
59{
60 const int min_length = 78; // Recommendations from RFC5233
61 const int max_length = 998;
62
63 if ((value >= min_length) && (value <= max_length))
64 return CSR_SUCCESS;
65
66 // L10N: This applies to the "$wrap_headers" config variable.
67 buf_printf(err, _("Option %s must be between %d and %d inclusive"),
68 cdef->name, min_length, max_length);
69 return CSR_ERR_INVALID;
70}
71
75static int smtp_auth_validator(const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
76{
77 const struct Slist *smtp_auth_methods = (const struct Slist *) value;
78 if (!smtp_auth_methods || (smtp_auth_methods->count == 0))
79 return CSR_SUCCESS;
80
81 struct ListNode *np = NULL;
82 STAILQ_FOREACH(np, &smtp_auth_methods->head, entries)
83 {
84 if (smtp_auth_is_valid(np->data))
85 continue;
86#ifdef USE_SASL_CYRUS
88 continue;
89#endif
90 buf_printf(err, _("Option %s: %s is not a valid authenticator"), cdef->name, np->data);
91 return CSR_ERR_INVALID;
92 }
93
94 return CSR_SUCCESS;
95}
96
100static int simple_command_validator(const struct ConfigDef *cdef,
101 intptr_t value, struct Buffer *err)
102{
103 // Check for shell metacharacters that won't do what the user expects
104 const char *valstr = (const char *) value;
105 if (!valstr)
106 return CSR_SUCCESS;
107
108 const char c = valstr[strcspn(valstr, "|&;()<>[]{}$`'~\"\\*?")];
109 if (c == '\0')
110 return CSR_SUCCESS;
111
112 // L10N: This applies to the "$sendmail" and "$inews" config variables.
113 buf_printf(err, _("Option %s must not contain shell metacharacters: %c"), cdef->name, c);
114 return CSR_ERR_INVALID;
115}
116
123static const struct ExpandoDefinition GreetingFormatDef[] = {
124 // clang-format off
125 { "n", "real-name", ED_ENVELOPE, ED_ENV_REAL_NAME, NULL },
126 { "u", "user-name", ED_ENVELOPE, ED_ENV_USER_NAME, NULL },
127 { "v", "first-name", ED_ENVELOPE, ED_ENV_FIRST_NAME, NULL },
128 { NULL, NULL, 0, -1, NULL }
129 // clang-format on
130};
131
135static struct ConfigDef SendVars[] = {
136 // clang-format off
137 { "abort_noattach", DT_QUAD, MUTT_NO, 0, NULL,
138 "Abort sending the email if attachments are missing"
139 },
140 { "abort_noattach_regex", DT_REGEX, IP "\\<(attach|attached|attachments?)\\>", 0, NULL,
141 "Regex to match text indicating attachments are expected"
142 },
143 { "abort_nosubject", DT_QUAD, MUTT_ASKYES, 0, NULL,
144 "Abort creating the email if subject is missing"
145 },
146 { "abort_unmodified", DT_QUAD, MUTT_YES, 0, NULL,
147 "Abort the sending if the message hasn't been edited"
148 },
149 { "allow_8bit", DT_BOOL, true, 0, NULL,
150 "Allow 8-bit messages, don't use quoted-printable or base64"
151 },
152 { "ask_bcc", DT_BOOL, false, 0, NULL,
153 "Ask the user for the blind-carbon-copy recipients"
154 },
155 { "ask_cc", DT_BOOL, false, 0, NULL,
156 "Ask the user for the carbon-copy recipients"
157 },
158 { "ask_followup_to", DT_BOOL, false, 0, NULL,
159 "(nntp) Ask the user for follow-up groups before editing"
160 },
161 { "ask_x_comment_to", DT_BOOL, false, 0, NULL,
162 "(nntp) Ask the user for the 'X-Comment-To' field before editing"
163 },
165 "When attaching files, use one of these character sets"
166 },
167 // L10N: $attribution_intro default format
168 { "attribution_intro", DT_EXPANDO|D_L10N_STRING, IP N_("On %d, %n wrote:"), IP IndexFormatDefNoPadding, NULL,
169 "Message to start a reply, 'On DATE, PERSON wrote:'"
170 },
171 { "attribution_locale", DT_STRING, 0, 0, NULL,
172 "Locale for dates in the attribution message"
173 },
174 { "attribution_trailer", DT_EXPANDO, 0, IP IndexFormatDefNoPadding, NULL,
175 "Suffix message to add after reply text"
176 },
177 { "bounce_delivered", DT_BOOL, true, 0, NULL,
178 "Add 'Delivered-To' to bounced messages"
179 },
180 { "confirm_empty_to", DT_BOOL, false, 0, NULL,
181 "Ask for a confirmation before sending an email with an empty To recipients list"
182 },
183 { "content_type", DT_STRING, IP "text/plain", 0, NULL,
184 "Default 'Content-Type' for newly composed messages"
185 },
186 { "crypt_auto_encrypt", DT_BOOL, false, 0, NULL,
187 "Automatically PGP encrypt all outgoing mail"
188 },
189 { "crypt_auto_pgp", DT_BOOL, true, 0, NULL,
190 "Allow automatic PGP functions"
191 },
192 { "crypt_auto_sign", DT_BOOL, false, 0, NULL,
193 "Automatically PGP sign all outgoing mail"
194 },
195 { "crypt_auto_smime", DT_BOOL, true, 0, NULL,
196 "Allow automatic SMIME functions"
197 },
198 { "crypt_reply_encrypt", DT_BOOL, true, 0, NULL,
199 "Encrypt replies to encrypted messages"
200 },
201 { "crypt_reply_sign", DT_BOOL, false, 0, NULL,
202 "Sign replies to signed messages"
203 },
204 { "crypt_reply_sign_encrypted", DT_BOOL, false, 0, NULL,
205 "Sign replies to encrypted messages"
206 },
207 { "dsn_notify", DT_STRING, 0, 0, NULL,
208 "Request notification for message delivery or delay"
209 },
210 { "dsn_return", DT_STRING, 0, 0, NULL,
211 "What to send as a notification of message delivery or delay"
212 },
213 { "empty_subject", DT_STRING, IP "Re: your mail", 0, NULL,
214 "Subject to use when replying to an email with none"
215 },
216 { "encode_from", DT_BOOL, false, 0, NULL,
217 "Encode 'From ' as 'quote-printable' at the beginning of lines"
218 },
219 { "fast_reply", DT_BOOL, false, 0, NULL,
220 "Don't prompt for the recipients and subject when replying/forwarding"
221 },
222 { "fcc_attach", DT_QUAD, MUTT_YES, 0, NULL,
223 "Save sent message with all their attachments"
224 },
225 { "fcc_before_send", DT_BOOL, false, 0, NULL,
226 "Save FCCs before sending the message"
227 },
228 { "fcc_clear", DT_BOOL, false, 0, NULL,
229 "Save sent messages unencrypted and unsigned"
230 },
231 { "followup_to", DT_BOOL, true, 0, NULL,
232 "Add the 'Mail-Followup-To' header is generated when sending mail"
233 },
234 { "forward_attachments", DT_QUAD, MUTT_ASKYES, 0, NULL,
235 "Forward attachments when forwarding a message"
236 },
237 // L10N: $forward_attribution_intro default format
238 { "forward_attribution_intro", DT_EXPANDO|D_L10N_STRING, IP N_("----- Forwarded message from %f -----"), IP IndexFormatDefNoPadding, NULL,
239 "Prefix message for forwarded messages"
240 },
241 // L10N: $forward_attribution_trailer default format
242 { "forward_attribution_trailer", DT_EXPANDO|D_L10N_STRING, IP N_("----- End forwarded message -----"), IP IndexFormatDefNoPadding, NULL,
243 "Suffix message for forwarded messages"
244 },
245 { "forward_decrypt", DT_BOOL, true, 0, NULL,
246 "Decrypt the message when forwarding it"
247 },
248 { "forward_edit", DT_QUAD, MUTT_YES, 0, NULL,
249 "Automatically start the editor when forwarding a message"
250 },
251 { "forward_format", DT_EXPANDO|D_NOT_EMPTY, IP "[%a: %s]", IP IndexFormatDefNoPadding, NULL,
252 "printf-like format string to control the subject when forwarding a message"
253 },
254 { "forward_references", DT_BOOL, false, 0, NULL,
255 "Set the 'In-Reply-To' and 'References' headers when forwarding a message"
256 },
257 { "greeting", DT_EXPANDO, 0, IP &GreetingFormatDef, NULL,
258 "Greeting string added to the top of all messages"
259 },
260 { "hdrs", DT_BOOL, true, 0, NULL,
261 "Add custom headers to outgoing mail"
262 },
263 { "hidden_host", DT_BOOL, false, 0, NULL,
264 "Don't use the hostname, just the domain, when generating the message id"
265 },
266 { "honor_followup_to", DT_QUAD, MUTT_YES, 0, NULL,
267 "Honour the 'Mail-Followup-To' header when group replying"
268 },
269 { "ignore_list_reply_to", DT_BOOL, false, 0, NULL,
270 "Ignore the 'Reply-To' header when using `<reply>` on a mailing list"
271 },
272 { "include", DT_QUAD, MUTT_ASKYES, 0, NULL,
273 "Include a copy of the email that's being replied to"
274 },
275 { "inews", DT_EXPANDO|D_STRING_COMMAND, 0, 0, NULL,
276 "(nntp) External command to post news articles"
277 },
278 { "me_too", DT_BOOL, false, 0, NULL,
279 "Remove the user's address from the list of recipients"
280 },
281 { "mime_forward_decode", DT_BOOL, false, 0, NULL,
282 "Decode the forwarded message before attaching it"
283 },
284 { "mime_type_query_command", DT_STRING|D_STRING_COMMAND, 0, 0, NULL,
285 "External command to determine the MIME type of an attachment"
286 },
287 { "mime_type_query_first", DT_BOOL, false, 0, NULL,
288 "Run the `$mime_type_query_command` before the mime.types lookup"
289 },
290 { "nm_record", DT_BOOL, false, 0, NULL,
291 "(notmuch) If the 'record' mailbox (sent mail) should be indexed"
292 },
293 { "pgp_reply_inline", DT_BOOL, false, 0, NULL,
294 "Reply using old-style inline PGP messages (not recommended)"
295 },
296 { "postpone_encrypt", DT_BOOL, false, 0, NULL,
297 "Self-encrypt postponed messages"
298 },
299 { "postpone_encrypt_as", DT_STRING, 0, 0, NULL,
300 "Fallback encryption key for postponed messages"
301 },
302 { "recall", DT_QUAD, MUTT_ASKYES, 0, NULL,
303 "Recall postponed mesaages when asked to compose a message"
304 },
305 { "reply_self", DT_BOOL, false, 0, NULL,
306 "Really reply to yourself, when replying to your own email"
307 },
308 { "reply_to", DT_QUAD, MUTT_ASKYES, 0, NULL,
309 "Address to use as a 'Reply-To' header"
310 },
311 { "reply_with_xorig", DT_BOOL, false, 0, NULL,
312 "Create 'From' header from 'X-Original-To' header"
313 },
314 { "resume_draft_files", DT_BOOL, false, 0, NULL,
315 "Process draft files like postponed messages"
316 },
317 { "reverse_name", DT_BOOL, false, 0, NULL,
318 "Set the 'From' from the address the email was sent to"
319 },
320 { "reverse_real_name", DT_BOOL, true, 0, NULL,
321 "Set the 'From' from the full 'To' address the email was sent to"
322 },
323 { "sendmail", DT_STRING|D_STRING_COMMAND, IP SENDMAIL " -oem -oi", 0, simple_command_validator,
324 "External command to send email"
325 },
326 { "sendmail_wait", DT_NUMBER, 0, 0, NULL,
327 "Time to wait for sendmail to finish"
328 },
329 { "sig_dashes", DT_BOOL, true, 0, NULL,
330 "Insert '-- ' before the signature"
331 },
332 { "sig_on_top", DT_BOOL, false, 0, NULL,
333 "Insert the signature before the quoted text"
334 },
335 { "signature", DT_PATH|D_PATH_FILE, IP "~/.signature", 0, NULL,
336 "File containing a signature to append to all mail"
337 },
338 { "smtp_authenticators", DT_SLIST|D_SLIST_SEP_COLON, 0, 0, smtp_auth_validator,
339 "(smtp) List of allowed authentication methods (colon-separated)"
340 },
341 { "smtp_oauth_refresh_command", DT_STRING|D_STRING_COMMAND|D_SENSITIVE, 0, 0, NULL,
342 "(smtp) External command to generate OAUTH refresh token"
343 },
344 { "smtp_pass", DT_STRING|D_SENSITIVE, 0, 0, NULL,
345 "(smtp) Password for the SMTP server"
346 },
347 { "smtp_url", DT_STRING|D_SENSITIVE, 0, 0, NULL,
348 "(smtp) Url of the SMTP server"
349 },
350 { "smtp_user", DT_STRING|D_SENSITIVE, 0, 0, NULL,
351 "(smtp) Username for the SMTP server"
352 },
353 { "use_8bit_mime", DT_BOOL, false, 0, NULL,
354 "Use 8-bit messages and ESMTP to send messages"
355 },
356 { "use_envelope_from", DT_BOOL, false, 0, NULL,
357 "Set the envelope sender of the message"
358 },
359 { "use_from", DT_BOOL, true, 0, NULL,
360 "Set the 'From' header for outgoing mail"
361 },
362 { "user_agent", DT_BOOL, false, 0, NULL,
363 "Add a 'User-Agent' header to outgoing mail"
364 },
366 "Width to wrap headers in outgoing messages"
367 },
368 { "write_bcc", DT_BOOL, false, 0, NULL,
369 "Write out the 'Bcc' field when preparing to send a mail"
370 },
371
372 { "abort_noattach_regexp", DT_SYNONYM, IP "abort_noattach_regex", IP "2021-03-21" },
373 { "askbcc", DT_SYNONYM, IP "ask_bcc", IP "2021-03-21" },
374 { "askcc", DT_SYNONYM, IP "ask_cc", IP "2021-03-21" },
375 { "ask_follow_up", DT_SYNONYM, IP "ask_followup_to", IP "2023-01-20" },
376 { "attach_keyword", DT_SYNONYM, IP "abort_noattach_regex", IP "2021-03-21" },
377 { "attribution", DT_SYNONYM, IP "attribution_intro", IP "2023-02-20" },
378 { "crypt_autoencrypt", DT_SYNONYM, IP "crypt_auto_encrypt", IP "2021-03-21" },
379 { "crypt_autopgp", DT_SYNONYM, IP "crypt_auto_pgp", IP "2021-03-21" },
380 { "crypt_autosign", DT_SYNONYM, IP "crypt_auto_sign", IP "2021-03-21" },
381 { "crypt_autosmime", DT_SYNONYM, IP "crypt_auto_smime", IP "2021-03-21" },
382 { "crypt_replyencrypt", DT_SYNONYM, IP "crypt_reply_encrypt", IP "2021-03-21" },
383 { "crypt_replysign", DT_SYNONYM, IP "crypt_reply_sign", IP "2021-03-21" },
384 { "crypt_replysignencrypted", DT_SYNONYM, IP "crypt_reply_sign_encrypted", IP "2021-03-21" },
385 { "envelope_from", DT_SYNONYM, IP "use_envelope_from", IP "2021-03-21" },
386 { "forw_decrypt", DT_SYNONYM, IP "forward_decrypt", IP "2021-03-21" },
387 { "forw_format", DT_SYNONYM, IP "forward_format", IP "2021-03-21" },
388 { "metoo", DT_SYNONYM, IP "me_too", IP "2021-03-21" },
389 { "pgp_autoencrypt", DT_SYNONYM, IP "crypt_auto_encrypt", IP "2021-03-21" },
390 { "pgp_autosign", DT_SYNONYM, IP "crypt_auto_sign", IP "2021-03-21" },
391 { "pgp_auto_traditional", DT_SYNONYM, IP "pgp_reply_inline", IP "2021-03-21" },
392 { "pgp_replyencrypt", DT_SYNONYM, IP "crypt_reply_encrypt", IP "2021-03-21" },
393 { "pgp_replyinline", DT_SYNONYM, IP "pgp_reply_inline", IP "2021-03-21" },
394 { "pgp_replysign", DT_SYNONYM, IP "crypt_reply_sign", IP "2021-03-21" },
395 { "pgp_replysignencrypted", DT_SYNONYM, IP "crypt_reply_sign_encrypted", IP "2021-03-21" },
396 { "post_indent_str", DT_SYNONYM, IP "post_indent_string", IP "2021-03-21" },
397 { "post_indent_string", DT_SYNONYM, IP "attribution_trailer", IP "2023-02-20" },
398 { "reverse_realname", DT_SYNONYM, IP "reverse_real_name", IP "2021-03-21" },
399 { "use_8bitmime", DT_SYNONYM, IP "use_8bit_mime", IP "2021-03-21" },
400
401 { "mime_subject", D_INTERNAL_DEPRECATED|DT_BOOL, 0, IP "2021-03-24" },
402 { NULL },
403 // clang-format on
404};
405
410{
412}
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition buffer.c:161
Convenience wrapper for the config headers.
bool cs_register_variables(const struct ConfigSet *cs, struct ConfigDef vars[])
Register a set of config items.
Definition set.c:289
#define CSR_ERR_INVALID
Value hasn't been set.
Definition set.h:36
#define CSR_SUCCESS
Action completed successfully.
Definition set.h:33
#define IP
Definition set.h:52
Connection Library.
@ ED_ENVELOPE
Envelope ED_ENV_ ExpandoDataEnvelope.
Definition domain.h:42
Structs that make up an email.
@ ED_ENV_REAL_NAME
Envelope.to (first)
Definition envelope.h:111
@ ED_ENV_USER_NAME
Envelope.to (first)
Definition envelope.h:122
@ ED_ENV_FIRST_NAME
Envelope.from, Envelope.to, Envelope.cc.
Definition envelope.h:101
Parse Expando string.
static int simple_command_validator(const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
Validate the "sendmail" config variable - Implements ConfigDef::validator() -.
Definition config.c:100
static int smtp_auth_validator(const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
Validate the "smtp_authenticators" config variable - Implements ConfigDef::validator() -.
Definition config.c:75
static int wrapheaders_validator(const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
Validate the "wrap_headers" config variable - Implements ConfigDef::validator() -.
Definition config.c:57
int charset_slist_validator(const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
Validate the multiple "charset" config variables - Implements ConfigDef::validator() -.
Definition charset.c:84
bool config_init_send(struct ConfigSet *cs)
Register send config variables - Implements module_init_config_t -.
Definition config.c:409
const struct ExpandoDefinition IndexFormatDef[]
Expando definitions.
Convenience wrapper for the library headers.
#define N_(a)
Definition message.h:32
#define _(a)
Definition message.h:28
static const struct ExpandoDefinition *const IndexFormatDefNoPadding
IndexFormatDefNoPadding - Index format definitions, without padding.
const struct ExpandoDefinition NntpFormatDef[]
Expando definitions.
Definition config.c:44
@ MUTT_NO
User answered 'No', or assume 'No'.
Definition quad.h:38
@ MUTT_ASKYES
Ask the user, defaulting to 'Yes'.
Definition quad.h:41
@ MUTT_YES
User answered 'Yes', or assume 'Yes'.
Definition quad.h:39
#define STAILQ_FOREACH(var, head, field)
Definition queue.h:390
bool sasl_auth_validator(const char *authenticator)
Validate an auth method against Cyrus SASL methods.
Definition sasl.c:135
static struct ConfigDef SendVars[]
Config definitions for the send library.
Definition config.c:135
static const struct ExpandoDefinition GreetingFormatDef[]
Expando definitions.
Definition config.c:123
bool smtp_auth_is_valid(const char *authenticator)
Check if string is a valid smtp authentication method.
Definition smtp.c:926
Send email to an SMTP server.
String manipulation buffer.
Definition buffer.h:36
const char * name
User-visible name.
Definition set.h:63
Container for lots of config items.
Definition set.h:248
Definition of a format string.
Definition definition.h:44
A List node for strings.
Definition list.h:37
char * data
String.
Definition list.h:38
String list.
Definition slist.h:37
struct ListHead head
List containing values.
Definition slist.h:38
size_t count
Number of values in list.
Definition slist.h:39
#define D_SLIST_SEP_COLON
Slist items are colon-separated.
Definition types.h:111
#define D_INTERNAL_DEPRECATED
Config item shouldn't be used any more.
Definition types.h:87
#define D_STRING_COMMAND
A command.
Definition types.h:98
#define D_SLIST_ALLOW_EMPTY
Slist may be empty.
Definition types.h:115
#define D_L10N_STRING
String can be localised.
Definition types.h:81
#define D_PATH_FILE
Path is a file.
Definition types.h:103
@ DT_NUMBER
a number
Definition types.h:38
@ DT_SLIST
a list of strings
Definition types.h:42
@ DT_BOOL
boolean option
Definition types.h:32
@ DT_QUAD
quad-option (no/yes/ask-no/ask-yes)
Definition types.h:40
@ DT_SYNONYM
synonym for another variable
Definition types.h:45
@ DT_STRING
a string
Definition types.h:44
@ DT_EXPANDO
an expando
Definition types.h:34
@ DT_REGEX
regular expressions
Definition types.h:41
@ DT_PATH
a path to a file/directory
Definition types.h:39
#define D_SENSITIVE
Contains sensitive value, e.g. password.
Definition types.h:80
#define D_NOT_EMPTY
Empty strings are not allowed.
Definition types.h:79
#define D_INTEGER_NOT_NEGATIVE
Negative numbers are not allowed.
Definition types.h:100