NeoMutt  2025-12-11-694-ga89709
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 /* Parse each mailbox specification: consume optional flags (-label, -notify,
225 * -poll and their negations) then the mailbox path itself */
226 while (MoreArgs(line))
227 {
228 bool label_set = false;
229 enum TriBool notify = TB_UNSET;
230 enum TriBool poll = TB_UNSET;
231
232 do
233 {
234 // Start by handling the options
236
237 if (mutt_str_equal(buf_string(token), "-label"))
238 {
239 if (!MoreArgs(line))
240 {
241 buf_printf(err, _("%s: too few arguments"), "mailboxes -label");
242 goto done;
243 }
244
246 label_set = true;
247 }
248 else if (mutt_str_equal(buf_string(token), "-nolabel"))
249 {
250 buf_reset(label);
251 label_set = true;
252 }
253 else if (mutt_str_equal(buf_string(token), "-notify"))
254 {
255 notify = TB_TRUE;
256 }
257 else if (mutt_str_equal(buf_string(token), "-nonotify"))
258 {
259 notify = TB_FALSE;
260 }
261 else if (mutt_str_equal(buf_string(token), "-poll"))
262 {
263 poll = TB_TRUE;
264 }
265 else if (mutt_str_equal(buf_string(token), "-nopoll"))
266 {
267 poll = TB_FALSE;
268 }
269 else if ((cmd->id == CMD_NAMED_MAILBOXES) && !label_set)
270 {
271 if (!MoreArgs(line))
272 {
273 buf_printf(err, _("%s: too few arguments"), cmd->name);
274 goto done;
275 }
276
277 buf_copy(label, token);
278 label_set = true;
279 }
280 else
281 {
282 buf_copy(mailbox, token);
283 break;
284 }
285 } while (MoreArgs(line));
286
287 if (buf_is_empty(mailbox))
288 {
289 buf_printf(err, _("%s: too few arguments"), cmd->name);
290 goto done;
291 }
292
293 /* Store the parsed mailbox entry with its associated options */
294 struct ParseMailbox pm = {
295 .path = buf_strdup(mailbox),
296 .label = label_set ? buf_strdup(label) : NULL,
297 .poll = poll,
298 .notify = notify,
299 };
300 ARRAY_ADD(args, pm);
301
303 buf_reset(mailbox);
304 }
305
306 rc = true;
307
308done:
310 buf_pool_release(&mailbox);
311 buf_pool_release(&token);
312 return rc;
313}
#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:665
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 322 of file mailboxes.c.

324{
325 if (!cmd || !args || !err)
326 return MUTT_CMD_ERROR;
327
328 const char *const c_folder = cs_subset_string(NeoMutt->sub, "folder");
330
331 struct ParseMailbox *pm = NULL;
332 ARRAY_FOREACH(pm, args)
333 {
334 rc = mailbox_add(c_folder, pm->path, pm->label, pm->poll, pm->notify, err);
335 if (rc != MUTT_CMD_SUCCESS)
336 return rc;
337 }
338
339 return rc;
340}
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 397 of file mailboxes.c.

398{
399 struct Buffer *buf = buf_pool_get();
400 buf_strcpy(buf, mailbox);
401 expand_path(buf, false);
402
403 struct Account **ap = NULL;
405 {
406 struct Mailbox *m = mx_mbox_find(*ap, buf_string(buf));
407 if (m)
408 {
410 buf_pool_release(&buf);
411 return true;
412 }
413 }
414
415 buf_pool_release(&buf);
416 return false;
417}
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:371
void expand_path(struct Buffer *buf, bool regex)
Create the canonical path.
Definition muttlib.c:122
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: