NeoMutt  2025-12-11-911-gd8d604
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
Browser Function API

Prototype for a Browser Function. More...

Functions

static int op_browser_new_file (struct BrowserPrivateData *priv, const struct KeyEvent *event)
 Select a new file in this directory - Implements browser_function_t -.
 
static int op_browser_subscribe (struct BrowserPrivateData *priv, const struct KeyEvent *event)
 Subscribe to current mbox (IMAP/NNTP only) - Implements browser_function_t -.
 
static int op_browser_tell (struct BrowserPrivateData *priv, const struct KeyEvent *event)
 Display the currently selected file's name - Implements browser_function_t -.
 
static int op_browser_toggle_lsub (struct BrowserPrivateData *priv, const struct KeyEvent *event)
 Toggle view all/subscribed mailboxes (IMAP only) - Implements browser_function_t -.
 
static int op_browser_view_file (struct BrowserPrivateData *priv, const struct KeyEvent *event)
 View file - Implements browser_function_t -.
 
static int op_catchup (struct BrowserPrivateData *priv, const struct KeyEvent *event)
 Mark all articles in newsgroup as read - Implements browser_function_t -.
 
static int op_change_directory (struct BrowserPrivateData *priv, const struct KeyEvent *event)
 Change directories - Implements browser_function_t -.
 
static int op_create_mailbox (struct BrowserPrivateData *priv, const struct KeyEvent *event)
 Create a new mailbox (IMAP only) - Implements browser_function_t -.
 
static int op_delete_mailbox (struct BrowserPrivateData *priv, const struct KeyEvent *event)
 Delete the current mailbox (IMAP only) - Implements browser_function_t -.
 
static int op_enter_mask (struct BrowserPrivateData *priv, const struct KeyEvent *event)
 Enter a file mask - Implements browser_function_t -.
 
static int op_exit (struct BrowserPrivateData *priv, const struct KeyEvent *event)
 Exit this menu - Implements browser_function_t -.
 
static int op_jump (struct BrowserPrivateData *priv, const struct KeyEvent *event)
 Jump to an index number - Implements browser_function_t -.
 
static int op_generic_select_entry (struct BrowserPrivateData *priv, const struct KeyEvent *event)
 Select the current entry - Implements browser_function_t -.
 
static int op_load_active (struct BrowserPrivateData *priv, const struct KeyEvent *event)
 Load list of all newsgroups from NNTP server - Implements browser_function_t -.
 
static int op_mailbox_list (struct BrowserPrivateData *priv, const struct KeyEvent *event)
 List mailboxes with new mail - Implements browser_function_t -.
 
static int op_rename_mailbox (struct BrowserPrivateData *priv, const struct KeyEvent *event)
 Rename the current mailbox (IMAP only) - Implements browser_function_t -.
 
static int op_sort (struct BrowserPrivateData *priv, const struct KeyEvent *event)
 Sort messages - Implements browser_function_t -.
 
static int op_subscribe_pattern (struct BrowserPrivateData *priv, const struct KeyEvent *event)
 Subscribe to newsgroups matching a pattern - Implements browser_function_t -.
 
static int op_toggle_mailboxes (struct BrowserPrivateData *priv, const struct KeyEvent *event)
 Toggle whether to browse mailboxes or all files - Implements browser_function_t -.
 

Detailed Description

Prototype for a Browser Function.

Parameters
privPrivate Browser data
eventEvent to process
Return values
enumFunctionRetval
Precondition
priv is not NULL
event is not NULL

Function Documentation

◆ op_browser_new_file()

static int op_browser_new_file ( struct BrowserPrivateData * priv,
const struct KeyEvent * event )
static

Select a new file in this directory - Implements browser_function_t -.

Definition at line 222 of file functions.c.

223{
225 struct Buffer *buf = buf_pool_get();
226 buf_printf(buf, "%s/", buf_string(&mod_data->last_dir));
227
228 struct FileCompletionData cdata = { false, priv->mailbox, NULL, NULL, NULL };
229 const int rc = mw_get_field(_("New file name: "), buf, MUTT_COMP_NONE,
230 HC_FILE, &CompleteMailboxOps, &cdata);
231 if (rc != 0)
232 {
233 buf_pool_release(&buf);
234 return FR_NO_ACTION;
235 }
236
237 buf_copy(priv->file, buf);
238 buf_pool_release(&buf);
239 priv->done = true;
240 return FR_DONE;
241}
const struct CompleteOps CompleteMailboxOps
Auto-Completion of Files / Mailboxes.
Definition complete.c:159
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition buffer.c:161
size_t buf_copy(struct Buffer *dst, const struct Buffer *src)
Copy a Buffer's contents to another Buffer.
Definition buffer.c:601
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition buffer.h:96
@ FR_DONE
Exit the Dialog.
Definition dispatcher.h:36
@ FR_NO_ACTION
Valid function - no action performed.
Definition dispatcher.h:38
@ MUTT_COMP_NONE
No flags are set.
Definition wdata.h:46
int mw_get_field(const char *prompt, struct Buffer *buf, CompletionFlags complete, enum HistoryClass hclass, const struct CompleteOps *comp_api, void *cdata)
Ask the user for a string -.
Definition window.c:502
@ HC_FILE
Files.
Definition lib.h:59
@ MODULE_ID_BROWSER
ModuleBrowser, Mailbox Browser
Definition module_api.h:52
#define _(a)
Definition message.h:28
void * neomutt_get_module_data(struct NeoMutt *n, enum ModuleId id)
Get the private data for a Module.
Definition neomutt.c:663
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
Browser private Module data.
Definition module_data.h:32
struct Buffer last_dir
Browser: previous selected directory.
Definition module_data.h:35
bool done
Should we close the Dialog?
struct Mailbox * mailbox
Mailbox.
struct Buffer * file
Buffer for the result.
String manipulation buffer.
Definition buffer.h:36
Input for the file completion function.
Definition curs_lib.h:39
Container for Accounts, Notifications.
Definition neomutt.h:41
+ Here is the call graph for this function:

◆ op_browser_subscribe()

static int op_browser_subscribe ( struct BrowserPrivateData * priv,
const struct KeyEvent * event )
static

Subscribe to current mbox (IMAP/NNTP only) - Implements browser_function_t -.

This function handles:

  • OP_BROWSER_SUBSCRIBE
  • OP_BROWSER_UNSUBSCRIBE

Supports repeat-count: 5<subscribe> operates on the current entry and the next 4. Overruns are silently capped at the end of the list.

Definition at line 302 of file functions.c.

303{
305 const bool subscribe = (event->op == OP_BROWSER_SUBSCRIBE);
306 const bool tagged = priv->menu->tag_prefix && (priv->menu->num_tagged > 0);
307
308 if (ARRAY_EMPTY(&priv->state.entry))
309 {
310 mutt_error(OptNews ? _("No newsgroups match the mask") : _("There are no mailboxes"));
311 return FR_ERROR;
312 }
313
314 struct FolderFilePtrArray ffpa = ARRAY_HEAD_INITIALIZER;
315 browser_add_selection(&ffpa, &priv->state, priv->menu, tagged, event->count);
316 if (ARRAY_EMPTY(&ffpa))
317 {
318 ARRAY_FREE(&ffpa);
319 return FR_NO_ACTION;
320 }
321 const int num = ARRAY_SIZE(&ffpa);
322
323 if (OptNews)
324 {
325 struct NntpAccountData *adata = mod_data->current_news_srv;
326 int rc = nntp_newsrc_parse(adata);
327 if (rc < 0)
328 {
329 ARRAY_FREE(&ffpa);
330 return FR_ERROR;
331 }
332
333 browser_apply_subscribe_nntp(&ffpa, adata, subscribe);
334
335 if (!tagged)
336 {
337 const int index = menu_get_index(priv->menu);
338 const int next = index + num;
339 if (next < ARRAY_SIZE(&priv->state.entry))
340 menu_set_index(priv->menu, next);
341 }
342
347 }
348 else
349 {
350 browser_apply_subscribe_imap(&ffpa, subscribe);
351 }
352
353 ARRAY_FREE(&ffpa);
354 return FR_SUCCESS;
355}
#define ARRAY_EMPTY(head)
Check if an array is empty.
Definition array.h:74
#define ARRAY_SIZE(head)
The number of elements stored.
Definition array.h:87
#define ARRAY_FREE(head)
Release all memory.
Definition array.h:209
#define ARRAY_HEAD_INITIALIZER
Static initializer for arrays.
Definition array.h:58
static void browser_apply_subscribe_imap(struct FolderFilePtrArray *ffpa, bool subscribe)
Subscribe/unsubscribe to IMAP mailboxes.
Definition functions.c:273
static void browser_apply_subscribe_nntp(struct FolderFilePtrArray *ffpa, struct NntpAccountData *adata, bool subscribe)
Subscribe/unsubscribe to NNTP newsgroups.
Definition functions.c:249
static int browser_add_selection(struct FolderFilePtrArray *ffpa, struct BrowserState *state, struct Menu *menu, bool tagged, int count)
Build a working set of FolderFile pointers for an action.
Definition functions.c:181
@ FR_SUCCESS
Valid function - successfully performed.
Definition dispatcher.h:40
@ FR_ERROR
Valid function - error occurred.
Definition dispatcher.h:39
bool OptNews
(pseudo) used to change reader mode
Definition globals.c:53
#define mutt_error(...)
Definition logging2.h:94
void menu_queue_redraw(struct Menu *menu, MenuRedrawFlags redraw)
Queue a request for a redraw.
Definition menu.c:179
int menu_get_index(struct Menu *menu)
Get the current selection in the Menu.
Definition menu.c:155
@ MENU_REDRAW_FULL
Redraw everything.
Definition lib.h:64
MenuRedrawFlags menu_set_index(struct Menu *menu, int index)
Set the current selection in the Menu.
Definition menu.c:169
@ MODULE_ID_NNTP
ModuleNntp, Nntp
Definition module_api.h:81
void nntp_clear_cache(struct NntpAccountData *adata)
Clear the NNTP cache.
Definition newsrc.c:848
int nntp_newsrc_parse(struct NntpAccountData *adata)
Parse .newsrc file.
Definition newsrc.c:165
void nntp_newsrc_close(struct NntpAccountData *adata)
Unlock and close .newsrc file.
Definition newsrc.c:121
int nntp_newsrc_update(struct NntpAccountData *adata)
Update .newsrc file.
Definition newsrc.c:444
void * adata
Private data (for Mailbox backends)
Definition account.h:42
struct Menu * menu
Menu.
struct BrowserState state
State containing list of files/dir/mailboxes.
struct BrowserEntryArray entry
Array of files / dirs / mailboxes.
Definition lib.h:149
int count
Optional count prefix, e.g. 3 for 3j
Definition get.h:78
int num_tagged
Number of tagged entries.
Definition lib.h:101
bool tag_prefix
User has pressed <tag-prefix>
Definition lib.h:92
NNTP-specific Account data -.
Definition adata.h:36
Nntp private Module data.
Definition module_data.h:30
struct NntpAccountData * current_news_srv
Current NNTP news server.
Definition module_data.h:32
+ Here is the call graph for this function:

◆ op_browser_tell()

static int op_browser_tell ( struct BrowserPrivateData * priv,
const struct KeyEvent * event )
static

Display the currently selected file's name - Implements browser_function_t -.

Definition at line 360 of file functions.c.

361{
362 int index = menu_get_index(priv->menu);
363 if (ARRAY_EMPTY(&priv->state.entry))
364 return FR_ERROR;
365
366 mutt_message("%s", ARRAY_GET(&priv->state.entry, index)->name);
367 return FR_SUCCESS;
368}
#define ARRAY_GET(head, idx)
Return the element at index.
Definition array.h:109
#define mutt_message(...)
Definition logging2.h:93
+ Here is the call graph for this function:

◆ op_browser_toggle_lsub()

static int op_browser_toggle_lsub ( struct BrowserPrivateData * priv,
const struct KeyEvent * event )
static

Toggle view all/subscribed mailboxes (IMAP only) - Implements browser_function_t -.

Definition at line 373 of file functions.c.

374{
375 bool_str_toggle(NeoMutt->sub, "imap_list_subscribed", NULL);
376
377 const bool c_imap_list_subscribed = cs_subset_bool(NeoMutt->sub, "imap_list_subscribed");
378 mutt_message("set imap_list_subscribed = %s", c_imap_list_subscribed ? "yes" : "no");
379
380 mutt_unget_op(OP_CHECK_NEW);
381 return FR_SUCCESS;
382}
int bool_str_toggle(struct ConfigSubset *sub, const char *name, struct Buffer *err)
Toggle the value of a bool.
Definition bool.c:231
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition helpers.c:47
void mutt_unget_op(int op)
Return an operation to the input buffer.
Definition get.c:159
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:49
+ Here is the call graph for this function:

◆ op_browser_view_file()

static int op_browser_view_file ( struct BrowserPrivateData * priv,
const struct KeyEvent * event )
static

View file - Implements browser_function_t -.

Definition at line 387 of file functions.c.

388{
390 if (ARRAY_EMPTY(&priv->state.entry))
391 {
392 mutt_error(_("No files match the file mask"));
393 return FR_ERROR;
394 }
395
396 int index = menu_get_index(priv->menu);
397 struct FolderFile *ff = ARRAY_GET(&priv->state.entry, index);
398 if (ff->selectable)
399 {
400 buf_strcpy(priv->file, ff->name);
401 priv->done = true;
402 return FR_DONE;
403 }
404 else if (S_ISDIR(ff->mode) ||
405 (S_ISLNK(ff->mode) && link_is_dir(buf_string(&mod_data->last_dir), ff->name)))
406 {
407 mutt_error(_("Can't view a directory"));
408 return FR_ERROR;
409 }
410 else
411 {
412 struct Buffer *path = buf_pool_get();
413 buf_concat_path(path, buf_string(&mod_data->last_dir), ff->name);
414 struct Body *b = mutt_make_file_attach(buf_string(path), NeoMutt->sub);
415 if (b)
416 {
417 mutt_view_attachment(NULL, b, MUTT_VA_REGULAR, NULL, NULL, priv->menu->win);
418 mutt_body_free(&b);
420 }
421 else
422 {
423 mutt_error(_("Error trying to view file"));
424 }
425 buf_pool_release(&path);
426 }
427 return FR_ERROR;
428}
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition buffer.c:395
size_t buf_concat_path(struct Buffer *buf, const char *dir, const char *fname)
Join a directory name and a filename.
Definition buffer.c:509
bool link_is_dir(const char *folder, const char *path)
Does this symlink point to a directory?
void mutt_body_free(struct Body **ptr)
Free a Body.
Definition body.c:58
int mutt_view_attachment(FILE *fp, struct Body *b, enum ViewAttachMode mode, struct Email *e, struct AttachCtx *actx, struct MuttWindow *win)
View an attachment.
@ MUTT_VA_REGULAR
View using default method.
Definition mutt_attach.h:45
struct Body * mutt_make_file_attach(const char *path, struct ConfigSubset *sub)
Create a file attachment.
Definition sendlib.c:613
The body of an email.
Definition body.h:36
Browser entry representing a folder/dir.
Definition lib.h:82
bool selectable
Folder can be selected.
Definition lib.h:100
char * name
Name of file/dir/mailbox.
Definition lib.h:90
mode_t mode
File permissions.
Definition lib.h:83
struct MuttWindow * win
Window holding the Menu.
Definition lib.h:94
+ Here is the call graph for this function:

◆ op_catchup()

static int op_catchup ( struct BrowserPrivateData * priv,
const struct KeyEvent * event )
static

Mark all articles in newsgroup as read - Implements browser_function_t -.

This function handles:

  • OP_CATCHUP
  • OP_UNCATCHUP

Supports repeat-count: 5<catchup> operates on the current entry and the next 4. Overruns are silently capped at the end of the list.

Definition at line 470 of file functions.c.

471{
473 if (!OptNews)
474 return FR_NOT_IMPL;
475
476 int rc = nntp_newsrc_parse(mod_data->current_news_srv);
477 if (rc < 0)
478 return FR_ERROR;
479
480 if (ARRAY_EMPTY(&priv->state.entry))
481 return FR_ERROR;
482
483 const bool tagged = priv->menu->tag_prefix && (priv->menu->num_tagged > 0);
484
485 struct FolderFilePtrArray ffpa = ARRAY_HEAD_INITIALIZER;
486 browser_add_selection(&ffpa, &priv->state, priv->menu, tagged, event->count);
487 if (ARRAY_EMPTY(&ffpa))
488 {
489 ARRAY_FREE(&ffpa);
490 return FR_NO_ACTION;
491 }
492 const int num = ARRAY_SIZE(&ffpa);
493
494 struct NntpMboxData *mdata = browser_apply_catchup(&ffpa, priv->mailbox,
495 mod_data->current_news_srv,
496 (event->op == OP_CATCHUP));
497 ARRAY_FREE(&ffpa);
498
499 if (mdata)
500 {
502 if (!tagged)
503 {
504 const int next = menu_get_index(priv->menu) + num;
505 if (next < priv->menu->max)
506 menu_set_index(priv->menu, next);
507 }
508 }
509
511
513 return FR_ERROR;
514}
static struct NntpMboxData * browser_apply_catchup(struct FolderFilePtrArray *ffpa, struct Mailbox *m, struct NntpAccountData *adata, bool up)
(Un)catchup a working set of newsgroups
Definition functions.c:438
@ FR_NOT_IMPL
Invalid function - feature not enabled.
Definition dispatcher.h:37
@ MENU_REDRAW_INDEX
Redraw the index.
Definition lib.h:61
int op
Function opcode, e.g. OP_HELP.
Definition get.h:77
void * mdata
Driver specific data.
Definition mailbox.h:134
NNTP-specific Mailbox data -.
Definition mdata.h:34
+ Here is the call graph for this function:

◆ op_change_directory()

static int op_change_directory ( struct BrowserPrivateData * priv,
const struct KeyEvent * event )
static

Change directories - Implements browser_function_t -.

This function handles:

  • OP_GOTO_PARENT
  • OP_CHANGE_DIRECTORY

Definition at line 523 of file functions.c.

524{
526 if (OptNews)
527 return FR_NOT_IMPL;
528
529 struct Buffer *buf = buf_pool_get();
530 buf_copy(buf, &mod_data->last_dir);
531 if (!priv->state.imap_browse)
532 {
533 /* add '/' at the end of the directory name if not already there */
534 size_t len = buf_len(buf);
535 if ((len > 0) && (buf_string(&mod_data->last_dir)[len - 1] != '/'))
536 buf_addch(buf, '/');
537 }
538
539 const int op = event->op;
540 if (op == OP_CHANGE_DIRECTORY)
541 {
542 struct FileCompletionData cdata = { false, priv->mailbox, NULL, NULL, NULL };
543 int rc = mw_get_field(_("Chdir to: "), buf, MUTT_COMP_NONE, HC_FILE,
544 &CompleteMailboxOps, &cdata);
545 if ((rc != 0) && buf_is_empty(buf))
546 {
547 buf_pool_release(&buf);
548 return FR_NO_ACTION;
549 }
550 }
551 else if (op == OP_GOTO_PARENT)
552 {
553 const int count = MAX(event->count, 1);
554 for (int i = 0; i < count; i++)
555 {
556 char prev[PATH_MAX];
557 mutt_str_copy(prev, buf_string(buf), sizeof(prev));
558 mutt_get_parent_path(buf_string(buf), buf->data, buf->dsize);
559 if (mutt_str_equal(buf_string(buf), prev))
560 break;
561 }
562 }
563
564 if (!buf_is_empty(buf))
565 {
566 priv->state.is_mailbox_list = false;
567 expand_path(buf, false);
568 if (imap_path_probe(buf_string(buf), NULL) == MUTT_IMAP)
569 {
570 buf_copy(&mod_data->last_dir, buf);
571 destroy_state(&priv->state);
572 init_state(&priv->state);
573 priv->state.imap_browse = true;
574 imap_browse(buf_string(&mod_data->last_dir), &priv->state);
575 browser_sort(&priv->state);
576 browser_highlight_default(&priv->state, priv->menu);
577 init_menu(&priv->state, priv->menu, priv->mailbox, priv->sbar);
578 }
579 else
580 {
581 if (buf_string(buf)[0] != '/')
582 {
583 /* in case dir is relative, make it relative to LastDir,
584 * not current working dir */
585 struct Buffer *tmp = buf_pool_get();
586 buf_concat_path(tmp, buf_string(&mod_data->last_dir), buf_string(buf));
587 buf_copy(buf, tmp);
588 buf_pool_release(&tmp);
589 }
590 /* Resolve path from <chdir>
591 * Avoids buildup such as /a/b/../../c
592 * Symlinks are always unraveled to keep code simple */
593 if (mutt_path_realpath(buf) == 0)
594 {
595 buf_pool_release(&buf);
596 return FR_ERROR;
597 }
598
599 struct stat st = { 0 };
600 if (stat(buf_string(buf), &st) == 0)
601 {
602 if (S_ISDIR(st.st_mode))
603 {
604 destroy_state(&priv->state);
605 if (examine_directory(priv->mailbox, priv->menu, &priv->state,
606 buf_string(buf), buf_string(priv->prefix)) == 0)
607 {
608 buf_copy(&mod_data->last_dir, buf);
609 }
610 else
611 {
612 mutt_error(_("Error scanning directory"));
613 if (examine_directory(priv->mailbox, priv->menu, &priv->state,
614 buf_string(&mod_data->last_dir),
615 buf_string(priv->prefix)) == -1)
616 {
617 priv->done = true;
618 return FR_ERROR;
619 }
620 }
621 browser_highlight_default(&priv->state, priv->menu);
622 init_menu(&priv->state, priv->menu, priv->mailbox, priv->sbar);
623 }
624 else
625 {
626 mutt_error(_("%s is not a directory"), buf_string(buf));
627 }
628 }
629 else
630 {
631 mutt_perror("%s", buf_string(buf));
632 }
633 }
634 }
635 buf_pool_release(&buf);
636 return FR_ERROR;
637}
int imap_browse(const char *path, struct BrowserState *state)
IMAP hook into the folder browser.
Definition browse.c:196
void destroy_state(struct BrowserState *state)
Free the BrowserState.
Definition functions.c:152
void browser_sort(struct BrowserState *state)
Sort the entries in the browser.
Definition sort.c:186
size_t buf_len(const struct Buffer *buf)
Calculate the length of a Buffer.
Definition buffer.c:491
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition buffer.c:291
size_t buf_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
Definition buffer.c:241
@ MUTT_IMAP
'IMAP' Mailbox type
Definition mailbox.h:49
int examine_directory(struct Mailbox *m, struct Menu *menu, struct BrowserState *state, const char *dirname, const char *prefix)
Get list of all files/newsgroups with mask.
void init_menu(struct BrowserState *state, struct Menu *menu, struct Mailbox *m, struct MuttWindow *sbar)
Set up a new menu.
void init_state(struct BrowserState *state)
Initialise a browser state.
void browser_highlight_default(struct BrowserState *state, struct Menu *menu)
Decide which browser item should be highlighted.
#define mutt_perror(...)
Definition logging2.h:95
enum MailboxType imap_path_probe(const char *path, const struct stat *st)
Is this an IMAP Mailbox?
Definition imap.c:2681
#define MAX(a, b)
Return the maximum of two values.
Definition memory.h:38
size_t mutt_path_realpath(struct Buffer *path)
Resolve path, unraveling symlinks.
Definition path.c:377
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition string.c:665
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:586
#define PATH_MAX
Definition mutt.h:49
void mutt_get_parent_path(const char *path, char *buf, size_t buflen)
Find the parent of a path (or mailbox)
Definition muttlib.c:867
void expand_path(struct Buffer *buf, bool regex)
Create the canonical path.
Definition muttlib.c:122
struct Buffer * prefix
Folder prefix string.
struct MuttWindow * sbar
Status Bar.
bool is_mailbox_list
Viewing mailboxes.
Definition lib.h:152
bool imap_browse
IMAP folder.
Definition lib.h:150
size_t dsize
Length of data.
Definition buffer.h:39
char * data
Pointer to data.
Definition buffer.h:37
+ Here is the call graph for this function:

◆ op_create_mailbox()

static int op_create_mailbox ( struct BrowserPrivateData * priv,
const struct KeyEvent * event )
static

Create a new mailbox (IMAP only) - Implements browser_function_t -.

Definition at line 642 of file functions.c.

643{
645 if (!priv->state.imap_browse)
646 {
647 mutt_error(_("Create is only supported for IMAP mailboxes"));
648 return FR_ERROR;
649 }
650
651 if (imap_mailbox_create(buf_string(&mod_data->last_dir)) != 0)
652 return FR_ERROR;
653
654 /* TODO: find a way to detect if the new folder would appear in
655 * this window, and insert it without starting over. */
656 destroy_state(&priv->state);
657 init_state(&priv->state);
658 priv->state.imap_browse = true;
659 imap_browse(buf_string(&mod_data->last_dir), &priv->state);
660 browser_sort(&priv->state);
661 browser_highlight_default(&priv->state, priv->menu);
662 init_menu(&priv->state, priv->menu, priv->mailbox, priv->sbar);
663
664 return FR_SUCCESS;
665}
int imap_mailbox_create(const char *path)
Create a new IMAP mailbox.
Definition browse.c:393
+ Here is the call graph for this function:

◆ op_delete_mailbox()

static int op_delete_mailbox ( struct BrowserPrivateData * priv,
const struct KeyEvent * event )
static

Delete the current mailbox (IMAP only) - Implements browser_function_t -.

Supports repeat-count: 5<delete-mailbox> deletes the current entry and the next 4. Overruns are silently capped at the end of the list.

Definition at line 716 of file functions.c.

717{
718 if (ARRAY_EMPTY(&priv->state.entry))
719 return FR_ERROR;
720
721 const bool tagged = priv->menu->tag_prefix && (priv->menu->num_tagged > 0);
722
723 struct FolderFilePtrArray ffpa = ARRAY_HEAD_INITIALIZER;
724 browser_add_selection(&ffpa, &priv->state, priv->menu, tagged, event->count);
725 if (ARRAY_EMPTY(&ffpa))
726 {
727 ARRAY_FREE(&ffpa);
728 return FR_NO_ACTION;
729 }
730
731 // Pre-flight validation
732 struct FolderFile **ffp = NULL;
733 ARRAY_FOREACH(ffp, &ffpa)
734 {
735 struct FolderFile *ff = *ffp;
736 if (!ff->imap)
737 {
738 mutt_error(_("Delete is only supported for IMAP mailboxes"));
739 ARRAY_FREE(&ffpa);
740 return FR_ERROR;
741 }
742 // TODO(sileht): It could be better to select INBOX instead. But I
743 // don't want to manipulate Mailboxes/mailbox->account here for now.
744 // Let's just protect neomutt against crash for now. #1417
745 if (mutt_str_equal(mailbox_path(priv->mailbox), ff->name))
746 {
747 mutt_error(_("Can't delete currently selected mailbox"));
748 ARRAY_FREE(&ffpa);
749 return FR_ERROR;
750 }
751 }
752
753 const int num = ARRAY_SIZE(&ffpa);
754 char msg[128] = { 0 };
755 if (num > 1)
756 {
757 snprintf(msg, sizeof(msg), _("Really delete %d tagged mailboxes?"), num);
758 }
759 else
760 {
761 struct FolderFile *ff = *ARRAY_FIRST(&ffpa);
762 snprintf(msg, sizeof(msg), _("Really delete mailbox \"%s\"?"), ff->name);
763 }
764 if (query_yesorno(msg, MUTT_NO) != MUTT_YES)
765 {
766 mutt_message(_("Mailbox not deleted"));
767 ARRAY_FREE(&ffpa);
768 return FR_NO_ACTION;
769 }
770
771 int failed = 0;
772 const int deleted = browser_apply_delete_mailbox(&ffpa, &priv->state,
773 priv->mailbox, &failed);
774 ARRAY_FREE(&ffpa);
775
776 if (failed > 0)
777 mutt_error(_("Mailbox deletion failed"));
778 else if (num > 1)
779 mutt_message(_("%d mailboxes deleted"), deleted);
780 else if (deleted == 1)
781 mutt_message(_("Mailbox deleted"));
782
783 init_menu(&priv->state, priv->menu, priv->mailbox, priv->sbar);
784 return failed ? FR_ERROR : FR_SUCCESS;
785}
#define ARRAY_FIRST(head)
Convenience method to get the first element.
Definition array.h:136
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition array.h:223
static int browser_apply_delete_mailbox(struct FolderFilePtrArray *ffpa, struct BrowserState *state, struct Mailbox *m, int *num_failed)
Delete a working set of IMAP mailboxes.
Definition functions.c:678
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox's path string.
Definition mailbox.h:216
@ MUTT_NO
User answered 'No', or assume 'No'.
Definition quad.h:38
@ MUTT_YES
User answered 'Yes', or assume 'Yes'.
Definition quad.h:39
enum QuadOption query_yesorno(const char *prompt, enum QuadOption def)
Ask the user a Yes/No question.
Definition question.c:329
bool imap
This is an IMAP folder.
Definition lib.h:99
+ Here is the call graph for this function:

◆ op_enter_mask()

static int op_enter_mask ( struct BrowserPrivateData * priv,
const struct KeyEvent * event )
static

Enter a file mask - Implements browser_function_t -.

Definition at line 790 of file functions.c.

791{
793 const struct Regex *c_mask = cs_subset_regex(NeoMutt->sub, "mask");
794 struct Buffer *buf = buf_pool_get();
795 buf_strcpy(buf, c_mask ? c_mask->pattern : NULL);
796 if (mw_get_field(_("File Mask: "), buf, MUTT_COMP_NONE, HC_OTHER, NULL, NULL) != 0)
797 {
798 buf_pool_release(&buf);
799 return FR_NO_ACTION;
800 }
801
802 buf_fix_dptr(buf);
803
804 priv->state.is_mailbox_list = false;
805 /* assume that the user wants to see everything */
806 if (buf_is_empty(buf))
807 buf_strcpy(buf, ".");
808
809 struct Buffer *errmsg = buf_pool_get();
810 int rc = cs_subset_str_string_set(NeoMutt->sub, "mask", buf_string(buf), errmsg);
811 buf_pool_release(&buf);
812 if (CSR_RESULT(rc) != CSR_SUCCESS)
813 {
814 if (!buf_is_empty(errmsg))
815 {
816 mutt_error("%s", buf_string(errmsg));
817 buf_pool_release(&errmsg);
818 }
819 return FR_ERROR;
820 }
821 buf_pool_release(&errmsg);
822
823 destroy_state(&priv->state);
824 if (priv->state.imap_browse)
825 {
826 init_state(&priv->state);
827 priv->state.imap_browse = true;
828 imap_browse(buf_string(&mod_data->last_dir), &priv->state);
829 browser_sort(&priv->state);
830 init_menu(&priv->state, priv->menu, priv->mailbox, priv->sbar);
831 }
832 else if (examine_directory(priv->mailbox, priv->menu, &priv->state,
833 buf_string(&mod_data->last_dir), NULL) == 0)
834 {
835 init_menu(&priv->state, priv->menu, priv->mailbox, priv->sbar);
836 }
837 else
838 {
839 mutt_error(_("Error scanning directory"));
840 priv->done = true;
841 return FR_ERROR;
842 }
843 priv->kill_prefix = false;
844 if (ARRAY_EMPTY(&priv->state.entry))
845 {
846 mutt_error(_("No files match the file mask"));
847 return FR_ERROR;
848 }
849 return FR_SUCCESS;
850}
void buf_fix_dptr(struct Buffer *buf)
Move the dptr to end of the Buffer.
Definition buffer.c:182
const struct Regex * cs_subset_regex(const struct ConfigSubset *sub, const char *name)
Get a regex config item by name.
Definition helpers.c:217
#define CSR_RESULT(x)
Extract the result code from CSR_* flags.
Definition set.h:53
#define CSR_SUCCESS
Action completed successfully.
Definition set.h:33
@ HC_OTHER
Miscellaneous strings.
Definition lib.h:61
bool kill_prefix
Prefix is in use.
Cached regular expression.
Definition regex3.h:85
char * pattern
printable version
Definition regex3.h:86
int cs_subset_str_string_set(const struct ConfigSubset *sub, const char *name, const char *value, struct Buffer *err)
Set a config item by string.
Definition subset.c:392
+ Here is the call graph for this function:

◆ op_exit()

static int op_exit ( struct BrowserPrivateData * priv,
const struct KeyEvent * event )
static

Exit this menu - Implements browser_function_t -.

Definition at line 855 of file functions.c.

856{
858 if (priv->multiple)
859 {
860 char **tfiles = NULL;
861
862 if (priv->menu->tag_prefix && (priv->menu->num_tagged != 0))
863 {
864 *priv->numfiles = priv->menu->num_tagged;
865 tfiles = MUTT_MEM_CALLOC(*priv->numfiles, char *);
866 size_t j = 0;
867 struct FolderFile *ff = NULL;
868 ARRAY_FOREACH(ff, &priv->state.entry)
869 {
870 if (ff->tagged)
871 {
872 struct Buffer *buf = buf_pool_get();
873 buf_concat_path(buf, buf_string(&mod_data->last_dir), ff->name);
874 expand_path(buf, false);
875 tfiles[j++] = buf_strdup(buf);
876 buf_pool_release(&buf);
877 }
878 }
879 *priv->files = tfiles;
880 }
881 else if (!buf_is_empty(priv->file)) /* no tagged entries. return selected entry */
882 {
883 *priv->numfiles = 1;
884 tfiles = MUTT_MEM_CALLOC(*priv->numfiles, char *);
885 expand_path(priv->file, false);
886 tfiles[0] = buf_strdup(priv->file);
887 *priv->files = tfiles;
888 }
889 }
890
891 priv->done = true;
892 return FR_DONE;
893}
char * buf_strdup(const struct Buffer *buf)
Copy a Buffer's string.
Definition buffer.c:571
#define MUTT_MEM_CALLOC(n, type)
Definition memory.h:52
char *** files
Array of selected files.
int * numfiles
Number of selected files.
bool multiple
Allow multiple selections.
bool tagged
Folder is tagged.
Definition lib.h:106
+ Here is the call graph for this function:

◆ op_jump()

static int op_jump ( struct BrowserPrivateData * priv,
const struct KeyEvent * event )
static

Jump to an index number - Implements browser_function_t -.

Definition at line 898 of file functions.c.

899{
900 int num = event->count;
901
902 if (num == 0)
903 return FR_NO_ACTION;
904
905 struct Menu *menu = priv->menu;
906
907 if ((num < 1) || (num > menu->max))
908 {
909 mutt_warning(_("Invalid message number"));
910 return FR_ERROR;
911 }
912
913 menu_set_index(menu, num - 1); // Num is 1-based
914 return FR_SUCCESS;
915}
#define mutt_warning(...)
Definition logging2.h:92
Definition lib.h:86
int max
Number of entries in the menu.
Definition lib.h:88
+ Here is the call graph for this function:

◆ op_generic_select_entry()

static int op_generic_select_entry ( struct BrowserPrivateData * priv,
const struct KeyEvent * event )
static

Select the current entry - Implements browser_function_t -.

This function handles:

  • OP_DESCEND_DIRECTORY
  • OP_GENERIC_SELECT_ENTRY

Definition at line 924 of file functions.c.

925{
926 if (event->count > 0)
927 return op_jump(priv, event);
928
930 if (ARRAY_EMPTY(&priv->state.entry))
931 {
932 mutt_warning(_("No files match the file mask"));
933 return FR_ERROR;
934 }
935
936 const int op = event->op;
937 int index = menu_get_index(priv->menu);
938 struct FolderFile *ff = ARRAY_GET(&priv->state.entry, index);
939 if ((priv->menu->tag_prefix) && (op == OP_GENERIC_SELECT_ENTRY))
940 {
941 // Do nothing
942 }
943 else if (S_ISDIR(ff->mode) ||
944 (S_ISLNK(ff->mode) && link_is_dir(buf_string(&mod_data->last_dir), ff->name)) ||
945 ff->inferiors)
946 {
947 /* make sure this isn't a MH or maildir mailbox */
948 struct Buffer *buf = buf_pool_get();
949 if (priv->state.is_mailbox_list)
950 {
951 buf_strcpy(buf, ff->name);
952 expand_path(buf, false);
953 }
954 else if (priv->state.imap_browse)
955 {
956 buf_strcpy(buf, ff->name);
957 }
958 else
959 {
960 buf_concat_path(buf, buf_string(&mod_data->last_dir), ff->name);
961 }
962
963 enum MailboxType type = mx_path_probe(buf_string(buf));
964 buf_pool_release(&buf);
965
966 if ((op == OP_DESCEND_DIRECTORY) || (type == MUTT_MAILBOX_ERROR) ||
967 (type == MUTT_UNKNOWN) || ff->inferiors)
968 {
969 /* save the old directory */
970 buf_copy(priv->old_last_dir, &mod_data->last_dir);
971
972 if (mutt_str_equal(ff->name, ".."))
973 {
974 size_t lastdirlen = buf_len(&mod_data->last_dir);
975 if ((lastdirlen > 1) &&
976 mutt_str_equal("..", buf_string(&mod_data->last_dir) + lastdirlen - 2))
977 {
978 buf_addstr(&mod_data->last_dir, "/..");
979 }
980 else
981 {
982 char *p = NULL;
983 if (lastdirlen > 1)
984 p = strrchr(mod_data->last_dir.data + 1, '/');
985
986 if (p)
987 {
988 *p = '\0';
989 buf_fix_dptr(&mod_data->last_dir);
990 }
991 else
992 {
993 if (buf_string(&mod_data->last_dir)[0] == '/')
994 buf_strcpy(&mod_data->last_dir, "/");
995 else
996 buf_addstr(&mod_data->last_dir, "/..");
997 }
998 }
999 }
1000 else if (priv->state.is_mailbox_list)
1001 {
1002 buf_strcpy(&mod_data->last_dir, ff->name);
1003 expand_path(&mod_data->last_dir, false);
1004 }
1005 else if (priv->state.imap_browse)
1006 {
1007 buf_strcpy(&mod_data->last_dir, ff->name);
1008 /* tack on delimiter here */
1009
1010 /* special case "" needs no delimiter */
1011 struct Url *url = url_parse(ff->name);
1012 if (url && url->path && (ff->delim != '\0'))
1013 {
1014 buf_addch(&mod_data->last_dir, ff->delim);
1015 }
1016 url_free(&url);
1017 }
1018 else
1019 {
1020 struct Buffer *tmp = buf_pool_get();
1021 buf_concat_path(tmp, buf_string(&mod_data->last_dir), ff->name);
1022 buf_copy(&mod_data->last_dir, tmp);
1023 buf_pool_release(&tmp);
1024 }
1025
1026 destroy_state(&priv->state);
1027 if (priv->kill_prefix)
1028 {
1029 buf_reset(priv->prefix);
1030 priv->kill_prefix = false;
1031 }
1032 priv->state.is_mailbox_list = false;
1033 if (priv->state.imap_browse)
1034 {
1035 init_state(&priv->state);
1036 priv->state.imap_browse = true;
1037 imap_browse(buf_string(&mod_data->last_dir), &priv->state);
1038 browser_sort(&priv->state);
1039 }
1040 else
1041 {
1042 if (examine_directory(priv->mailbox, priv->menu, &priv->state,
1043 buf_string(&mod_data->last_dir),
1044 buf_string(priv->prefix)) == -1)
1045 {
1046 /* try to restore the old values */
1047 buf_copy(&mod_data->last_dir, priv->old_last_dir);
1048 if (examine_directory(priv->mailbox, priv->menu, &priv->state,
1049 buf_string(&mod_data->last_dir),
1050 buf_string(priv->prefix)) == -1)
1051 {
1052 buf_strcpy(&mod_data->last_dir, NeoMutt->home_dir);
1053 priv->done = true;
1054 return FR_DONE;
1055 }
1056 }
1057 /* resolve paths navigated from GUI */
1058 if (mutt_path_realpath(&mod_data->last_dir) == 0)
1059 return FR_ERROR;
1060 }
1061
1062 browser_highlight_default(&priv->state, priv->menu);
1063 init_menu(&priv->state, priv->menu, priv->mailbox, priv->sbar);
1064 priv->goto_swapper[0] = '\0';
1065 return FR_SUCCESS;
1066 }
1067 }
1068 else if (op == OP_DESCEND_DIRECTORY)
1069 {
1070 mutt_error(_("%s is not a directory"), ARRAY_GET(&priv->state.entry, index)->name);
1071 return FR_ERROR;
1072 }
1073
1074 if (priv->state.is_mailbox_list || OptNews)
1075 {
1076 buf_strcpy(priv->file, ff->name);
1077 expand_path(priv->file, false);
1078 }
1079 else if (priv->state.imap_browse)
1080 {
1081 buf_strcpy(priv->file, ff->name);
1082 }
1083 else
1084 {
1085 buf_concat_path(priv->file, buf_string(&mod_data->last_dir), ff->name);
1086 }
1087
1088 return op_exit(priv, event);
1089}
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition buffer.c:76
size_t buf_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition buffer.c:226
MailboxType
Supported mailbox formats.
Definition mailbox.h:40
@ MUTT_MAILBOX_ERROR
Error occurred examining Mailbox.
Definition mailbox.h:42
@ MUTT_UNKNOWN
Mailbox wasn't recognised.
Definition mailbox.h:43
static int op_jump(struct AliasFunctionData *fdata, const struct KeyEvent *event)
Jump to an index number - Implements alias_function_t -.
Definition functions.c:320
static int op_exit(struct AliasFunctionData *fdata, const struct KeyEvent *event)
exit this menu - Implements alias_function_t -
Definition functions.c:312
enum MailboxType mx_path_probe(const char *path)
Find a mailbox that understands a path.
Definition mx.c:1323
struct Buffer * old_last_dir
Previous to last dir.
char goto_swapper[PATH_MAX]
Saved path after <goto-folder>
char delim
Path delimiter.
Definition lib.h:97
bool inferiors
Folder has children.
Definition lib.h:101
char * home_dir
User's home directory.
Definition neomutt.h:55
A parsed URL proto://user:password@host:port/path?a=1&b=2
Definition url.h:69
char * path
Path.
Definition url.h:75
struct Url * url_parse(const char *src)
Fill in Url.
Definition url.c:242
void url_free(struct Url **ptr)
Free the contents of a URL.
Definition url.c:124
+ Here is the call graph for this function:

◆ op_load_active()

static int op_load_active ( struct BrowserPrivateData * priv,
const struct KeyEvent * event )
static

Load list of all newsgroups from NNTP server - Implements browser_function_t -.

Definition at line 1094 of file functions.c.

1095{
1097 if (!OptNews)
1098 return FR_NOT_IMPL;
1099
1100 struct NntpAccountData *adata = mod_data->current_news_srv;
1101
1102 if (nntp_newsrc_parse(adata) < 0)
1103 return FR_ERROR;
1104
1105 for (size_t i = 0; i < adata->groups_num; i++)
1106 {
1107 struct NntpMboxData *mdata = adata->groups_list[i];
1108 if (mdata)
1109 mdata->deleted = true;
1110 }
1111 nntp_active_fetch(adata, true);
1114
1115 destroy_state(&priv->state);
1116 if (priv->state.is_mailbox_list)
1117 {
1118 examine_mailboxes(priv->mailbox, priv->menu, &priv->state);
1119 }
1120 else
1121 {
1122 if (examine_directory(priv->mailbox, priv->menu, &priv->state, NULL, NULL) == -1)
1123 return FR_ERROR;
1124 }
1125 init_menu(&priv->state, priv->menu, priv->mailbox, priv->sbar);
1126 return FR_SUCCESS;
1127}
int examine_mailboxes(struct Mailbox *m, struct Menu *menu, struct BrowserState *state)
Get list of mailboxes/subscribed newsgroups.
int nntp_active_fetch(struct NntpAccountData *adata, bool mark_new)
Fetch list of all newsgroups from server.
Definition nntp.c:2037
struct NntpMboxData ** groups_list
List of newsgroups.
Definition adata.h:60
bool deleted
Newsgroup is deleted.
Definition mdata.h:45
struct NntpAccountData * adata
Account data.
Definition mdata.h:48
+ Here is the call graph for this function:

◆ op_mailbox_list()

static int op_mailbox_list ( struct BrowserPrivateData * priv,
const struct KeyEvent * event )
static

List mailboxes with new mail - Implements browser_function_t -.

Definition at line 1132 of file functions.c.

1133{
1135 return FR_SUCCESS;
1136}
bool mutt_mailbox_list(void)
Show a message with the list of mailboxes with new mail.
+ Here is the call graph for this function:

◆ op_rename_mailbox()

static int op_rename_mailbox ( struct BrowserPrivateData * priv,
const struct KeyEvent * event )
static

Rename the current mailbox (IMAP only) - Implements browser_function_t -.

Definition at line 1141 of file functions.c.

1142{
1144 if (ARRAY_EMPTY(&priv->state.entry))
1145 return FR_ERROR;
1146
1147 int index = menu_get_index(priv->menu);
1148 struct FolderFile *ff = ARRAY_GET(&priv->state.entry, index);
1149 if (!ff->imap)
1150 {
1151 mutt_error(_("Rename is only supported for IMAP mailboxes"));
1152 return FR_ERROR;
1153 }
1154
1155 if (imap_mailbox_rename(ff->name) < 0)
1156 return FR_ERROR;
1157
1158 destroy_state(&priv->state);
1159 init_state(&priv->state);
1160 priv->state.imap_browse = true;
1161 imap_browse(buf_string(&mod_data->last_dir), &priv->state);
1162 browser_sort(&priv->state);
1163 browser_highlight_default(&priv->state, priv->menu);
1164 init_menu(&priv->state, priv->menu, priv->mailbox, priv->sbar);
1165
1166 return FR_SUCCESS;
1167}
int imap_mailbox_rename(const char *path)
Rename a mailbox.
Definition browse.c:448
+ Here is the call graph for this function:

◆ op_sort()

static int op_sort ( struct BrowserPrivateData * priv,
const struct KeyEvent * event )
static

Sort messages - Implements browser_function_t -.

This function handles:

  • OP_SORT
  • OP_SORT_REVERSE

Definition at line 1176 of file functions.c.

1177{
1178 bool resort = true;
1179 int sort = -1;
1180 const int op = event->op;
1181 int reverse = (op == OP_SORT_REVERSE);
1182
1183 switch (mw_multi_choice((reverse) ?
1184 /* L10N: The highlighted letters must match the "Sort" options */
1185 _("Reverse sort by (d)ate, (a)lpha, si(z)e, d(e)scription, (c)ount, ne(w) count, or do(n)'t sort?") :
1186 /* L10N: The highlighted letters must match the "Reverse Sort" options */
1187 _("Sort by (d)ate, (a)lpha, si(z)e, d(e)scription, (c)ount, ne(w) count, or do(n)'t sort?"),
1188 /* L10N: These must match the highlighted letters from "Sort" and "Reverse Sort" */
1189 _("dazecwn")))
1190 {
1191 case -1: /* abort */
1192 resort = false;
1193 break;
1194
1195 case 1: /* (d)ate */
1196 sort = BROWSER_SORT_DATE;
1197 break;
1198
1199 case 2: /* (a)lpha */
1200 sort = BROWSER_SORT_ALPHA;
1201 break;
1202
1203 case 3: /* si(z)e */
1204 sort = BROWSER_SORT_SIZE;
1205 break;
1206
1207 case 4: /* d(e)scription */
1208 sort = BROWSER_SORT_DESC;
1209 break;
1210
1211 case 5: /* (c)ount */
1212 sort = BROWSER_SORT_COUNT;
1213 break;
1214
1215 case 6: /* ne(w) count */
1216 sort = BROWSER_SORT_NEW;
1217 break;
1218
1219 case 7: /* do(n)'t sort */
1220 sort = BROWSER_SORT_UNSORTED;
1221 break;
1222 }
1223
1224 if (!resort)
1225 return FR_NO_ACTION;
1226
1227 sort |= reverse ? SORT_REVERSE : 0;
1228 cs_subset_str_native_set(NeoMutt->sub, "browser_sort", sort, NULL);
1229 browser_sort(&priv->state);
1230 browser_highlight_default(&priv->state, priv->menu);
1232 return FR_SUCCESS;
1233}
@ BROWSER_SORT_ALPHA
Sort by name.
Definition sort.h:31
@ BROWSER_SORT_UNSORTED
Sort into the raw order.
Definition sort.h:37
@ BROWSER_SORT_COUNT
Sort by total message count.
Definition sort.h:32
@ BROWSER_SORT_DATE
Sort by date.
Definition sort.h:33
@ BROWSER_SORT_NEW
Sort by count of new messages.
Definition sort.h:35
@ BROWSER_SORT_SIZE
Sort by size.
Definition sort.h:36
@ BROWSER_SORT_DESC
Sort by description.
Definition sort.h:34
#define SORT_REVERSE
Reverse the order of the sort.
Definition sort.h:40
int mw_multi_choice(const char *prompt, const char *letters)
Offer the user a multiple choice question -.
Definition question.c:62
int cs_subset_str_native_set(const struct ConfigSubset *sub, const char *name, intptr_t value, struct Buffer *err)
Natively set the value of a string config item.
Definition subset.c:303
+ Here is the call graph for this function:

◆ op_subscribe_pattern()

static int op_subscribe_pattern ( struct BrowserPrivateData * priv,
const struct KeyEvent * event )
static

Subscribe to newsgroups matching a pattern - Implements browser_function_t -.

This function handles:

  • OP_SUBSCRIBE_PATTERN
  • OP_UNSUBSCRIBE_PATTERN

Definition at line 1242 of file functions.c.

1243{
1245 if (!OptNews)
1246 return FR_NOT_IMPL;
1247
1248 struct NntpAccountData *adata = mod_data->current_news_srv;
1249 regex_t rx = { 0 };
1250 int index = menu_get_index(priv->menu);
1251
1252 char tmp2[256] = { 0 };
1253
1254 const int op = event->op;
1255 struct Buffer *buf = buf_pool_get();
1256 if (op == OP_SUBSCRIBE_PATTERN)
1257 snprintf(tmp2, sizeof(tmp2), _("Subscribe pattern: "));
1258 else
1259 snprintf(tmp2, sizeof(tmp2), _("Unsubscribe pattern: "));
1260 /* buf comes from the buffer pool, so defaults to size 1024 */
1261 if ((mw_get_field(tmp2, buf, MUTT_COMP_NONE, HC_PATTERN, &CompletePatternOps, NULL) != 0) ||
1262 buf_is_empty(buf))
1263 {
1264 buf_pool_release(&buf);
1265 return FR_NO_ACTION;
1266 }
1267
1268 int err = REG_COMP(&rx, buf->data, REG_NOSUB);
1269 if (err != 0)
1270 {
1271 regerror(err, &rx, buf->data, buf->dsize);
1272 regfree(&rx);
1273 mutt_error("%s", buf_string(buf));
1274 buf_pool_release(&buf);
1275 return FR_ERROR;
1276 }
1278 index = 0;
1279 buf_pool_release(&buf);
1280
1281 int rc = nntp_newsrc_parse(adata);
1282 if (rc < 0)
1283 return FR_ERROR;
1284
1285 struct FolderFile *ff = NULL;
1286 ARRAY_FOREACH_FROM(ff, &priv->state.entry, index)
1287 {
1288 if (regexec(&rx, ff->name, 0, NULL, 0) == 0)
1289 {
1290 if (op == OP_SUBSCRIBE_PATTERN)
1291 mutt_newsgroup_subscribe(adata, ff->name);
1292 else
1293 mutt_newsgroup_unsubscribe(adata, ff->name);
1294 }
1295 }
1296
1297 if (op == OP_SUBSCRIBE_PATTERN)
1298 {
1299 for (size_t j = 0; j < adata->groups_num; j++)
1300 {
1301 struct NntpMboxData *mdata = adata->groups_list[j];
1302 if (mdata && mdata->group && !mdata->subscribed)
1303 {
1304 if (regexec(&rx, mdata->group, 0, NULL, 0) == 0)
1305 {
1307 browser_add_folder(priv->menu, &priv->state, mdata->group, NULL, NULL, NULL, mdata);
1308 }
1309 }
1310 }
1311 init_menu(&priv->state, priv->menu, priv->mailbox, priv->sbar);
1312 }
1313 if (rc > 0)
1318 regfree(&rx);
1319 return FR_SUCCESS;
1320}
#define ARRAY_FOREACH_FROM(elem, head, from)
Iterate from an index to the end.
Definition array.h:235
void browser_add_folder(const struct Menu *menu, struct BrowserState *state, const char *name, const char *desc, const struct stat *st, struct Mailbox *m, void *data)
Add a folder to the browser list.
@ HC_PATTERN
Patterns.
Definition lib.h:60
struct NntpMboxData * mutt_newsgroup_subscribe(struct NntpAccountData *adata, char *group)
Subscribe newsgroup.
Definition newsrc.c:1183
struct NntpMboxData * mutt_newsgroup_unsubscribe(struct NntpAccountData *adata, char *group)
Unsubscribe newsgroup.
Definition newsrc.c:1207
const struct CompleteOps CompletePatternOps
Auto-Completion of Patterns.
Definition complete.c:98
#define REG_COMP(preg, regex, cflags)
Compile a regular expression.
Definition regex3.h:49
unsigned int groups_num
Number of newsgroups.
Definition adata.h:58
+ Here is the call graph for this function:

◆ op_toggle_mailboxes()

static int op_toggle_mailboxes ( struct BrowserPrivateData * priv,
const struct KeyEvent * event )
static

Toggle whether to browse mailboxes or all files - Implements browser_function_t -.

This function handles:

  • OP_BROWSER_GOTO_FOLDER
  • OP_CHECK_NEW
  • OP_TOGGLE_MAILBOXES

Definition at line 1330 of file functions.c.

1331{
1333 if (priv->state.is_mailbox_list)
1334 {
1336 }
1337
1338 const int op = event->op;
1339 if (op == OP_TOGGLE_MAILBOXES)
1340 {
1342 }
1343
1344 if (op == OP_BROWSER_GOTO_FOLDER)
1345 {
1346 /* When in mailboxes mode, disables this feature */
1347 const char *const c_folder = cs_subset_string(NeoMutt->sub, "folder");
1348 if (c_folder)
1349 {
1350 mutt_debug(LL_DEBUG3, "= hit! Folder: %s, LastDir: %s\n", c_folder,
1351 buf_string(&mod_data->last_dir));
1352 if (priv->goto_swapper[0] == '\0')
1353 {
1354 if (!mutt_str_equal(buf_string(&mod_data->last_dir), c_folder))
1355 {
1356 /* Stores into goto_swapper LastDir, and swaps to `$folder` */
1357 mutt_str_copy(priv->goto_swapper, buf_string(&mod_data->last_dir),
1358 sizeof(priv->goto_swapper));
1359 buf_copy(&mod_data->last_dir_backup, &mod_data->last_dir);
1360 buf_strcpy(&mod_data->last_dir, c_folder);
1361 }
1362 }
1363 else
1364 {
1365 buf_copy(&mod_data->last_dir_backup, &mod_data->last_dir);
1366 buf_strcpy(&mod_data->last_dir, priv->goto_swapper);
1367 priv->goto_swapper[0] = '\0';
1368 }
1369 }
1370 }
1371 destroy_state(&priv->state);
1372 buf_reset(priv->prefix);
1373 priv->kill_prefix = false;
1374
1375 if (priv->state.is_mailbox_list)
1376 {
1377 examine_mailboxes(priv->mailbox, priv->menu, &priv->state);
1378 }
1379 else if (imap_path_probe(buf_string(&mod_data->last_dir), NULL) == MUTT_IMAP)
1380 {
1381 init_state(&priv->state);
1382 priv->state.imap_browse = true;
1383 imap_browse(buf_string(&mod_data->last_dir), &priv->state);
1384 browser_sort(&priv->state);
1385 }
1386 else if (examine_directory(priv->mailbox, priv->menu, &priv->state,
1387 buf_string(&mod_data->last_dir),
1388 buf_string(priv->prefix)) == -1)
1389 {
1390 priv->done = true;
1391 return FR_ERROR;
1392 }
1393 init_menu(&priv->state, priv->menu, priv->mailbox, priv->sbar);
1394 if (priv->state.is_mailbox_list)
1396 return FR_ERROR;
1397}
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition helpers.c:291
#define mutt_debug(LEVEL,...)
Definition logging2.h:91
@ LL_DEBUG3
Log at debug level 3.
Definition logging2.h:47
struct Buffer last_dir_backup
Browser: backup copy of the current directory.
Definition module_data.h:36
int last_selected_mailbox
Index of last selected Mailbox.
+ Here is the call graph for this function: