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 "lib.h"
37 
41 static int wrapheaders_validator(const struct ConfigSet *cs, const struct ConfigDef *cdef,
42  intptr_t value, struct Buffer *err)
43 {
44  const int min_length = 78; // Recommendations from RFC5233
45  const int max_length = 998;
46 
47  if ((value >= min_length) && (value <= max_length))
48  return CSR_SUCCESS;
49 
50  // L10N: This applies to the "$wrap_headers" config variable.
51  mutt_buffer_printf(err, _("Option %s must be between %d and %d inclusive"),
52  cdef->name, min_length, max_length);
53  return CSR_ERR_INVALID;
54 }
55 
59 static int smtp_auth_validator(const struct ConfigSet *cs, const struct ConfigDef *cdef,
60  intptr_t value, struct Buffer *err)
61 {
62  const struct Slist *smtp_auth_methods = (const struct Slist *) value;
63  if (!smtp_auth_methods || (smtp_auth_methods->count == 0))
64  return CSR_SUCCESS;
65 
66  struct ListNode *np = NULL;
67  STAILQ_FOREACH(np, &smtp_auth_methods->head, entries)
68  {
69  if (smtp_auth_is_valid(np->data))
70  continue;
71 #ifdef USE_SASL
72  if (sasl_auth_validator(np->data))
73  continue;
74 #endif
75  mutt_buffer_printf(err, _("Option %s: %s is not a valid authenticator"),
76  cdef->name, np->data);
77  return CSR_ERR_INVALID;
78  }
79 
80  return CSR_SUCCESS;
81 }
82 
83 static struct ConfigDef SendVars[] = {
84  // clang-format off
85  { "abort_noattach", DT_QUAD, MUTT_NO, 0, NULL,
86  "Abort sending the email if attachments are missing"
87  },
88  { "abort_noattach_regex", DT_REGEX, IP "\\<(attach|attached|attachments?)\\>", 0, NULL,
89  "Regex to match text indicating attachments are expected"
90  },
91  { "abort_nosubject", DT_QUAD, MUTT_ASKYES, 0, NULL,
92  "Abort creating the email if subject is missing"
93  },
94  { "abort_unmodified", DT_QUAD, MUTT_YES, 0, NULL,
95  "Abort the sending if the message hasn't been edited"
96  },
97  { "allow_8bit", DT_BOOL, true, 0, NULL,
98  "Allow 8-bit messages, don't use quoted-printable or base64"
99  },
100  { "ask_follow_up", DT_BOOL, false, 0, NULL,
101  "(nntp) Ask the user for follow-up groups before editing"
102  },
103 #ifdef USE_NNTP
104  { "ask_x_comment_to", DT_BOOL, false, 0, NULL,
105  "(nntp) Ask the user for the 'X-Comment-To' field before editing"
106  },
107 #endif
108  { "attach_charset", DT_STRING, 0, 0, charset_validator,
109  "When attaching files, use one of these character sets"
110  },
111  { "bounce_delivered", DT_BOOL, true, 0, NULL,
112  "Add 'Delivered-To' to bounced messages"
113  },
114  { "content_type", DT_STRING, IP "text/plain", 0, NULL,
115  "Default 'Content-Type' for newly composed messages"
116  },
117  { "crypt_auto_encrypt", DT_BOOL, false, 0, NULL,
118  "Automatically PGP encrypt all outgoing mail"
119  },
120  { "crypt_auto_pgp", DT_BOOL, true, 0, NULL,
121  "Allow automatic PGP functions"
122  },
123  { "crypt_auto_sign", DT_BOOL, false, 0, NULL,
124  "Automatically PGP sign all outgoing mail"
125  },
126  { "crypt_auto_smime", DT_BOOL, true, 0, NULL,
127  "Allow automatic SMIME functions"
128  },
129  { "crypt_reply_encrypt", DT_BOOL, true, 0, NULL,
130  "Encrypt replies to encrypted messages"
131  },
132  { "crypt_reply_sign", DT_BOOL, false, 0, NULL,
133  "Sign replies to signed messages"
134  },
135  { "crypt_reply_sign_encrypted", DT_BOOL, false, 0, NULL,
136  "Sign replies to encrypted messages"
137  },
138  { "dsn_notify", DT_STRING, 0, 0, NULL,
139  "Request notification for message delivery or delay"
140  },
141  { "dsn_return", DT_STRING, 0, 0, NULL,
142  "What to send as a notification of message delivery or delay"
143  },
144  { "empty_subject", DT_STRING, IP "Re: your mail", 0, NULL,
145  "Subject to use when replying to an email with none"
146  },
147  { "encode_from", DT_BOOL, false, 0, NULL,
148  "Encode 'From ' as 'quote-printable' at the beginning of lines"
149  },
150  { "fast_reply", DT_BOOL, false, 0, NULL,
151  "Don't prompt for the recipients and subject when replying/forwarding"
152  },
153  { "fcc_attach", DT_QUAD, MUTT_YES, 0, NULL,
154  "Save send message with all their attachments"
155  },
156  { "fcc_before_send", DT_BOOL, false, 0, NULL,
157  "Save FCCs before sending the message"
158  },
159  { "fcc_clear", DT_BOOL, false, 0, NULL,
160  "Save sent messages unencrypted and unsigned"
161  },
162  { "followup_to", DT_BOOL, true, 0, NULL,
163  "Add the 'Mail-Followup-To' header is generated when sending mail"
164  },
165  { "forward_attribution_intro", DT_STRING, IP "----- Forwarded message from %f -----", 0, NULL,
166  "Prefix message for forwarded messages"
167  },
168  { "forward_attribution_trailer", DT_STRING, IP "----- End forwarded message -----", 0, NULL,
169  "Suffix message for forwarded messages"
170  },
171  { "forward_decrypt", DT_BOOL, true, 0, NULL,
172  "Decrypt the message when forwarding it"
173  },
174  { "forward_edit", DT_QUAD, MUTT_YES, 0, NULL,
175  "Automatically start the editor when forwarding a message"
176  },
177  { "forward_format", DT_STRING|DT_NOT_EMPTY, IP "[%a: %s]", 0, NULL,
178  "printf-like format string to control the subject when forwarding a message"
179  },
180  { "forward_references", DT_BOOL, false, 0, NULL,
181  "Set the 'In-Reply-To' and 'References' headers when forwarding a message"
182  },
183  { "hdrs", DT_BOOL, true, 0, NULL,
184  "Add custom headers to outgoing mail"
185  },
186  { "hidden_host", DT_BOOL, false, 0, NULL,
187  "Don't use the hostname, just the domain, when generating the message id"
188  },
189  { "honor_followup_to", DT_QUAD, MUTT_YES, 0, NULL,
190  "Honour the 'Mail-Followup-To' header when group replying"
191  },
192  { "ignore_list_reply_to", DT_BOOL, false, 0, NULL,
193  "Ignore the 'Reply-To' header when using `<reply>` on a mailing list"
194  },
195  { "include", DT_QUAD, MUTT_ASKYES, 0, NULL,
196  "Include a copy of the email that's being replied to"
197  },
198 #ifdef USE_NNTP
199  { "inews", DT_STRING|DT_COMMAND, 0, 0, NULL,
200  "(nntp) External command to post news articles"
201  },
202 #endif
203  { "me_too", DT_BOOL, false, 0, NULL,
204  "Remove the user's address from the list of recipients"
205  },
206  { "mime_forward_decode", DT_BOOL, false, 0, NULL,
207  "Decode the forwarded message before attaching it"
208  },
209  { "mime_type_query_command", DT_STRING|DT_COMMAND, 0, 0, NULL,
210  "External command to determine the MIME type of an attachment"
211  },
212  { "mime_type_query_first", DT_BOOL, false, 0, NULL,
213  "Run the `$mime_type_query_command` before the mime.types lookup"
214  },
215  { "nm_record", DT_BOOL, false, 0, NULL,
216  "(notmuch) If the 'record' mailbox (sent mail) should be indexed"
217  },
218  { "pgp_reply_inline", DT_BOOL, false, 0, NULL,
219  "Reply using old-style inline PGP messages (not recommended)"
220  },
221  { "post_indent_string", DT_STRING, 0, 0, NULL,
222  "Suffix message to add after reply text"
223  },
224  { "postpone_encrypt", DT_BOOL, false, 0, NULL,
225  "Self-encrypt postponed messages"
226  },
227  { "postpone_encrypt_as", DT_STRING, 0, 0, NULL,
228  "Fallback encryption key for postponed messages"
229  },
230  { "recall", DT_QUAD, MUTT_ASKYES, 0, NULL,
231  "Recall postponed mesaages when asked to compose a message"
232  },
233  { "reply_self", DT_BOOL, false, 0, NULL,
234  "Really reply to yourself, when replying to your own email"
235  },
236  { "reply_to", DT_QUAD, MUTT_ASKYES, 0, NULL,
237  "Address to use as a 'Reply-To' header"
238  },
239  { "reply_with_xorig", DT_BOOL, false, 0, NULL,
240  "Create 'From' header from 'X-Original-To' header"
241  },
242  { "reverse_name", DT_BOOL|R_INDEX|R_PAGER, false, 0, NULL,
243  "Set the 'From' from the address the email was sent to"
244  },
245  { "reverse_real_name", DT_BOOL|R_INDEX|R_PAGER, true, 0, NULL,
246  "Set the 'From' from the full 'To' address the email was sent to"
247  },
248  { "sendmail", DT_STRING|DT_COMMAND, IP SENDMAIL " -oem -oi", 0, NULL,
249  "External command to send email"
250  },
251  { "sendmail_wait", DT_NUMBER, 0, 0, NULL,
252  "Time to wait for sendmail to finish"
253  },
254  { "sig_dashes", DT_BOOL, true, 0, NULL,
255  "Insert '-- ' before the signature"
256  },
257  { "sig_on_top", DT_BOOL, false, 0, NULL,
258  "Insert the signature before the quoted text"
259  },
260  { "signature", DT_PATH|DT_PATH_FILE, IP "~/.signature", 0, NULL,
261  "File containing a signature to append to all mail"
262  },
263 #ifdef USE_SMTP
264  { "smtp_authenticators", DT_SLIST|SLIST_SEP_COLON, 0, 0, smtp_auth_validator,
265  "(smtp) List of allowed authentication methods (colon-separated)"
266  },
267  { "smtp_oauth_refresh_command", DT_STRING|DT_COMMAND|DT_SENSITIVE, 0, 0, NULL,
268  "(smtp) External command to generate OAUTH refresh token"
269  },
270  { "smtp_pass", DT_STRING|DT_SENSITIVE, 0, 0, NULL,
271  "(smtp) Password for the SMTP server"
272  },
273  { "smtp_user", DT_STRING|DT_SENSITIVE, 0, 0, NULL,
274  "(smtp) Username for the SMTP server"
275  },
276  { "smtp_url", DT_STRING|DT_SENSITIVE, 0, 0, NULL,
277  "(smtp) Url of the SMTP server"
278  },
279 #endif
280  { "use_8bit_mime", DT_BOOL, false, 0, NULL,
281  "Use 8-bit messages and ESMTP to send messages"
282  },
283  { "use_envelope_from", DT_BOOL, false, 0, NULL,
284  "Set the envelope sender of the message"
285  },
286  { "use_from", DT_BOOL, true, 0, NULL,
287  "Set the 'From' header for outgoing mail"
288  },
289  { "user_agent", DT_BOOL, false, 0, NULL,
290  "Add a 'User-Agent' head to outgoing mail"
291  },
292  { "wrap_headers", DT_NUMBER|DT_NOT_NEGATIVE|R_PAGER, 78, 0, wrapheaders_validator,
293  "Width to wrap headers in outgoing messages"
294  },
295 
296  { "abort_noattach_regexp", DT_SYNONYM, IP "abort_noattach_regex", },
297  { "attach_keyword", DT_SYNONYM, IP "abort_noattach_regex", },
298  { "crypt_autoencrypt", DT_SYNONYM, IP "crypt_auto_encrypt", },
299  { "crypt_autopgp", DT_SYNONYM, IP "crypt_auto_pgp", },
300  { "crypt_autosign", DT_SYNONYM, IP "crypt_auto_sign", },
301  { "crypt_autosmime", DT_SYNONYM, IP "crypt_auto_smime", },
302  { "crypt_replyencrypt", DT_SYNONYM, IP "crypt_reply_encrypt", },
303  { "crypt_replysign", DT_SYNONYM, IP "crypt_reply_sign", },
304  { "crypt_replysignencrypted", DT_SYNONYM, IP "crypt_reply_sign_encrypted", },
305  { "envelope_from", DT_SYNONYM, IP "use_envelope_from", },
306  { "forw_decrypt", DT_SYNONYM, IP "forward_decrypt", },
307  { "forw_format", DT_SYNONYM, IP "forward_format", },
308  { "metoo", DT_SYNONYM, IP "me_too", },
309  { "pgp_auto_traditional", DT_SYNONYM, IP "pgp_reply_inline", },
310  { "pgp_autoencrypt", DT_SYNONYM, IP "crypt_auto_encrypt", },
311  { "pgp_autosign", DT_SYNONYM, IP "crypt_auto_sign", },
312  { "pgp_replyencrypt", DT_SYNONYM, IP "crypt_reply_encrypt", },
313  { "pgp_replyinline", DT_SYNONYM, IP "pgp_reply_inline", },
314  { "pgp_replysign", DT_SYNONYM, IP "crypt_reply_sign", },
315  { "pgp_replysignencrypted", DT_SYNONYM, IP "crypt_reply_sign_encrypted", },
316  { "post_indent_str", DT_SYNONYM, IP "post_indent_string", },
317  { "reverse_realname", DT_SYNONYM, IP "reverse_real_name", },
318  { "use_8bitmime", DT_SYNONYM, IP "use_8bit_mime", },
319 
320 #ifdef USE_NNTP
321  { "mime_subject", DT_DEPRECATED|DT_BOOL, true },
322 #endif
323 
324  { NULL },
325  // clang-format on
326 };
327 
331 bool config_init_send(struct ConfigSet *cs)
332 {
333  return cs_register_variables(cs, SendVars, 0);
334 }
#define CSR_SUCCESS
Action completed successfully.
Definition: set.h:35
#define R_PAGER
Redraw the pager menu.
Definition: types.h:66
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 config_init_send(struct ConfigSet *cs)
Register send config variables - Implements module_init_config_t -.
Definition: config.c:331
#define DT_REGEX
regular expressions
Definition: types.h:38
String manipulation buffer.
Definition: buffer.h:33
static int wrapheaders_validator(const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
Validate the "wrap_headers" config variable - Implements ConfigDef::validator() -.
Definition: config.c:41
#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_QUAD
quad-option (no/yes/ask-no/ask-yes)
Definition: types.h:37
#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
#define DT_PATH_FILE
Path is a file.
Definition: types.h:54
size_t count
Definition: slist.h:49
int charset_validator(const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
Validate the "charset" config variable - Implements ConfigDef::validator() -.
Definition: charset.c:39
#define DT_STRING
a string
Definition: types.h:41
#define DT_PATH
a path to a file/directory
Definition: types.h:36
#define DT_DEPRECATED
Config item shouldn&#39;t be used any more.
Definition: types.h:77
bool smtp_auth_is_valid(const char *authenticator)
Check if string is a valid smtp authentication method.
Definition: smtp.c:719
#define DT_COMMAND
A command.
Definition: types.h:50
Ask the user, defaulting to &#39;Yes&#39;.
Definition: quad.h:41
#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
Connection Library.
User answered &#39;No&#39;, or assume &#39;No&#39;.
Definition: quad.h:38
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
User answered &#39;Yes&#39;, or assume &#39;Yes&#39;.
Definition: quad.h:39
#define R_INDEX
Redraw the index menu (MENU_MAIN)
Definition: types.h:65
static int smtp_auth_validator(const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
Validate the "smtp_authenticators" config variable - Implements ConfigDef::validator() -...
Definition: config.c:59