NeoMutt  2025-12-11-694-ga89709
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
dlg_browser.c File Reference

File/Mailbox Browser Dialog. More...

#include "config.h"
#include <dirent.h>
#include <errno.h>
#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include "mutt/lib.h"
#include "config/lib.h"
#include "email/lib.h"
#include "core/lib.h"
#include "conn/lib.h"
#include "gui/lib.h"
#include "lib.h"
#include "expando/lib.h"
#include "imap/lib.h"
#include "key/lib.h"
#include "menu/lib.h"
#include "nntp/lib.h"
#include "expando.h"
#include "functions.h"
#include "globals.h"
#include "mutt_logging.h"
#include "mutt_mailbox.h"
#include "muttlib.h"
#include "mx.h"
#include "nntp/adata.h"
#include "nntp/mdata.h"
#include "private_data.h"
#include "sort.h"
+ Include dependency graph for dlg_browser.c:

Go to the source code of this file.

Functions

static void init_lastdir (void)
 Initialise the browser directories.
 
void mutt_browser_cleanup (void)
 Clean up working Buffers.
 
bool link_is_dir (const char *folder, const char *path)
 Does this symlink point to a directory?
 
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.
 
void init_state (struct BrowserState *state)
 Initialise a browser state.
 
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.
 
int examine_mailboxes (struct Mailbox *m, struct Menu *menu, struct BrowserState *state)
 Get list of mailboxes/subscribed newsgroups.
 
static int select_file_search (struct Menu *menu, regex_t *rx, int line)
 Menu search callback for matching files - Implements Menu::search() -.
 
static int folder_make_entry (struct Menu *menu, int line, int max_cols, struct Buffer *buf)
 Format a Folder for the Menu - Implements Menu::make_entry() -.
 
void browser_highlight_default (struct BrowserState *state, struct Menu *menu)
 Decide which browser item should be highlighted.
 
void init_menu (struct BrowserState *state, struct Menu *menu, struct Mailbox *m, struct MuttWindow *sbar)
 Set up a new menu.
 
static int file_tag (struct Menu *menu, int sel, int act)
 Tag an entry in the menu - Implements Menu::tag() -.
 
static int browser_config_observer (struct NotifyCallback *nc)
 Notification that a Config Variable has changed - Implements observer_t -.
 
static int browser_mailbox_observer (struct NotifyCallback *nc)
 Notification that a Mailbox has changed - Implements observer_t -.
 
static int browser_window_observer (struct NotifyCallback *nc)
 Notification that a Window has changed - Implements observer_t -.
 
void mutt_browser_select_dir (const char *f)
 Remember the last directory selected.
 
void dlg_browser (struct Buffer *file, SelectFileFlags flags, struct Mailbox *m, char ***files, int *numfiles)
 Let the user select a file -.
 

Variables

static const struct Mapping FolderHelp []
 Help Bar for the File/Dir/Mailbox browser dialog.
 
static const struct Mapping FolderNewsHelp []
 Help Bar for the NNTP Mailbox browser dialog.
 
struct Buffer LastDir = { 0 }
 Browser: previous selected directory.
 
struct Buffer LastDirBackup = { 0 }
 Browser: backup copy of the current directory.
 

Detailed Description

File/Mailbox Browser Dialog.

Authors
  • Pierre-Elliott Bécue
  • Richard Russon
  • Austin Ray
  • Pietro Cerutti
  • R Primus
  • Carlos Henrique Lima Melara
  • Leon Philman
  • наб
  • Tóth János

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 dlg_browser.c.

Function Documentation

◆ init_lastdir()

static void init_lastdir ( void )
static

Initialise the browser directories.

These keep track of where the browser used to be looking.

Definition at line 144 of file dlg_browser.c.

145{
146 static bool done = false;
147 if (!done)
148 {
151 done = true;
152 }
153}
void buf_alloc(struct Buffer *buf, size_t new_size)
Make sure a buffer can store at least new_size bytes.
Definition buffer.c:337
struct Buffer LastDir
Browser: previous selected directory.
struct Buffer LastDirBackup
Browser: backup copy of the current directory.
#define PATH_MAX
Definition mutt.h:49
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_browser_cleanup()

void mutt_browser_cleanup ( void )

Clean up working Buffers.

Definition at line 158 of file dlg_browser.c.

159{
162}
void buf_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
Definition buffer.c:377
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ link_is_dir()

bool link_is_dir ( const char * folder,
const char * path )

Does this symlink point to a directory?

Parameters
folderFolder
pathLink name
Return values
trueLinks to a directory
falseOtherwise

Definition at line 171 of file dlg_browser.c.

172{
173 struct stat st = { 0 };
174 bool rc = false;
175
176 struct Buffer *fullpath = buf_pool_get();
177 buf_concat_path(fullpath, folder, path);
178
179 if (stat(buf_string(fullpath), &st) == 0)
180 rc = S_ISDIR(st.st_mode);
181
182 buf_pool_release(&fullpath);
183
184 return rc;
185}
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
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition buffer.h:96
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
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ browser_add_folder()

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.

Parameters
menuMenu to use
stateBrowser state
nameName of folder
descDescription of folder
ststat info for the folder
mMailbox
dataData to associate with the folder

Definition at line 197 of file dlg_browser.c.

200{
201 if ((!menu || state->is_mailbox_list) && m && !m->visible)
202 {
203 return;
204 }
205
206 struct FolderFile ff = { 0 };
207
208 if (st)
209 {
210 ff.mode = st->st_mode;
211 ff.mtime = st->st_mtime;
212 ff.size = st->st_size;
213 ff.gid = st->st_gid;
214 ff.uid = st->st_uid;
215 ff.nlink = st->st_nlink;
216 ff.local = true;
217 }
218 else
219 {
220 ff.local = false;
221 }
222
223 if (m)
224 {
225 ff.has_mailbox = true;
226 ff.gen = m->gen;
227 ff.has_new_mail = m->has_new;
228 ff.msg_count = m->msg_count;
229 ff.msg_unread = m->msg_unread;
230 ff.notify_user = m->notify_user;
232 }
233
234 ff.name = mutt_str_dup(name);
235 ff.desc = mutt_str_dup(desc ? desc : name);
236 ff.imap = false;
237 if (OptNews)
238 ff.nd = data;
239
240 ARRAY_ADD(&state->entry, ff);
241}
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition array.h:157
bool OptNews
(pseudo) used to change reader mode
Definition globals.c:53
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition string.c:257
bool is_mailbox_list
Viewing mailboxes.
Definition lib.h:149
struct BrowserEntryArray entry
Array of files / dirs / mailboxes.
Definition lib.h:146
Browser entry representing a folder/dir.
Definition lib.h:79
bool imap
This is an IMAP folder.
Definition lib.h:96
bool has_mailbox
This is a mailbox.
Definition lib.h:99
char * name
Name of file/dir/mailbox.
Definition lib.h:87
uid_t uid
File's User ID.
Definition lib.h:83
gid_t gid
File's Group ID.
Definition lib.h:84
bool has_new_mail
true if mailbox has "new mail"
Definition lib.h:90
bool poll_new_mail
Check mailbox for new mail.
Definition lib.h:102
bool notify_user
User will be notified of new mail.
Definition lib.h:101
nlink_t nlink
Number of hard links.
Definition lib.h:85
char * desc
Description of mailbox.
Definition lib.h:88
struct NntpMboxData * nd
Extra NNTP data.
Definition lib.h:104
off_t size
File size.
Definition lib.h:81
int gen
Unique id, used for (un)sorting.
Definition lib.h:106
bool local
Folder is on local filesystem.
Definition lib.h:100
time_t mtime
Modification time.
Definition lib.h:82
int msg_count
total number of messages
Definition lib.h:91
mode_t mode
File permissions.
Definition lib.h:80
int msg_unread
number of unread messages
Definition lib.h:92
bool has_new
Mailbox has new mail.
Definition mailbox.h:84
int msg_count
Total number of messages.
Definition mailbox.h:87
bool poll_new_mail
Check for new mail.
Definition mailbox.h:114
bool notify_user
Notify the user of new mail.
Definition mailbox.h:112
bool visible
True if a result of "mailboxes".
Definition mailbox.h:129
int msg_unread
Number of unread messages.
Definition mailbox.h:88
int gen
Generation number, for sorting.
Definition mailbox.h:146
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ init_state()

void init_state ( struct BrowserState * state)

Initialise a browser state.

Parameters
stateBrowserState to initialise

Definition at line 247 of file dlg_browser.c.

248{
249 ARRAY_INIT(&state->entry);
250 ARRAY_RESERVE(&state->entry, 256);
251 state->imap_browse = false;
252}
#define ARRAY_RESERVE(head, n)
Reserve memory for the array.
Definition array.h:191
#define ARRAY_INIT(head)
Initialize an array.
Definition array.h:65
bool imap_browse
IMAP folder.
Definition lib.h:147
+ Here is the caller graph for this function:

◆ examine_directory()

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.

Parameters
mMailbox
menuCurrent Menu
stateState of browser
dirnameDirectory
prefixFiles/newsgroups must match this prefix
Return values
0Success
-1Error

Definition at line 264 of file dlg_browser.c.

266{
267 int rc = -1;
268 struct Buffer *buf = buf_pool_get();
269 if (OptNews)
270 {
272
273 init_state(state);
274
275 const struct Regex *c_mask = cs_subset_regex(NeoMutt->sub, "mask");
276 for (unsigned int i = 0; i < adata->groups_num; i++)
277 {
278 struct NntpMboxData *mdata = adata->groups_list[i];
279 if (!mdata)
280 continue;
281 if (prefix && *prefix && !mutt_str_startswith(mdata->group, prefix))
282 continue;
283 if (!mutt_regex_match(c_mask, mdata->group))
284 {
285 continue;
286 }
287 browser_add_folder(menu, state, mdata->group, NULL, NULL, NULL, mdata);
288 }
289 }
290 else
291 {
292 struct stat st = { 0 };
293 DIR *dir = NULL;
294 struct dirent *de = NULL;
295
296 // Work on a mutable copy to avoid modifying the const dirname parameter
297 char dstrbuf[PATH_MAX] = { 0 };
298 mutt_str_copy(dstrbuf, dirname, sizeof(dstrbuf));
299
300 while (stat(dstrbuf, &st) == -1)
301 {
302 if (errno == ENOENT)
303 {
304 /* The last used directory is deleted, try to use the parent dir. */
305 char *c = strrchr(dstrbuf, '/');
306
307 if (c && (c > dstrbuf))
308 {
309 *c = '\0';
310 continue;
311 }
312 }
313 mutt_perror("%s", dstrbuf);
314 goto ed_out;
315 }
316
317 if (!S_ISDIR(st.st_mode))
318 {
319 mutt_error(_("%s is not a directory"), dstrbuf);
320 goto ed_out;
321 }
322
323 if (m)
325
326 dir = mutt_file_opendir(dstrbuf, MUTT_OPENDIR_NONE);
327 if (!dir)
328 {
329 mutt_perror("%s", dstrbuf);
330 goto ed_out;
331 }
332
333 init_state(state);
334
335 struct MailboxArray ma = neomutt_mailboxes_get(NeoMutt, MUTT_MAILBOX_ANY);
336
337 const struct Regex *c_mask = cs_subset_regex(NeoMutt->sub, "mask");
338 while ((de = readdir(dir)))
339 {
340 if (mutt_str_equal(de->d_name, "."))
341 continue; /* we don't need . */
342
343 if (prefix && *prefix && !mutt_str_startswith(de->d_name, prefix))
344 {
345 continue;
346 }
347 if (!mutt_regex_match(c_mask, de->d_name))
348 {
349 continue;
350 }
351
352 buf_concat_path(buf, dstrbuf, de->d_name);
353 if (lstat(buf_string(buf), &st) == -1)
354 continue;
355
356 /* No size for directories or symlinks */
357 if (S_ISDIR(st.st_mode) || S_ISLNK(st.st_mode))
358 st.st_size = 0;
359 else if (!S_ISREG(st.st_mode))
360 continue;
361
362 struct Mailbox **mp = NULL;
363 ARRAY_FOREACH(mp, &ma)
364 {
365 if (mutt_str_equal(buf_string(buf), mailbox_path(*mp)))
366 break;
367 }
368
369 struct Mailbox *m_match = mp ? *mp : NULL;
370 if (m_match && m && m->poll_new_mail && mutt_str_equal(m_match->realpath, m->realpath))
371 {
372 m_match->msg_count = m->msg_count;
373 m_match->msg_unread = m->msg_unread;
374 }
375 browser_add_folder(menu, state, de->d_name, NULL, &st, m_match, NULL);
376 }
377 ARRAY_FREE(&ma); // Clean up the ARRAY, but not the Mailboxes
378 closedir(dir);
379 }
380 browser_sort(state);
381 rc = 0;
382ed_out:
383 buf_pool_release(&buf);
384 return rc;
385}
#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 browser_sort(struct BrowserState *state)
Sort the entries in the browser.
Definition sort.c:186
const struct Regex * cs_subset_regex(const struct ConfigSubset *sub, const char *name)
Get a regex config item by name.
Definition helpers.c:217
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox's path string.
Definition mailbox.h:213
@ MUTT_MAILBOX_ANY
Match any Mailbox type.
Definition mailbox.h:41
void init_state(struct BrowserState *state)
Initialise a browser state.
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.
DIR * mutt_file_opendir(const char *path, enum MuttOpenDirMode mode)
Open a directory.
Definition file.c:535
@ MUTT_OPENDIR_NONE
Plain opendir()
Definition file.h:63
#define mutt_error(...)
Definition logging2.h:94
#define mutt_perror(...)
Definition logging2.h:95
#define _(a)
Definition message.h:28
bool mutt_regex_match(const struct Regex *regex, const char *str)
Shorthand to mutt_regex_capture()
Definition regex.c:614
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition string.c:665
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
Definition string.c:234
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
int mutt_mailbox_check(struct Mailbox *m_cur, CheckStatsFlags flags)
Check all all Mailboxes for new mail.
#define MUTT_MAILBOX_CHECK_NO_FLAGS
No flags are set.
Definition mxapi.h:49
struct MailboxArray neomutt_mailboxes_get(struct NeoMutt *n, enum MailboxType type)
Get an Array of matching Mailboxes.
Definition neomutt.c:526
struct NntpAccountData * CurrentNewsSrv
Current NNTP news server.
Definition nntp.c:74
void * adata
Private data (for Mailbox backends)
Definition account.h:42
A mailbox.
Definition mailbox.h:78
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition mailbox.h:80
void * mdata
Driver specific data.
Definition mailbox.h:131
Container for Accounts, Notifications.
Definition neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:49
NNTP-specific Account data -.
Definition adata.h:36
struct NntpMboxData ** groups_list
List of newsgroups.
Definition adata.h:60
unsigned int groups_num
Number of newsgroups.
Definition adata.h:58
NNTP-specific Mailbox data -.
Definition mdata.h:34
struct NntpAccountData * adata
Account data.
Definition mdata.h:48
Cached regular expression.
Definition regex3.h:85
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ examine_mailboxes()

int examine_mailboxes ( struct Mailbox * m,
struct Menu * menu,
struct BrowserState * state )

Get list of mailboxes/subscribed newsgroups.

Parameters
mMailbox
menuCurrent menu
stateState of browser
Return values
0Success
-1Error

Definition at line 395 of file dlg_browser.c.

396{
397 struct stat st = { 0 };
398 struct Buffer *md = NULL;
399 struct Buffer *mailbox = NULL;
400
401 if (OptNews)
402 {
404
405 init_state(state);
406
407 const bool c_show_only_unread = cs_subset_bool(NeoMutt->sub, "show_only_unread");
408 for (unsigned int i = 0; i < adata->groups_num; i++)
409 {
410 struct NntpMboxData *mdata = adata->groups_list[i];
411 if (mdata && (mdata->has_new_mail ||
412 (mdata->subscribed && (mdata->unread || !c_show_only_unread))))
413 {
414 browser_add_folder(menu, state, mdata->group, NULL, NULL, NULL, mdata);
415 }
416 }
417 }
418 else
419 {
420 init_state(state);
421
423 return -1;
424
425 mailbox = buf_pool_get();
426 md = buf_pool_get();
427
429
430 struct MailboxArray ma = neomutt_mailboxes_get(NeoMutt, MUTT_MAILBOX_ANY);
431 const bool c_browser_abbreviate_mailboxes = cs_subset_bool(NeoMutt->sub, "browser_abbreviate_mailboxes");
432
433 struct Mailbox **mp = NULL;
434 ARRAY_FOREACH(mp, &ma)
435 {
436 struct Mailbox *m_match = *mp;
437
438 if (m && m->poll_new_mail && mutt_str_equal(m_match->realpath, m->realpath))
439 {
440 m_match->msg_count = m->msg_count;
441 m_match->msg_unread = m->msg_unread;
442 }
443
444 buf_strcpy(mailbox, mailbox_path(m_match));
445 if (c_browser_abbreviate_mailboxes)
446 pretty_mailbox(mailbox);
447
448 switch (m_match->type)
449 {
450 case MUTT_IMAP:
451 case MUTT_POP:
452 browser_add_folder(menu, state, buf_string(mailbox), m_match->name,
453 NULL, m_match, NULL);
454 continue;
455 case MUTT_NOTMUCH:
456 case MUTT_NNTP:
457 browser_add_folder(menu, state, mailbox_path(m_match), m_match->name,
458 NULL, m_match, NULL);
459 continue;
460 default: /* Continue */
461 break;
462 }
463
464 if (lstat(mailbox_path(m_match), &st) == -1)
465 continue;
466
467 if ((!S_ISREG(st.st_mode)) && (!S_ISDIR(st.st_mode)) && (!S_ISLNK(st.st_mode)))
468 continue;
469
470 if (m_match->type == MUTT_MAILDIR)
471 {
472 struct stat st2 = { 0 };
473
474 buf_printf(md, "%s/new", mailbox_path(m_match));
475 if (stat(buf_string(md), &st) < 0)
476 st.st_mtime = 0;
477 buf_printf(md, "%s/cur", mailbox_path(m_match));
478 if (stat(buf_string(md), &st2) < 0)
479 st2.st_mtime = 0;
480 if (st2.st_mtime > st.st_mtime)
481 st.st_mtime = st2.st_mtime;
482 }
483
484 browser_add_folder(menu, state, buf_string(mailbox), m_match->name, &st, m_match, NULL);
485 }
486 ARRAY_FREE(&ma); // Clean up the ARRAY, but not the Mailboxes
487 }
488 browser_sort(state);
489
490 buf_pool_release(&mailbox);
491 buf_pool_release(&md);
492 return 0;
493}
#define ARRAY_EMPTY(head)
Check if an array is empty.
Definition array.h:74
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition buffer.c:161
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition buffer.c:395
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition helpers.c:47
@ MUTT_NOTMUCH
'Notmuch' (virtual) Mailbox type
Definition mailbox.h:50
@ MUTT_POP
'POP3' Mailbox type
Definition mailbox.h:51
@ MUTT_NNTP
'NNTP' (Usenet) Mailbox type
Definition mailbox.h:48
@ MUTT_IMAP
'IMAP' Mailbox type
Definition mailbox.h:49
@ MUTT_MAILDIR
'Maildir' Mailbox type
Definition mailbox.h:47
void pretty_mailbox(struct Buffer *buf)
Shorten a mailbox path using '~' or '='.
Definition muttlib.c:428
enum MailboxType type
Mailbox type.
Definition mailbox.h:101
char * name
A short name for the Mailbox.
Definition mailbox.h:81
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:

◆ browser_highlight_default()

void browser_highlight_default ( struct BrowserState * state,
struct Menu * menu )

Decide which browser item should be highlighted.

Parameters
stateBrowser state
menuCurrent Menu

This function takes a menu and a state and defines the current entry that should be highlighted.

Definition at line 560 of file dlg_browser.c.

561{
562 menu->top = 0;
563 /* Reset menu position to 1.
564 * We do not risk overflow as the init_menu function changes
565 * current if it is bigger than state->entrylen. */
566 if (!ARRAY_EMPTY(&state->entry) &&
567 (mutt_str_equal(ARRAY_FIRST(&state->entry)->desc, "..") ||
568 mutt_str_equal(ARRAY_FIRST(&state->entry)->desc, "../")))
569 {
570 /* Skip the first entry, unless there's only one entry. */
571 menu_set_index(menu, (menu->max > 1));
572 }
573 else
574 {
575 menu_set_index(menu, 0);
576 }
577}
#define ARRAY_FIRST(head)
Convenience method to get the first element.
Definition array.h:136
MenuRedrawFlags menu_set_index(struct Menu *menu, int index)
Set the current selection in the Menu.
Definition menu.c:178
int top
Entry that is the top of the current page.
Definition lib.h:92
int max
Number of entries in the menu.
Definition lib.h:82
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ init_menu()

void init_menu ( struct BrowserState * state,
struct Menu * menu,
struct Mailbox * m,
struct MuttWindow * sbar )

Set up a new menu.

Parameters
stateBrowser state
menuCurrent menu
mMailbox
sbarStatus bar

Definition at line 586 of file dlg_browser.c.

588{
589 char title[256] = { 0 };
590 menu->max = ARRAY_SIZE(&state->entry);
591
592 int index = menu_get_index(menu);
593 if (index >= menu->max)
594 menu_set_index(menu, menu->max - 1);
595 if (index < 0)
596 menu_set_index(menu, 0);
597 if (menu->top > index)
598 menu->top = 0;
599
600 menu->num_tagged = 0;
601
602 if (OptNews)
603 {
604 if (state->is_mailbox_list)
605 {
606 snprintf(title, sizeof(title), _("Subscribed newsgroups"));
607 }
608 else
609 {
610 snprintf(title, sizeof(title), _("Newsgroups on server [%s]"),
611 CurrentNewsSrv->conn->account.host);
612 }
613 }
614 else
615 {
616 if (state->is_mailbox_list)
617 {
618 snprintf(title, sizeof(title), _("Mailboxes [%d]"),
620 }
621 else
622 {
623 struct Buffer *path = buf_pool_get();
624 buf_copy(path, &LastDir);
625 pretty_mailbox(path);
626 const struct Regex *c_mask = cs_subset_regex(NeoMutt->sub, "mask");
627 const bool c_imap_list_subscribed = cs_subset_bool(NeoMutt->sub, "imap_list_subscribed");
628 if (state->imap_browse && c_imap_list_subscribed)
629 {
630 snprintf(title, sizeof(title), _("Subscribed [%s], File mask: %s"),
631 buf_string(path), NONULL(c_mask ? c_mask->pattern : NULL));
632 }
633 else
634 {
635 snprintf(title, sizeof(title), _("Directory [%s], File mask: %s"),
636 buf_string(path), NONULL(c_mask ? c_mask->pattern : NULL));
637 }
638 buf_pool_release(&path);
639 }
640 }
641 sbar_set_title(sbar, title);
642
643 /* Browser tracking feature.
644 * The goal is to highlight the good directory if LastDir is the parent dir
645 * of LastDirBackup (this occurs mostly when one hit "../"). It should also work
646 * properly when the user is in examine_mailboxes-mode. */
648 {
649 char target_dir[PATH_MAX] = { 0 };
650
651 /* Check what kind of dir LastDirBackup is. */
653 {
654 mutt_str_copy(target_dir, buf_string(&LastDirBackup), sizeof(target_dir));
655 imap_clean_path(target_dir, sizeof(target_dir));
656 }
657 else
658 {
659 const char *slash = strrchr(buf_string(&LastDirBackup), '/');
660 if (slash)
661 mutt_str_copy(target_dir, slash + 1, sizeof(target_dir));
662 else
663 mutt_str_copy(target_dir, buf_string(&LastDirBackup), sizeof(target_dir));
664 }
665
666 /* If we get here, it means that LastDir is the parent directory of
667 * LastDirBackup. I.e., we're returning from a subdirectory, and we want
668 * to position the cursor on the directory we're returning from. */
669 bool matched = false;
670 struct FolderFile *ff = NULL;
671 ARRAY_FOREACH(ff, &state->entry)
672 {
673 if (mutt_str_equal(ff->name, target_dir))
674 {
675 menu_set_index(menu, ARRAY_FOREACH_IDX_ff);
676 matched = true;
677 break;
678 }
679 }
680 if (!matched)
681 browser_highlight_default(state, menu);
682 }
683 else
684 {
685 browser_highlight_default(state, menu);
686 }
687
689}
#define ARRAY_SIZE(head)
The number of elements stored.
Definition array.h:87
size_t buf_copy(struct Buffer *dst, const struct Buffer *src)
Copy a Buffer's contents to another Buffer.
Definition buffer.c:601
void browser_highlight_default(struct BrowserState *state, struct Menu *menu)
Decide which browser item should be highlighted.
enum MailboxType imap_path_probe(const char *path, const struct stat *st)
Is this an IMAP Mailbox?
Definition imap.c:2546
void imap_clean_path(char *path, size_t plen)
Cleans an IMAP path using imap_fix_path.
Definition util.c:192
#define MENU_REDRAW_FULL
Redraw everything.
Definition lib.h:60
void menu_queue_redraw(struct Menu *menu, MenuRedrawFlags redraw)
Queue a request for a redraw.
Definition menu.c:188
int menu_get_index(struct Menu *menu)
Get the current selection in the Menu.
Definition menu.c:164
void sbar_set_title(struct MuttWindow *win, const char *title)
Set the title for the Simple Bar.
Definition sbar.c:227
#define NONULL(x)
Definition string2.h:44
int num_tagged
Number of tagged entries.
Definition lib.h:95
char * pattern
printable version
Definition regex3.h:86
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_browser_select_dir()

void mutt_browser_select_dir ( const char * f)

Remember the last directory selected.

Parameters
fDirectory name to save

This function helps the browser to know which directory has been selected. It should be called anywhere a confirm hit is done to open a new directory/file which is a maildir/mbox.

We could check if the sort method is appropriate with this feature.

Definition at line 834 of file dlg_browser.c.

835{
836 init_lastdir();
837
839
840 /* Method that will fetch the parent path depending on the type of the path. */
841 char buf[PATH_MAX] = { 0 };
842 mutt_get_parent_path(buf_string(&LastDirBackup), buf, sizeof(buf));
843 buf_strcpy(&LastDir, buf);
844}
static void init_lastdir(void)
Initialise the browser directories.
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
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ FolderHelp

const struct Mapping FolderHelp[]
static
Initial value:
= {
{ N_("Exit"), OP_EXIT },
{ N_("Chdir"), OP_CHANGE_DIRECTORY },
{ N_("Goto"), OP_BROWSER_GOTO_FOLDER },
{ N_("Mask"), OP_ENTER_MASK },
{ N_("Help"), OP_HELP },
{ NULL, 0 },
}
#define N_(a)
Definition message.h:32

Help Bar for the File/Dir/Mailbox browser dialog.

Definition at line 109 of file dlg_browser.c.

109 {
110 // clang-format off
111 { N_("Exit"), OP_EXIT },
112 { N_("Chdir"), OP_CHANGE_DIRECTORY },
113 { N_("Goto"), OP_BROWSER_GOTO_FOLDER },
114 { N_("Mask"), OP_ENTER_MASK },
115 { N_("Help"), OP_HELP },
116 { NULL, 0 },
117 // clang-format on
118};

◆ FolderNewsHelp

const struct Mapping FolderNewsHelp[]
static
Initial value:
= {
{ N_("Exit"), OP_EXIT },
{ N_("List"), OP_TOGGLE_MAILBOXES },
{ N_("Subscribe"), OP_BROWSER_SUBSCRIBE },
{ N_("Unsubscribe"), OP_BROWSER_UNSUBSCRIBE },
{ N_("Catchup"), OP_CATCHUP },
{ N_("Mask"), OP_ENTER_MASK },
{ N_("Help"), OP_HELP },
{ NULL, 0 },
}

Help Bar for the NNTP Mailbox browser dialog.

Definition at line 121 of file dlg_browser.c.

121 {
122 // clang-format off
123 { N_("Exit"), OP_EXIT },
124 { N_("List"), OP_TOGGLE_MAILBOXES },
125 { N_("Subscribe"), OP_BROWSER_SUBSCRIBE },
126 { N_("Unsubscribe"), OP_BROWSER_UNSUBSCRIBE },
127 { N_("Catchup"), OP_CATCHUP },
128 { N_("Mask"), OP_ENTER_MASK },
129 { N_("Help"), OP_HELP },
130 { NULL, 0 },
131 // clang-format on
132};

◆ LastDir

struct Buffer LastDir = { 0 }

Browser: previous selected directory.

Definition at line 135 of file dlg_browser.c.

135{ 0 };

◆ LastDirBackup

struct Buffer LastDirBackup = { 0 }

Browser: backup copy of the current directory.

Definition at line 137 of file dlg_browser.c.

137{ 0 };