NeoMutt  2024-04-16-36-g75b6fb
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
commands.c File Reference

Functions to parse commands in a config file. More...

#include "config.h"
#include <errno.h>
#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "mutt/lib.h"
#include "address/lib.h"
#include "config/lib.h"
#include "email/lib.h"
#include "core/lib.h"
#include "alias/lib.h"
#include "gui/lib.h"
#include "mutt.h"
#include "commands.h"
#include "attach/lib.h"
#include "color/lib.h"
#include "imap/lib.h"
#include "key/lib.h"
#include "menu/lib.h"
#include "pager/lib.h"
#include "parse/lib.h"
#include "store/lib.h"
#include "alternates.h"
#include "globals.h"
#include "muttlib.h"
#include "mx.h"
#include "score.h"
#include "version.h"
#include "monitor.h"
#include <libintl.h>
+ Include dependency graph for commands.c:

Go to the source code of this file.

Macros

#define MAX_ERRS   128
 

Enumerations

enum  TriBool { TB_UNSET = -1 , TB_FALSE , TB_TRUE }
 Tri-state boolean. More...
 
enum  GroupState { GS_NONE , GS_RX , GS_ADDR }
 Type of email address group. More...
 

Functions

static bool is_function (const char *name)
 Is the argument a neomutt function?
 
int parse_grouplist (struct GroupList *gl, struct Buffer *buf, struct Buffer *s, struct Buffer *err)
 Parse a group context.
 
enum CommandResult parse_rc_line_cwd (const char *line, char *cwd, struct Buffer *err)
 Parse and run a muttrc line in a relative directory.
 
char * mutt_get_sourced_cwd (void)
 Get the current file path that is being parsed.
 
int source_rc (const char *rcfile_path, struct Buffer *err)
 Read an initialization file.
 
static enum CommandResult parse_cd (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'cd' command - Implements Command::parse() -.
 
static enum CommandResult parse_echo (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'echo' command - Implements Command::parse() -.
 
static enum CommandResult parse_finish (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'finish' command - Implements Command::parse() -.
 
static enum CommandResult parse_group (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'group' and 'ungroup' commands - Implements Command::parse() -.
 
static enum CommandResult parse_ifdef (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'ifdef' and 'ifndef' commands - Implements Command::parse() -.
 
static enum CommandResult parse_ignore (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'ignore' command - Implements Command::parse() -.
 
static enum CommandResult parse_lists (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'lists' command - Implements Command::parse() -.
 
static enum CommandResult mailbox_add (const char *folder, const char *mailbox, const char *label, enum TriBool poll, enum TriBool notify, struct Buffer *err)
 Add a new Mailbox.
 
bool mailbox_add_simple (const char *mailbox, struct Buffer *err)
 Add a new Mailbox.
 
enum CommandResult parse_mailboxes (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'mailboxes' command - Implements Command::parse() -.
 
enum CommandResult parse_my_hdr (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'my_hdr' command - Implements Command::parse() -.
 
enum CommandResult set_dump (ConfigDumpFlags flags, struct Buffer *err)
 Dump list of config variables into a file/pager.
 
static int envlist_sort (const void *a, const void *b, void *sdata)
 Compare two environment strings - Implements sort_t -.
 
static enum CommandResult parse_setenv (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'setenv' and 'unsetenv' commands - Implements Command::parse() -.
 
static enum CommandResult parse_source (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'source' command - Implements Command::parse() -.
 
static enum CommandResult parse_nospam (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'nospam' command - Implements Command::parse() -.
 
static enum CommandResult parse_spam (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'spam' command - Implements Command::parse() -.
 
static enum CommandResult parse_stailq (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse a list command - Implements Command::parse() -.
 
static enum CommandResult parse_subscribe (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'subscribe' command - Implements Command::parse() -.
 
enum CommandResult parse_subscribe_to (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'subscribe-to' command - Implements Command::parse() -.
 
static enum CommandResult parse_tag_formats (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'tag-formats' command - Implements Command::parse() -.
 
static enum CommandResult parse_tag_transforms (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'tag-transforms' command - Implements Command::parse() -.
 
static enum CommandResult parse_unignore (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unignore' command - Implements Command::parse() -.
 
static enum CommandResult parse_unlists (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unlists' command - Implements Command::parse() -.
 
static void do_unmailboxes (struct Mailbox *m)
 Remove a Mailbox from the Sidebar/notifications.
 
static void do_unmailboxes_star (void)
 Remove all Mailboxes from the Sidebar/notifications.
 
enum CommandResult parse_unmailboxes (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unmailboxes' command - Implements Command::parse() -.
 
static enum CommandResult parse_unmy_hdr (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unmy_hdr' command - Implements Command::parse() -.
 
static enum CommandResult parse_unstailq (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse an unlist command - Implements Command::parse() -.
 
static enum CommandResult parse_unsubscribe (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unsubscribe' command - Implements Command::parse() -.
 
enum CommandResult parse_unsubscribe_from (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unsubscribe-from' command - Implements Command::parse() -.
 
static enum CommandResult parse_version (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'version' command - Implements Command::parse() -.
 
void source_stack_cleanup (void)
 Free memory from the stack used for the source command.
 
void commands_init (void)
 Initialize commands array and register default commands.
 

Variables

static struct ListHead MuttrcStack = STAILQ_HEAD_INITIALIZER(MuttrcStack)
 LIFO designed to contain the list of config files that have been sourced and avoid cyclic sourcing.
 
static const struct Command MuttCommands []
 General NeoMutt Commands.
 

Detailed Description

Functions to parse commands in a config file.

Authors
  • Michael R. Elkins
  • g10 Code GmbH
  • Richard Russon
  • Aditya De Saha
  • Matthew Hughes
  • R Primus
  • Pietro Cerutti
  • Marco Sirabella
  • Dennis Schön

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file commands.c.

Macro Definition Documentation

◆ MAX_ERRS

#define MAX_ERRS   128

Definition at line 78 of file commands.c.

Enumeration Type Documentation

◆ TriBool

enum TriBool

Tri-state boolean.

Enumerator
TB_UNSET 

Value hasn't been set.

TB_FALSE 

Value is false.

TB_TRUE 

Value is true.

Definition at line 83 of file commands.c.

84{
85 TB_UNSET = -1,
86 TB_FALSE,
87 TB_TRUE,
88};
@ TB_FALSE
Value is false.
Definition: commands.c:86
@ TB_TRUE
Value is true.
Definition: commands.c:87
@ TB_UNSET
Value hasn't been set.
Definition: commands.c:85

◆ GroupState

enum GroupState

Type of email address group.

Enumerator
GS_NONE 

Group is missing an argument.

GS_RX 

Entry is a regular expression.

GS_ADDR 

Entry is an address.

Definition at line 93 of file commands.c.

94{
95 GS_NONE,
96 GS_RX,
97 GS_ADDR,
98};
@ GS_RX
Entry is a regular expression.
Definition: commands.c:96
@ GS_NONE
Group is missing an argument.
Definition: commands.c:95
@ GS_ADDR
Entry is an address.
Definition: commands.c:97

Function Documentation

◆ is_function()

static bool is_function ( const char *  name)
static

Is the argument a neomutt function?

Parameters
nameCommand name to be searched for
Return values
trueFunction found
falseFunction not found

Definition at line 106 of file commands.c.

107{
108 for (size_t i = 0; MenuNames[i].name; i++)
109 {
110 const struct MenuFuncOp *fns = km_get_table(MenuNames[i].value);
111 if (!fns)
112 continue;
113
114 for (int j = 0; fns[j].name; j++)
115 if (mutt_str_equal(name, fns[j].name))
116 return true;
117 }
118 return false;
119}
const struct MenuFuncOp * km_get_table(enum MenuType mtype)
Lookup a Menu's functions.
Definition: lib.c:528
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:654
const char * name
String value.
Definition: mapping.h:34
Mapping between a function and an operation.
Definition: lib.h:101
const char * name
Name of the function.
Definition: lib.h:102
const struct Mapping MenuNames[]
Menu name lookup table.
Definition: type.c:37
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse_grouplist()

int parse_grouplist ( struct GroupList *  gl,
struct Buffer buf,
struct Buffer s,
struct Buffer err 
)

Parse a group context.

Parameters
glGroupList to add to
bufTemporary Buffer space
sBuffer containing string to be parsed
errBuffer for error messages
Return values
0Success
-1Error

Definition at line 130 of file commands.c.

132{
133 while (mutt_istr_equal(buf->data, "-group"))
134 {
135 if (!MoreArgs(s))
136 {
137 buf_strcpy(err, _("-group: no group name"));
138 return -1;
139 }
140
142
144
145 if (!MoreArgs(s))
146 {
147 buf_strcpy(err, _("out of arguments"));
148 return -1;
149 }
150
152 }
153
154 return 0;
155}
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:394
int parse_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: extract.c:50
#define MoreArgs(buf)
Definition: extract.h:32
#define TOKEN_NO_FLAGS
No flags are set.
Definition: extract.h:46
void mutt_grouplist_add(struct GroupList *gl, struct Group *group)
Add a Group to a GroupList.
Definition: group.c:183
struct Group * mutt_pattern_group(const char *pat)
Match a pattern to a Group.
Definition: group.c:118
#define _(a)
Definition: message.h:28
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:666
char * data
Pointer to data.
Definition: buffer.h:37
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse_rc_line_cwd()

enum CommandResult parse_rc_line_cwd ( const char *  line,
char *  cwd,
struct Buffer err 
)

Parse and run a muttrc line in a relative directory.

Parameters
lineLine to be parsed
cwdFile relative where to run the line
errWhere to write error messages
Return values
CommandResultResult e.g. MUTT_CMD_SUCCESS

Definition at line 164 of file commands.c.

165{
167
168 enum CommandResult ret = parse_rc_line(line, err);
169
170 struct ListNode *np = STAILQ_FIRST(&MuttrcStack);
172 FREE(&np->data);
173 FREE(&np);
174
175 return ret;
176}
CommandResult
Error codes for command_t parse functions.
Definition: command.h:36
static struct ListHead MuttrcStack
LIFO designed to contain the list of config files that have been sourced and avoid cyclic sourcing.
Definition: commands.c:76
struct ListNode * mutt_list_insert_head(struct ListHead *h, char *s)
Insert a string at the beginning of a List.
Definition: list.c:45
#define FREE(x)
Definition: memory.h:45
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:253
#define STAILQ_REMOVE_HEAD(head, field)
Definition: queue.h:422
#define STAILQ_FIRST(head)
Definition: queue.h:350
enum CommandResult parse_rc_line(const char *line, struct Buffer *err)
Parse a line of user config.
Definition: rc.c:104
#define NONULL(x)
Definition: string2.h:37
A List node for strings.
Definition: list.h:35
char * data
String.
Definition: list.h:36
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_get_sourced_cwd()

char * mutt_get_sourced_cwd ( void  )

Get the current file path that is being parsed.

Return values
ptrFile path that is being parsed or cwd at runtime
Note
Caller is responsible for freeing returned string

Definition at line 184 of file commands.c.

185{
186 struct ListNode *np = STAILQ_FIRST(&MuttrcStack);
187 if (np && np->data)
188 return mutt_str_dup(np->data);
189
190 // stack is empty, return our own dummy file relative to cwd
191 struct Buffer *cwd = buf_pool_get();
192 mutt_path_getcwd(cwd);
193 buf_addstr(cwd, "/dummy.rc");
194 char *ret = buf_strdup(cwd);
195 buf_pool_release(&cwd);
196 return ret;
197}
size_t buf_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:225
char * buf_strdup(const struct Buffer *buf)
Copy a Buffer's string.
Definition: buffer.c:570
const char * mutt_path_getcwd(struct Buffer *cwd)
Get the current working directory.
Definition: path.c:469
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:81
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:94
String manipulation buffer.
Definition: buffer.h:36
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ source_rc()

int source_rc ( const char *  rcfile_path,
struct Buffer err 
)

Read an initialization file.

Parameters
rcfile_pathPath to initialization file
errBuffer for error messages
Return values
<0NeoMutt should pause to let the user know

Definition at line 205 of file commands.c.

206{
207 int lineno = 0, rc = 0, warnings = 0;
208 enum CommandResult line_rc;
209 struct Buffer *token = NULL, *linebuf = NULL;
210 char *line = NULL;
211 char *currentline = NULL;
212 char rcfile[PATH_MAX] = { 0 };
213 size_t linelen = 0;
214 pid_t pid;
215
216 mutt_str_copy(rcfile, rcfile_path, sizeof(rcfile));
217
218 size_t rcfilelen = mutt_str_len(rcfile);
219 if (rcfilelen == 0)
220 return -1;
221
222 bool ispipe = rcfile[rcfilelen - 1] == '|';
223
224 if (!ispipe)
225 {
226 struct ListNode *np = STAILQ_FIRST(&MuttrcStack);
227 if (!mutt_path_to_absolute(rcfile, np ? NONULL(np->data) : ""))
228 {
229 mutt_error(_("Error: Can't build path of '%s'"), rcfile_path);
230 return -1;
231 }
232
233 STAILQ_FOREACH(np, &MuttrcStack, entries)
234 {
235 if (mutt_str_equal(np->data, rcfile))
236 {
237 break;
238 }
239 }
240 if (np)
241 {
242 mutt_error(_("Error: Cyclic sourcing of configuration file '%s'"), rcfile);
243 return -1;
244 }
245
247 }
248
249 mutt_debug(LL_DEBUG2, "Reading configuration file '%s'\n", rcfile);
250
251 FILE *fp = mutt_open_read(rcfile, &pid);
252 if (!fp)
253 {
254 buf_printf(err, "%s: %s", rcfile, strerror(errno));
255 return -1;
256 }
257
258 token = buf_pool_get();
259 linebuf = buf_pool_get();
260
261 const char *const c_config_charset = cs_subset_string(NeoMutt->sub, "config_charset");
262 const char *const c_charset = cc_charset();
263 while ((line = mutt_file_read_line(line, &linelen, fp, &lineno, MUTT_RL_CONT)) != NULL)
264 {
265 const bool conv = c_config_charset && c_charset;
266 if (conv)
267 {
268 currentline = mutt_str_dup(line);
269 if (!currentline)
270 continue;
271 mutt_ch_convert_string(&currentline, c_config_charset, c_charset, MUTT_ICONV_NO_FLAGS);
272 }
273 else
274 {
275 currentline = line;
276 }
277
278 buf_strcpy(linebuf, currentline);
279
280 buf_reset(err);
281 line_rc = parse_rc_buffer(linebuf, token, err);
282 if (line_rc == MUTT_CMD_ERROR)
283 {
284 mutt_error("%s:%d: %s", rcfile, lineno, buf_string(err));
285 if (--rc < -MAX_ERRS)
286 {
287 if (conv)
288 FREE(&currentline);
289 break;
290 }
291 }
292 else if (line_rc == MUTT_CMD_WARNING)
293 {
294 /* Warning */
295 mutt_warning("%s:%d: %s", rcfile, lineno, buf_string(err));
296 warnings++;
297 }
298 else if (line_rc == MUTT_CMD_FINISH)
299 {
300 if (conv)
301 FREE(&currentline);
302 break; /* Found "finish" command */
303 }
304 else
305 {
306 if (rc < 0)
307 rc = -1;
308 }
309 if (conv)
310 FREE(&currentline);
311 }
312
313 FREE(&line);
314 mutt_file_fclose(&fp);
315 if (pid != -1)
316 filter_wait(pid);
317
318 if (rc)
319 {
320 /* the neomuttrc source keyword */
321 buf_reset(err);
322 buf_printf(err, (rc >= -MAX_ERRS) ? _("source: errors in %s") : _("source: reading aborted due to too many errors in %s"),
323 rcfile);
324 rc = -1;
325 }
326 else
327 {
328 /* Don't alias errors with warnings */
329 if (warnings > 0)
330 {
331 buf_printf(err, ngettext("source: %d warning in %s", "source: %d warnings in %s", warnings),
332 warnings, rcfile);
333 rc = -2;
334 }
335 }
336
337 if (!ispipe && !STAILQ_EMPTY(&MuttrcStack))
338 {
339 struct ListNode *np = STAILQ_FIRST(&MuttrcStack);
341 FREE(&np->data);
342 FREE(&np);
343 }
344
345 buf_pool_release(&token);
346 buf_pool_release(&linebuf);
347 return rc;
348}
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:75
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:96
@ MUTT_CMD_ERROR
Error: Can't help the user.
Definition: command.h:37
@ MUTT_CMD_WARNING
Warning: Help given to the user.
Definition: command.h:38
@ MUTT_CMD_FINISH
Finish: Stop processing this file.
Definition: command.h:40
#define MAX_ERRS
Definition: commands.c:78
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:292
const char * cc_charset(void)
Get the cached value of $charset.
Definition: config_cache.c:116
char * mutt_file_read_line(char *line, size_t *size, FILE *fp, int *line_num, ReadLineFlags flags)
Read a line from a file.
Definition: file.c:805
#define MUTT_RL_CONT
-continuation
Definition: file.h:41
#define mutt_file_fclose(FP)
Definition: file.h:147
int filter_wait(pid_t pid)
Wait for the exit of a process and return its status.
Definition: filter.c:220
#define mutt_warning(...)
Definition: logging2.h:90
#define mutt_error(...)
Definition: logging2.h:92
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
@ LL_DEBUG2
Log at debug level 2.
Definition: logging2.h:44
int mutt_ch_convert_string(char **ps, const char *from, const char *to, uint8_t flags)
Convert a string between encodings.
Definition: charset.c:831
#define MUTT_ICONV_NO_FLAGS
No flags are set.
Definition: charset.h:72
bool mutt_path_to_absolute(char *path, const char *reference)
Convert relative filepath to an absolute path.
Definition: path.c:333
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:490
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:575
#define PATH_MAX
Definition: mutt.h:42
FILE * mutt_open_read(const char *path, pid_t *thepid)
Run a command to read from.
Definition: muttlib.c:736
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
#define STAILQ_EMPTY(head)
Definition: queue.h:348
enum CommandResult parse_rc_buffer(struct Buffer *line, struct Buffer *token, struct Buffer *err)
Parse a line of user config.
Definition: rc.c:46
Container for Accounts, Notifications.
Definition: neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:45
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mailbox_add()

static enum CommandResult mailbox_add ( const char *  folder,
const char *  mailbox,
const char *  label,
enum TriBool  poll,
enum TriBool  notify,
struct Buffer err 
)
static

Add a new Mailbox.

Parameters
folderPath to use for '+' abbreviations
mailboxMailbox to add
labelDescriptive label
pollEnable mailbox polling?
notifyEnable mailbox notification?
errBuffer for error messages
Return values
CommandResultResult e.g. MUTT_CMD_SUCCESS

Definition at line 622 of file commands.c.

625{
626 mutt_debug(LL_DEBUG1, "Adding mailbox: '%s' label '%s', poll %s, notify %s\n",
627 mailbox, label ? label : "[NONE]",
628 (poll == TB_UNSET) ? "[UNSPECIFIED]" :
629 (poll == TB_TRUE) ? "true" :
630 "false",
631 (notify == TB_UNSET) ? "[UNSPECIFIED]" :
632 (notify == TB_TRUE) ? "true" :
633 "false");
634 struct Mailbox *m = mailbox_new();
635
636 buf_strcpy(&m->pathbuf, mailbox);
637 /* int rc = */ mx_path_canon2(m, folder);
638
639 if (m->type <= MUTT_UNKNOWN)
640 {
641 buf_printf(err, "Unknown Mailbox: %s", m->realpath);
642 mailbox_free(&m);
643 return MUTT_CMD_ERROR;
644 }
645
646 bool new_account = false;
647 struct Account *a = mx_ac_find(m);
648 if (!a)
649 {
650 a = account_new(NULL, NeoMutt->sub);
651 a->type = m->type;
652 new_account = true;
653 }
654
655 if (!new_account)
656 {
657 struct Mailbox *m_old = mx_mbox_find(a, m->realpath);
658 if (m_old)
659 {
660 if (!m_old->visible)
661 {
662 m_old->visible = true;
663 m_old->gen = mailbox_gen();
664 }
665
666 if (label)
667 mutt_str_replace(&m_old->name, label);
668
669 if (notify != TB_UNSET)
670 m_old->notify_user = notify;
671
672 if (poll != TB_UNSET)
673 m_old->poll_new_mail = poll;
674
675 struct EventMailbox ev_m = { m_old };
677
678 mailbox_free(&m);
679 return MUTT_CMD_SUCCESS;
680 }
681 }
682
683 if (label)
684 m->name = mutt_str_dup(label);
685
686 if (notify != TB_UNSET)
687 m->notify_user = notify;
688
689 if (poll != TB_UNSET)
690 m->poll_new_mail = poll;
691
692 if (!mx_ac_add(a, m))
693 {
694 mailbox_free(&m);
695 if (new_account)
696 {
697 cs_subset_free(&a->sub);
698 FREE(&a->name);
699 notify_free(&a->notify);
700 FREE(&a);
701 }
702 return MUTT_CMD_SUCCESS;
703 }
704
705 if (new_account)
706 {
708 }
709
710 // this is finally a visible mailbox in the sidebar and mailboxes list
711 m->visible = true;
712
713#ifdef USE_INOTIFY
715#endif
716
717 return MUTT_CMD_SUCCESS;
718}
@ MUTT_CMD_SUCCESS
Success: Command worked.
Definition: command.h:39
struct Account * account_new(const char *name, struct ConfigSubset *sub)
Create a new Account.
Definition: account.c:44
int mailbox_gen(void)
Get the next generation number.
Definition: mailbox.c:59
struct Mailbox * mailbox_new(void)
Create a new Mailbox.
Definition: mailbox.c:69
void mailbox_free(struct Mailbox **ptr)
Free a Mailbox.
Definition: mailbox.c:90
@ NT_MAILBOX_CHANGE
Mailbox has been changed.
Definition: mailbox.h:185
@ MUTT_UNKNOWN
Mailbox wasn't recognised.
Definition: mailbox.h:44
@ LL_DEBUG1
Log at debug level 1.
Definition: logging2.h:43
int mutt_monitor_add(struct Mailbox *m)
Add a watch for a mailbox.
Definition: monitor.c:483
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:173
void notify_free(struct Notify **ptr)
Free a notification handler.
Definition: notify.c:75
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:274
struct Mailbox * mx_mbox_find(struct Account *a, const char *path)
Find a Mailbox on an Account.
Definition: mx.c:1541
bool mx_ac_add(struct Account *a, struct Mailbox *m)
Add a Mailbox to an Account - Wrapper for MxOps::ac_add()
Definition: mx.c:1721
struct Account * mx_ac_find(struct Mailbox *m)
Find the Account owning a Mailbox.
Definition: mx.c:1517
int mx_path_canon2(struct Mailbox *m, const char *folder)
Canonicalise the path to realpath.
Definition: mx.c:1469
bool neomutt_account_add(struct NeoMutt *n, struct Account *a)
Add an Account to the global list.
Definition: neomutt.c:105
@ NT_MAILBOX
Mailbox has changed, NotifyMailbox, EventMailbox.
Definition: notify_type.h:49
A group of associated Mailboxes.
Definition: account.h:36
enum MailboxType type
Type of Mailboxes this Account contains.
Definition: account.h:37
char * name
Name of Account.
Definition: account.h:38
struct Notify * notify
Notifications: NotifyAccount, EventAccount.
Definition: account.h:41
struct ConfigSubset * sub
Inherited config items.
Definition: account.h:39
An Event that happened to a Mailbox.
Definition: mailbox.h:199
A mailbox.
Definition: mailbox.h:79
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition: mailbox.h:81
enum MailboxType type
Mailbox type.
Definition: mailbox.h:102
bool poll_new_mail
Check for new mail.
Definition: mailbox.h:115
char * name
A short name for the Mailbox.
Definition: mailbox.h:82
struct Notify * notify
Notifications: NotifyMailbox, EventMailbox.
Definition: mailbox.h:145
bool notify_user
Notify the user of new mail.
Definition: mailbox.h:113
struct Buffer pathbuf
Path of the Mailbox.
Definition: mailbox.h:80
bool visible
True if a result of "mailboxes".
Definition: mailbox.h:130
int gen
Generation number, for sorting.
Definition: mailbox.h:147
void cs_subset_free(struct ConfigSubset **ptr)
Free a Config Subset.
Definition: subset.c:108
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mailbox_add_simple()

bool mailbox_add_simple ( const char *  mailbox,
struct Buffer err 
)

Add a new Mailbox.

Parameters
mailboxMailbox to add
errBuffer for error messages
Return values
trueSuccess

Definition at line 726 of file commands.c.

727{
728 enum CommandResult rc = mailbox_add("", mailbox, NULL, TB_UNSET, TB_UNSET, err);
729
730 return (rc == MUTT_CMD_SUCCESS);
731}
static enum CommandResult mailbox_add(const char *folder, const char *mailbox, const char *label, enum TriBool poll, enum TriBool notify, struct Buffer *err)
Add a new Mailbox.
Definition: commands.c:622
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ set_dump()

enum CommandResult set_dump ( ConfigDumpFlags  flags,
struct Buffer err 
)

Dump list of config variables into a file/pager.

Parameters
flagswhat configs to dump: see ConfigDumpFlags
errbuffer for error message
Returns
num See CommandResult

FIXME: Move me into parse/set.c. Note: this function currently depends on pager, which is the reason it is not included in the parse library.

Definition at line 873 of file commands.c.

874{
875 struct Buffer *tempfile = buf_pool_get();
876 buf_mktemp(tempfile);
877
878 FILE *fp_out = mutt_file_fopen(buf_string(tempfile), "w");
879 if (!fp_out)
880 {
881 // L10N: '%s' is the file name of the temporary file
882 buf_printf(err, _("Could not create temporary file %s"), buf_string(tempfile));
883 buf_pool_release(&tempfile);
884 return MUTT_CMD_ERROR;
885 }
886
887 dump_config(NeoMutt->sub->cs, flags, fp_out);
888
889 mutt_file_fclose(&fp_out);
890
891 struct PagerData pdata = { 0 };
892 struct PagerView pview = { &pdata };
893
894 pdata.fname = buf_string(tempfile);
895
896 pview.banner = "set";
898 pview.mode = PAGER_MODE_OTHER;
899
900 mutt_do_pager(&pview, NULL);
901 buf_pool_release(&tempfile);
902
903 return MUTT_CMD_SUCCESS;
904}
bool dump_config(struct ConfigSet *cs, ConfigDumpFlags flags, FILE *fp)
Write all the config to a file.
Definition: dump.c:167
int mutt_do_pager(struct PagerView *pview, struct Email *e)
Display some page-able text to the user (help or attachment)
Definition: do_pager.c:123
#define mutt_file_fopen(PATH, MODE)
Definition: file.h:146
#define MUTT_PAGER_NO_FLAGS
No flags are set.
Definition: lib.h:60
@ PAGER_MODE_OTHER
Pager is invoked via 3rd path. Non-email content is likely to be shown.
Definition: lib.h:142
struct ConfigSet * cs
Parent ConfigSet.
Definition: subset.h:51
Data to be displayed by PagerView.
Definition: lib.h:161
const char * fname
Name of the file to read.
Definition: lib.h:165
Paged view into some data.
Definition: lib.h:172
struct PagerData * pdata
Data that pager displays. NOTNULL.
Definition: lib.h:173
enum PagerMode mode
Pager mode.
Definition: lib.h:174
PagerFlags flags
Additional settings to tweak pager's function.
Definition: lib.h:175
const char * banner
Title to display in status bar.
Definition: lib.h:176
#define buf_mktemp(buf)
Definition: tmp.h:33
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ do_unmailboxes()

static void do_unmailboxes ( struct Mailbox m)
static

Remove a Mailbox from the Sidebar/notifications.

Parameters
mMailbox to unmailboxes

Definition at line 1400 of file commands.c.

1401{
1402#ifdef USE_INOTIFY
1403 if (m->poll_new_mail)
1405#endif
1406 m->visible = false;
1407 m->gen = -1;
1408 if (m->opened)
1409 {
1410 struct EventMailbox ev_m = { NULL };
1411 mutt_debug(LL_NOTIFY, "NT_MAILBOX_CHANGE: NULL\n");
1413 }
1414 else
1415 {
1417 mailbox_free(&m);
1418 }
1419}
bool account_mailbox_remove(struct Account *a, struct Mailbox *m)
Remove a Mailbox from an Account.
Definition: account.c:98
@ LL_NOTIFY
Log of notifications.
Definition: logging2.h:48
int mutt_monitor_remove(struct Mailbox *m)
Remove a watch for a mailbox.
Definition: monitor.c:527
struct Account * account
Account that owns this Mailbox.
Definition: mailbox.h:127
int opened
Number of times mailbox is opened.
Definition: mailbox.h:128
struct Notify * notify
Notifications handler.
Definition: neomutt.h:42
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ do_unmailboxes_star()

static void do_unmailboxes_star ( void  )
static

Remove all Mailboxes from the Sidebar/notifications.

Definition at line 1424 of file commands.c.

1425{
1426 struct MailboxList ml = STAILQ_HEAD_INITIALIZER(ml);
1428 struct MailboxNode *np = NULL;
1429 struct MailboxNode *nptmp = NULL;
1430 STAILQ_FOREACH_SAFE(np, &ml, entries, nptmp)
1431 {
1433 }
1435}
static void do_unmailboxes(struct Mailbox *m)
Remove a Mailbox from the Sidebar/notifications.
Definition: commands.c:1400
@ MUTT_MAILBOX_ANY
Match any Mailbox type.
Definition: mailbox.h:42
void neomutt_mailboxlist_clear(struct MailboxList *ml)
Free a Mailbox List.
Definition: neomutt.c:163
size_t neomutt_mailboxlist_get_all(struct MailboxList *head, struct NeoMutt *n, enum MailboxType type)
Get a List of all Mailboxes.
Definition: neomutt.c:186
#define STAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:324
#define STAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:362
List of Mailboxes.
Definition: mailbox.h:166
struct Mailbox * mailbox
Mailbox in the list.
Definition: mailbox.h:167
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ source_stack_cleanup()

void source_stack_cleanup ( void  )

Free memory from the stack used for the source command.

Definition at line 1647 of file commands.c.

1648{
1650}
void mutt_list_free(struct ListHead *h)
Free a List AND its strings.
Definition: list.c:122
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ commands_init()

void commands_init ( void  )

Initialize commands array and register default commands.

Definition at line 1723 of file commands.c.

1724{
1726}
static const struct Command MuttCommands[]
General NeoMutt Commands.
Definition: commands.c:1655
void commands_register(const struct Command *cmds, const size_t num_cmds)
Add commands to Commands array.
Definition: command.c:53
#define mutt_array_size(x)
Definition: memory.h:38
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ MuttrcStack

struct ListHead MuttrcStack = STAILQ_HEAD_INITIALIZER(MuttrcStack)
static

LIFO designed to contain the list of config files that have been sourced and avoid cyclic sourcing.

Definition at line 76 of file commands.c.

◆ MuttCommands

const struct Command MuttCommands[]
static

General NeoMutt Commands.

Definition at line 1655 of file commands.c.