NeoMutt  2025-12-11-435-g4ac674
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
mailboxes.h File Reference

Parse Mailboxes Commands. More...

#include <stdbool.h>
#include "mutt/lib.h"
#include "core/lib.h"
+ Include dependency graph for mailboxes.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ParseMailbox
 Parsed data for a single mailbox. More...
 

Enumerations

enum  TriBool { TB_UNSET = -1 , TB_FALSE , TB_TRUE }
 Tri-state boolean. More...
 

Functions

 ARRAY_HEAD (ParseMailboxArray, struct ParseMailbox)
 
void parse_mailbox_free (struct ParseMailbox *pm)
 Free a ParseMailbox structure.
 
void parse_mailbox_array_free (struct ParseMailboxArray *pma)
 Free a ParseMailboxArray.
 
bool parse_mailboxes_args (const struct Command *cmd, struct Buffer *line, struct Buffer *err, struct ParseMailboxArray *args)
 Parse the 'mailboxes' and 'named-mailboxes' commands.
 
enum CommandResult parse_mailboxes_exec (const struct Command *cmd, struct ParseMailboxArray *args, struct Buffer *err)
 Execute the 'mailboxes' or 'named-mailboxes' command.
 
enum CommandResult parse_mailboxes (const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
 Parse the 'mailboxes' command - Implements Command::parse() -.
 
enum CommandResult parse_unmailboxes (const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
 Parse the 'unmailboxes' command - Implements Command::parse() -.
 
bool mailbox_add_simple (const char *mailbox, struct Buffer *err)
 Add a new Mailbox.
 
bool mailbox_remove_simple (const char *mailbox)
 Remove a Mailbox.
 

Detailed Description

Parse Mailboxes Commands.

Authors
  • Richard Russon

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 mailboxes.h.

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 36 of file mailboxes.h.

37{
38 TB_UNSET = -1,
39 TB_FALSE,
40 TB_TRUE,
41};
@ TB_FALSE
Value is false.
Definition mailboxes.h:39
@ TB_TRUE
Value is true.
Definition mailboxes.h:40
@ TB_UNSET
Value hasn't been set.
Definition mailboxes.h:38

Function Documentation

◆ ARRAY_HEAD()

ARRAY_HEAD ( ParseMailboxArray ,
struct ParseMailbox  )

◆ parse_mailbox_free()

void parse_mailbox_free ( struct ParseMailbox * pm)

Free a ParseMailbox structure.

Parameters
pmParseMailbox to free

Definition at line 168 of file mailboxes.c.

169{
170 if (!pm)
171 return;
172
173 FREE(&pm->path);
174 FREE(&pm->label);
175}
#define FREE(x)
Free memory and set the pointer to NULL.
Definition memory.h:68
char * label
Descriptive label (strdup'd, may be NULL)
Definition mailboxes.h:49
char * path
Mailbox path.
Definition mailboxes.h:48
+ Here is the caller graph for this function:

◆ parse_mailbox_array_free()

void parse_mailbox_array_free ( struct ParseMailboxArray * pma)

Free a ParseMailboxArray.

Parameters
pmaParseMailboxArray to free

Definition at line 181 of file mailboxes.c.

182{
183 if (!pma)
184 return;
185
186 struct ParseMailbox *pm = NULL;
187 ARRAY_FOREACH(pm, pma)
188 {
190 }
191 ARRAY_FREE(pma);
192}
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition array.h:223
#define ARRAY_FREE(head)
Release all memory.
Definition array.h:209
void parse_mailbox_free(struct ParseMailbox *pm)
Free a ParseMailbox structure.
Definition mailboxes.c:168
Parsed data for a single mailbox.
Definition mailboxes.h:47
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse_mailboxes_args()

bool parse_mailboxes_args ( const struct Command * cmd,
struct Buffer * line,
struct Buffer * err,
struct ParseMailboxArray * args )

Parse the 'mailboxes' and 'named-mailboxes' commands.

Parameters
[in]cmdCommand being parsed
[in]lineText to parse
[out]errBuffer for error messages
[out]argsParsed args
Return values
trueSuccess

Parse:

  • mailboxes [[ -label <label> ] | -nolabel ] [ -notify | -nonotify ] [ -poll | -nopoll ] <mailbox> [ ... ]
  • named-mailboxes [ -notify | -nonotify ] [ -poll | -nopoll ] <mailbox> [ ... ]

Definition at line 206 of file mailboxes.c.

208{
209 if (!cmd || !line || !err || !args)
210 return false;
211
212 if (!MoreArgs(line))
213 {
214 buf_printf(err, _("%s: too few arguments"), cmd->name);
215 return false;
216 }
217
218 // Parsed (label, mailbox, flags) tuples will be appended to the @args array
219 struct Buffer *label = buf_pool_get();
220 struct Buffer *mailbox = buf_pool_get();
221 struct Buffer *token = buf_pool_get();
222 bool rc = false;
223
224 while (MoreArgs(line))
225 {
226 bool label_set = false;
227 enum TriBool notify = TB_UNSET;
228 enum TriBool poll = TB_UNSET;
229
230 do
231 {
232 // Start by handling the options
234
235 if (mutt_str_equal(buf_string(token), "-label"))
236 {
237 if (!MoreArgs(line))
238 {
239 buf_printf(err, _("%s: too few arguments"), "mailboxes -label");
240 goto done;
241 }
242
244 label_set = true;
245 }
246 else if (mutt_str_equal(buf_string(token), "-nolabel"))
247 {
248 buf_reset(label);
249 label_set = true;
250 }
251 else if (mutt_str_equal(buf_string(token), "-notify"))
252 {
253 notify = TB_TRUE;
254 }
255 else if (mutt_str_equal(buf_string(token), "-nonotify"))
256 {
257 notify = TB_FALSE;
258 }
259 else if (mutt_str_equal(buf_string(token), "-poll"))
260 {
261 poll = TB_TRUE;
262 }
263 else if (mutt_str_equal(buf_string(token), "-nopoll"))
264 {
265 poll = TB_FALSE;
266 }
267 else if ((cmd->id == CMD_NAMED_MAILBOXES) && !label_set)
268 {
269 if (!MoreArgs(line))
270 {
271 buf_printf(err, _("%s: too few arguments"), cmd->name);
272 goto done;
273 }
274
275 buf_copy(label, token);
276 label_set = true;
277 }
278 else
279 {
280 buf_copy(mailbox, token);
281 break;
282 }
283 } while (MoreArgs(line));
284
285 if (buf_is_empty(mailbox))
286 {
287 buf_printf(err, _("%s: too few arguments"), cmd->name);
288 goto done;
289 }
290
291 struct ParseMailbox pm = {
292 .path = buf_strdup(mailbox),
293 .label = label_set ? buf_strdup(label) : NULL,
294 .poll = poll,
295 .notify = notify,
296 };
297 ARRAY_ADD(args, pm);
298
300 buf_reset(mailbox);
301 }
302
303 rc = true;
304
305done:
307 buf_pool_release(&mailbox);
308 buf_pool_release(&token);
309 return rc;
310}
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition array.h:157
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition buffer.c:161
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition buffer.c:76
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition buffer.c:291
size_t buf_copy(struct Buffer *dst, const struct Buffer *src)
Copy a Buffer's contents to another Buffer.
Definition buffer.c:601
char * buf_strdup(const struct Buffer *buf)
Copy a Buffer's string.
Definition buffer.c:571
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition buffer.h:96
@ CMD_NAMED_MAILBOXES
:named-mailboxes
Definition command.h:98
int parse_extract_token(struct Buffer *dest, struct Buffer *line, TokenFlags flags)
Extract one token from a string.
Definition extract.c:49
#define MoreArgs(buf)
Definition extract.h:31
#define TOKEN_NO_FLAGS
No flags are set.
Definition extract.h:45
TriBool
Tri-state boolean.
Definition mailboxes.h:37
#define _(a)
Definition message.h:28
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition string.c:662
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition pool.c:91
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition pool.c:111
String manipulation buffer.
Definition buffer.h:36
const char * name
Name of the Command.
Definition command.h:159
enum CommandId id
ID of the Command.
Definition command.h:160
enum TriBool notify
Enable mailbox notification?
Definition mailboxes.h:51
enum TriBool poll
Enable mailbox polling?
Definition mailboxes.h:50
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse_mailboxes_exec()

enum CommandResult parse_mailboxes_exec ( const struct Command * cmd,
struct ParseMailboxArray * args,
struct Buffer * err )

Execute the 'mailboxes' or 'named-mailboxes' command.

Parameters
[in]cmdCommand being executed
[in]argsParsed arguments
[out]errBuffer for error messages
Return values
CommandResultResult e.g. MUTT_CMD_SUCCESS

Definition at line 319 of file mailboxes.c.

321{
322 if (!cmd || !args || !err)
323 return MUTT_CMD_ERROR;
324
325 const char *const c_folder = cs_subset_string(NeoMutt->sub, "folder");
327
328 struct ParseMailbox *pm = NULL;
329 ARRAY_FOREACH(pm, args)
330 {
331 rc = mailbox_add(c_folder, pm->path, pm->label, pm->poll, pm->notify, err);
332 if (rc != MUTT_CMD_SUCCESS)
333 return rc;
334 }
335
336 return rc;
337}
CommandResult
Error codes for command_t parse functions.
Definition command.h:37
@ MUTT_CMD_SUCCESS
Success: Command worked.
Definition command.h:40
@ MUTT_CMD_ERROR
Error: Can't help the user.
Definition command.h:38
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition helpers.c:291
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 mailboxes.c:53
Container for Accounts, Notifications.
Definition neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:49
+ 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 157 of file mailboxes.c.

158{
159 enum CommandResult rc = mailbox_add("", mailbox, NULL, TB_UNSET, TB_UNSET, err);
160
161 return (rc == MUTT_CMD_SUCCESS);
162}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mailbox_remove_simple()

bool mailbox_remove_simple ( const char * mailbox)

Remove a Mailbox.

Parameters
mailboxPath of Mailbox to remove
Return values
trueSuccess

Definition at line 394 of file mailboxes.c.

395{
396 struct Buffer *buf = buf_pool_get();
397 buf_strcpy(buf, mailbox);
398 expand_path(buf, false);
399
400 struct Account **ap = NULL;
402 {
403 struct Mailbox *m = mx_mbox_find(*ap, buf_string(buf));
404 if (m)
405 {
407 buf_pool_release(&buf);
408 return true;
409 }
410 }
411
412 buf_pool_release(&buf);
413 return false;
414}
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition buffer.c:395
static void do_unmailboxes(struct Mailbox *m)
Remove a Mailbox from the Sidebar/notifications.
Definition mailboxes.c:368
void expand_path(struct Buffer *buf, bool regex)
Create the canonical path.
Definition muttlib.c:121
struct Mailbox * mx_mbox_find(struct Account *a, const char *path)
Find a Mailbox on an Account.
Definition mx.c:1546
A group of associated Mailboxes.
Definition account.h:36
A mailbox.
Definition mailbox.h:78
struct AccountArray accounts
All Accounts.
Definition neomutt.h:50
+ Here is the call graph for this function:
+ Here is the caller graph for this function: