NeoMutt  2024-04-16-36-g75b6fb
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 <assert.h>
#include <dirent.h>
#include <errno.h>
#include <grp.h>
#include <limits.h>
#include <locale.h>
#include <pwd.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <time.h>
#include "mutt/lib.h"
#include "config/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 "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 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?
 
long folder_date_num (const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
 Browser: Last modified (strftime) - Implements ExpandoRenderData::get_number() -.
 
void folder_date (const struct ExpandoNode *node, void *data, MuttFormatFlags flags, int max_cols, struct Buffer *buf)
 Browser: Last modified (strftime) - Implements ExpandoRenderData::get_string() -.
 
void folder_space (const struct ExpandoNode *node, void *data, MuttFormatFlags flags, int max_cols, struct Buffer *buf)
 Fixed whitespace - Implements ExpandoRenderData::get_string() -.
 
long folder_a_num (const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
 Browser: Alert for new mail - Implements ExpandoRenderData::get_number() -.
 
long folder_C_num (const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
 Browser: Index number - Implements ExpandoRenderData::get_number() -.
 
long folder_d_num (const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
 Browser: Last modified - Implements ExpandoRenderData::get_number() -.
 
void folder_d (const struct ExpandoNode *node, void *data, MuttFormatFlags flags, int max_cols, struct Buffer *buf)
 Browser: Last modified - Implements ExpandoRenderData::get_string() -.
 
long folder_D_num (const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
 Browser: Last modified ($date_format) - Implements ExpandoRenderData::get_number() -.
 
void folder_D (const struct ExpandoNode *node, void *data, MuttFormatFlags flags, int max_cols, struct Buffer *buf)
 Browser: Last modified ($date_format) - Implements ExpandoRenderData::get_string() -.
 
void folder_f (const struct ExpandoNode *node, void *data, MuttFormatFlags flags, int max_cols, struct Buffer *buf)
 Browser: Filename - Implements ExpandoRenderData::get_string() -.
 
void folder_F (const struct ExpandoNode *node, void *data, MuttFormatFlags flags, int max_cols, struct Buffer *buf)
 Browser: File permissions - Implements ExpandoRenderData::get_string() -.
 
void folder_g (const struct ExpandoNode *node, void *data, MuttFormatFlags flags, int max_cols, struct Buffer *buf)
 Browser: Group name - Implements ExpandoRenderData::get_string() -.
 
void folder_i (const struct ExpandoNode *node, void *data, MuttFormatFlags flags, int max_cols, struct Buffer *buf)
 Browser: Description - Implements ExpandoRenderData::get_string() -.
 
long folder_l_num (const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
 Browser: Hard links - Implements ExpandoRenderData::get_number() -.
 
void folder_l (const struct ExpandoNode *node, void *data, MuttFormatFlags flags, int max_cols, struct Buffer *buf)
 Browser: Hard links - Implements ExpandoRenderData::get_string() -.
 
long folder_m_num (const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
 Browser: Number of messages - Implements ExpandoRenderData::get_number() -.
 
void folder_m (const struct ExpandoNode *node, void *data, MuttFormatFlags flags, int max_cols, struct Buffer *buf)
 Browser: Number of messages - Implements ExpandoRenderData::get_string() -.
 
long folder_n_num (const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
 Browser: Number of unread messages - Implements ExpandoRenderData::get_number() -.
 
void folder_n (const struct ExpandoNode *node, void *data, MuttFormatFlags flags, int max_cols, struct Buffer *buf)
 Browser: Number of unread messages - Implements ExpandoRenderData::get_string() -.
 
long folder_N_num (const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
 Browser: New mail flag - Implements ExpandoRenderData::get_number() -.
 
void folder_N (const struct ExpandoNode *node, void *data, MuttFormatFlags flags, int max_cols, struct Buffer *buf)
 Browser: New mail flag - Implements ExpandoRenderData::get_string() -.
 
long folder_p_num (const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
 Browser: Poll for new mail - Implements ExpandoRenderData::get_number() -.
 
long folder_s_num (const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
 Browser: Size in bytes - Implements ExpandoRenderData::get_number() -.
 
void folder_s (const struct ExpandoNode *node, void *data, MuttFormatFlags flags, int max_cols, struct Buffer *buf)
 Browser: Size in bytes - Implements ExpandoRenderData::get_string() -.
 
long folder_t_num (const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
 Browser: Is Tagged - Implements ExpandoRenderData::get_number() -.
 
void folder_t (const struct ExpandoNode *node, void *data, MuttFormatFlags flags, int max_cols, struct Buffer *buf)
 Browser: Is Tagged - Implements ExpandoRenderData::get_string() -.
 
void folder_u (const struct ExpandoNode *node, void *data, MuttFormatFlags flags, int max_cols, struct Buffer *buf)
 Browser: Owner name - Implements ExpandoRenderData::get_string() -.
 
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, struct Menu *menu)
 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

const struct ExpandoRenderData FolderRenderData []
 Callbacks for Browser Expandos.
 
const struct ExpandoRenderData GroupIndexRenderData []
 Callbacks for Nntp Browser Expandos.
 
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 149 of file dlg_browser.c.

150{
151 static bool done = false;
152 if (!done)
153 {
156 done = true;
157 }
158}
void buf_alloc(struct Buffer *buf, size_t new_size)
Make sure a buffer can store at least new_size bytes.
Definition: buffer.c:336
struct Buffer LastDir
Browser: previous selected directory.
Definition: dlg_browser.c:140
struct Buffer LastDirBackup
Browser: backup copy of the current directory.
Definition: dlg_browser.c:142
#define PATH_MAX
Definition: mutt.h:42
+ 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 163 of file dlg_browser.c.

164{
167}
void buf_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
Definition: buffer.c:376
+ 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 176 of file dlg_browser.c.

177{
178 struct stat st = { 0 };
179 bool rc = false;
180
181 struct Buffer *fullpath = buf_pool_get();
182 buf_concat_path(fullpath, folder, path);
183
184 if (stat(buf_string(fullpath), &st) == 0)
185 rc = S_ISDIR(st.st_mode);
186
187 buf_pool_release(&fullpath);
188
189 return rc;
190}
size_t buf_concat_path(struct Buffer *buf, const char *dir, const char *fname)
Join a directory name and a filename.
Definition: buffer.c:508
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:81
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:94
String manipulation buffer.
Definition: buffer.h:36
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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 638 of file dlg_browser.c.

641{
642 if ((!menu || state->is_mailbox_list) && m && !m->visible)
643 {
644 return;
645 }
646
647 struct FolderFile ff = { 0 };
648
649 if (st)
650 {
651 ff.mode = st->st_mode;
652 ff.mtime = st->st_mtime;
653 ff.size = st->st_size;
654 ff.gid = st->st_gid;
655 ff.uid = st->st_uid;
656 ff.nlink = st->st_nlink;
657 ff.local = true;
658 }
659 else
660 {
661 ff.local = false;
662 }
663
664 if (m)
665 {
666 ff.has_mailbox = true;
667 ff.gen = m->gen;
668 ff.has_new_mail = m->has_new;
669 ff.msg_count = m->msg_count;
670 ff.msg_unread = m->msg_unread;
671 ff.notify_user = m->notify_user;
673 }
674
675 ff.name = mutt_str_dup(name);
676 ff.desc = mutt_str_dup(desc ? desc : name);
677 ff.imap = false;
678 if (OptNews)
679 ff.nd = data;
680
681 ARRAY_ADD(&state->entry, ff);
682}
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition: array.h:156
bool OptNews
(pseudo) used to change reader mode
Definition: globals.c:70
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:253
bool is_mailbox_list
Viewing mailboxes.
Definition: lib.h:148
struct BrowserEntryArray entry
Array of files / dirs / mailboxes.
Definition: lib.h:145
Browser entry representing a folder/dir.
Definition: lib.h:78
bool imap
This is an IMAP folder.
Definition: lib.h:95
bool has_mailbox
This is a mailbox.
Definition: lib.h:98
char * name
Name of file/dir/mailbox.
Definition: lib.h:86
uid_t uid
File's User ID.
Definition: lib.h:82
gid_t gid
File's Group ID.
Definition: lib.h:83
bool has_new_mail
true if mailbox has "new mail"
Definition: lib.h:89
bool poll_new_mail
Check mailbox for new mail.
Definition: lib.h:101
bool notify_user
User will be notified of new mail.
Definition: lib.h:100
nlink_t nlink
Number of hard links.
Definition: lib.h:84
char * desc
Description of mailbox.
Definition: lib.h:87
struct NntpMboxData * nd
Extra NNTP data.
Definition: lib.h:103
off_t size
File size.
Definition: lib.h:80
int gen
Unique id, used for (un)sorting.
Definition: lib.h:105
time_t mtime
Modification time.
Definition: lib.h:81
int msg_count
total number of messages
Definition: lib.h:90
mode_t mode
File permissions.
Definition: lib.h:79
int msg_unread
number of unread messages
Definition: lib.h:91
bool has_new
Mailbox has new mail.
Definition: mailbox.h:85
int msg_count
Total number of messages.
Definition: mailbox.h:88
bool poll_new_mail
Check for new mail.
Definition: mailbox.h:115
bool notify_user
Notify the user of new mail.
Definition: mailbox.h:113
bool visible
True if a result of "mailboxes".
Definition: mailbox.h:130
int msg_unread
Number of unread messages.
Definition: mailbox.h:89
int gen
Generation number, for sorting.
Definition: mailbox.h:147
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ init_state()

void init_state ( struct BrowserState state,
struct Menu menu 
)

Initialise a browser state.

Parameters
stateBrowserState to initialise
menuCurrent menu

Definition at line 689 of file dlg_browser.c.

690{
691 ARRAY_INIT(&state->entry);
692 ARRAY_RESERVE(&state->entry, 256);
693 state->imap_browse = false;
694
695 if (menu)
696 {
697 menu->mdata = &state->entry;
698 menu->mdata_free = NULL; // Menu doesn't own the data
699 }
700}
#define ARRAY_RESERVE(head, num)
Reserve memory for the array.
Definition: array.h:189
#define ARRAY_INIT(head)
Initialize an array.
Definition: array.h:65
bool imap_browse
IMAP folder.
Definition: lib.h:146
void(* mdata_free)(struct Menu *menu, void **ptr)
Definition: lib.h:161
void * mdata
Private data.
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 712 of file dlg_browser.c.

714{
715 int rc = -1;
716 struct Buffer *buf = buf_pool_get();
717 if (OptNews)
718 {
720
721 init_state(state, menu);
722
723 const struct Regex *c_mask = cs_subset_regex(NeoMutt->sub, "mask");
724 for (unsigned int i = 0; i < adata->groups_num; i++)
725 {
726 struct NntpMboxData *mdata = adata->groups_list[i];
727 if (!mdata)
728 continue;
729 if (prefix && *prefix && !mutt_str_startswith(mdata->group, prefix))
730 continue;
731 if (!mutt_regex_match(c_mask, mdata->group))
732 {
733 continue;
734 }
735 browser_add_folder(menu, state, mdata->group, NULL, NULL, NULL, mdata);
736 }
737 }
738 else
739 {
740 struct stat st = { 0 };
741 DIR *dir = NULL;
742 struct dirent *de = NULL;
743
744 while (stat(dirname, &st) == -1)
745 {
746 if (errno == ENOENT)
747 {
748 /* The last used directory is deleted, try to use the parent dir. */
749 char *c = strrchr(dirname, '/');
750
751 if (c && (c > dirname))
752 {
753 *c = '\0';
754 continue;
755 }
756 }
757 mutt_perror("%s", dirname);
758 goto ed_out;
759 }
760
761 if (!S_ISDIR(st.st_mode))
762 {
763 mutt_error(_("%s is not a directory"), dirname);
764 goto ed_out;
765 }
766
767 if (m)
769
770 dir = mutt_file_opendir(dirname, MUTT_OPENDIR_NONE);
771 if (!dir)
772 {
773 mutt_perror("%s", dirname);
774 goto ed_out;
775 }
776
777 init_state(state, menu);
778
779 struct MailboxList ml = STAILQ_HEAD_INITIALIZER(ml);
781
782 const struct Regex *c_mask = cs_subset_regex(NeoMutt->sub, "mask");
783 while ((de = readdir(dir)))
784 {
785 if (mutt_str_equal(de->d_name, "."))
786 continue; /* we don't need . */
787
788 if (prefix && *prefix && !mutt_str_startswith(de->d_name, prefix))
789 {
790 continue;
791 }
792 if (!mutt_regex_match(c_mask, de->d_name))
793 {
794 continue;
795 }
796
797 buf_concat_path(buf, dirname, de->d_name);
798 if (lstat(buf_string(buf), &st) == -1)
799 continue;
800
801 /* No size for directories or symlinks */
802 if (S_ISDIR(st.st_mode) || S_ISLNK(st.st_mode))
803 st.st_size = 0;
804 else if (!S_ISREG(st.st_mode))
805 continue;
806
807 struct MailboxNode *np = NULL;
808 STAILQ_FOREACH(np, &ml, entries)
809 {
811 break;
812 }
813
814 if (np && m && m->poll_new_mail && mutt_str_equal(np->mailbox->realpath, m->realpath))
815 {
816 np->mailbox->msg_count = m->msg_count;
817 np->mailbox->msg_unread = m->msg_unread;
818 }
819 browser_add_folder(menu, state, de->d_name, NULL, &st, np ? np->mailbox : NULL, NULL);
820 }
822 closedir(dir);
823 }
824 browser_sort(state);
825 rc = 0;
826ed_out:
827 buf_pool_release(&buf);
828 return rc;
829}
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:218
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox's path string.
Definition: mailbox.h:223
@ MUTT_MAILBOX_ANY
Match any Mailbox type.
Definition: mailbox.h:42
void init_state(struct BrowserState *state, struct Menu *menu)
Initialise a browser state.
Definition: dlg_browser.c:689
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.
Definition: dlg_browser.c:638
DIR * mutt_file_opendir(const char *path, enum MuttOpenDirMode mode)
Open a directory.
Definition: file.c:640
@ MUTT_OPENDIR_NONE
Plain opendir()
Definition: file.h:74
#define mutt_error(...)
Definition: logging2.h:92
#define mutt_perror(...)
Definition: logging2.h:93
#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:654
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
Definition: string.c:230
int mutt_mailbox_check(struct Mailbox *m_cur, CheckStatsFlags flags)
Check all all Mailboxes for new mail.
Definition: mutt_mailbox.c:168
#define MUTT_MAILBOX_CHECK_NO_FLAGS
No flags are set.
Definition: mxapi.h:53
void neomutt_mailboxlist_clear(struct MailboxList *ml)
Free a Mailbox List.
Definition: neomutt.c:163
size_t neomutt_mailboxlist_get_all(struct MailboxList *head, struct NeoMutt *n, enum MailboxType type)
Get a List of all Mailboxes.
Definition: neomutt.c:186
struct NntpAccountData * CurrentNewsSrv
Current NNTP news server.
Definition: nntp.c:77
#define STAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:324
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
void * adata
Private data (for Mailbox backends)
Definition: account.h:42
List of Mailboxes.
Definition: mailbox.h:166
struct Mailbox * mailbox
Mailbox in the list.
Definition: mailbox.h:167
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition: mailbox.h:81
void * mdata
Driver specific data.
Definition: mailbox.h:132
Container for Accounts, Notifications.
Definition: neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:45
NNTP-specific Account data -.
Definition: adata.h:36
unsigned int groups_num
Definition: adata.h:58
void ** groups_list
Definition: adata.h:60
NNTP-specific Mailbox data -.
Definition: mdata.h:34
struct NntpAccountData * adata
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 839 of file dlg_browser.c.

840{
841 struct stat st = { 0 };
842 struct Buffer *md = NULL;
843 struct Buffer *mailbox = NULL;
844
845 if (OptNews)
846 {
848
849 init_state(state, menu);
850
851 const bool c_show_only_unread = cs_subset_bool(NeoMutt->sub, "show_only_unread");
852 for (unsigned int i = 0; i < adata->groups_num; i++)
853 {
854 struct NntpMboxData *mdata = adata->groups_list[i];
855 if (mdata && (mdata->has_new_mail ||
856 (mdata->subscribed && (mdata->unread || !c_show_only_unread))))
857 {
858 browser_add_folder(menu, state, mdata->group, NULL, NULL, NULL, mdata);
859 }
860 }
861 }
862 else
863 {
864 init_state(state, menu);
865
867 return -1;
868 mailbox = buf_pool_get();
869 md = buf_pool_get();
870
872
873 struct MailboxList ml = STAILQ_HEAD_INITIALIZER(ml);
875 struct MailboxNode *np = NULL;
876 const bool c_browser_abbreviate_mailboxes = cs_subset_bool(NeoMutt->sub, "browser_abbreviate_mailboxes");
877
878 STAILQ_FOREACH(np, &ml, entries)
879 {
880 if (!np->mailbox)
881 continue;
882
883 if (m && m->poll_new_mail && mutt_str_equal(np->mailbox->realpath, m->realpath))
884 {
885 np->mailbox->msg_count = m->msg_count;
886 np->mailbox->msg_unread = m->msg_unread;
887 }
888
890 if (c_browser_abbreviate_mailboxes)
892
893 switch (np->mailbox->type)
894 {
895 case MUTT_IMAP:
896 case MUTT_POP:
898 np->mailbox->name, NULL, np->mailbox, NULL);
899 continue;
900 case MUTT_NOTMUCH:
901 case MUTT_NNTP:
902 browser_add_folder(menu, state, mailbox_path(np->mailbox),
903 np->mailbox->name, NULL, np->mailbox, NULL);
904 continue;
905 default: /* Continue */
906 break;
907 }
908
909 if (lstat(mailbox_path(np->mailbox), &st) == -1)
910 continue;
911
912 if ((!S_ISREG(st.st_mode)) && (!S_ISDIR(st.st_mode)) && (!S_ISLNK(st.st_mode)))
913 continue;
914
915 if (np->mailbox->type == MUTT_MAILDIR)
916 {
917 struct stat st2 = { 0 };
918
919 buf_printf(md, "%s/new", mailbox_path(np->mailbox));
920 if (stat(buf_string(md), &st) < 0)
921 st.st_mtime = 0;
922 buf_printf(md, "%s/cur", mailbox_path(np->mailbox));
923 if (stat(buf_string(md), &st2) < 0)
924 st2.st_mtime = 0;
925 if (st2.st_mtime > st.st_mtime)
926 st.st_mtime = st2.st_mtime;
927 }
928
929 browser_add_folder(menu, state, buf_string(mailbox), np->mailbox->name,
930 &st, np->mailbox, NULL);
931 }
933 }
934 browser_sort(state);
935
936 buf_pool_release(&mailbox);
937 buf_pool_release(&md);
938 return 0;
939}
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:394
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:48
@ MUTT_NOTMUCH
'Notmuch' (virtual) Mailbox type
Definition: mailbox.h:51
@ MUTT_POP
'POP3' Mailbox type
Definition: mailbox.h:52
@ MUTT_NNTP
'NNTP' (Usenet) Mailbox type
Definition: mailbox.h:49
@ MUTT_IMAP
'IMAP' Mailbox type
Definition: mailbox.h:50
@ MUTT_MAILDIR
'Maildir' Mailbox type
Definition: mailbox.h:48
void buf_pretty_mailbox(struct Buffer *buf)
Shorten a mailbox path using '~' or '='.
Definition: muttlib.c:554
#define TAILQ_EMPTY(head)
Definition: queue.h:721
enum MailboxType type
Mailbox type.
Definition: mailbox.h:102
char * name
A short name for the Mailbox.
Definition: mailbox.h:82
struct AccountList accounts
List of all Accounts.
Definition: neomutt.h:46
+ 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 1003 of file dlg_browser.c.

1004{
1005 menu->top = 0;
1006 /* Reset menu position to 1.
1007 * We do not risk overflow as the init_menu function changes
1008 * current if it is bigger than state->entrylen. */
1009 if (!ARRAY_EMPTY(&state->entry) &&
1010 (mutt_str_equal(ARRAY_FIRST(&state->entry)->desc, "..") ||
1011 mutt_str_equal(ARRAY_FIRST(&state->entry)->desc, "../")))
1012 {
1013 /* Skip the first entry, unless there's only one entry. */
1014 menu_set_index(menu, (menu->max > 1));
1015 }
1016 else
1017 {
1018 menu_set_index(menu, 0);
1019 }
1020}
#define ARRAY_FIRST(head)
Convenience method to get the first element.
Definition: array.h:135
#define ARRAY_EMPTY(head)
Check if an array is empty.
Definition: array.h:74
MenuRedrawFlags menu_set_index(struct Menu *menu, int index)
Set the current selection in the Menu.
Definition: menu.c:174
int top
Entry that is the top of the current page.
Definition: lib.h:90
int max
Number of entries in the menu.
Definition: lib.h:81
+ 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 1029 of file dlg_browser.c.

1031{
1032 char title[256] = { 0 };
1033 menu->max = ARRAY_SIZE(&state->entry);
1034
1035 int index = menu_get_index(menu);
1036 if (index >= menu->max)
1037 menu_set_index(menu, menu->max - 1);
1038 if (index < 0)
1039 menu_set_index(menu, 0);
1040 if (menu->top > index)
1041 menu->top = 0;
1042
1043 menu->num_tagged = 0;
1044
1045 if (OptNews)
1046 {
1047 if (state->is_mailbox_list)
1048 {
1049 snprintf(title, sizeof(title), _("Subscribed newsgroups"));
1050 }
1051 else
1052 {
1053 snprintf(title, sizeof(title), _("Newsgroups on server [%s]"),
1055 }
1056 }
1057 else
1058 {
1059 if (state->is_mailbox_list)
1060 {
1061 snprintf(title, sizeof(title), _("Mailboxes [%d]"),
1063 }
1064 else
1065 {
1066 struct Buffer *path = buf_pool_get();
1067 buf_copy(path, &LastDir);
1068 buf_pretty_mailbox(path);
1069 const struct Regex *c_mask = cs_subset_regex(NeoMutt->sub, "mask");
1070 const bool c_imap_list_subscribed = cs_subset_bool(NeoMutt->sub, "imap_list_subscribed");
1071 if (state->imap_browse && c_imap_list_subscribed)
1072 {
1073 snprintf(title, sizeof(title), _("Subscribed [%s], File mask: %s"),
1074 buf_string(path), NONULL(c_mask ? c_mask->pattern : NULL));
1075 }
1076 else
1077 {
1078 snprintf(title, sizeof(title), _("Directory [%s], File mask: %s"),
1079 buf_string(path), NONULL(c_mask ? c_mask->pattern : NULL));
1080 }
1081 buf_pool_release(&path);
1082 }
1083 }
1084 sbar_set_title(sbar, title);
1085
1086 /* Browser tracking feature.
1087 * The goal is to highlight the good directory if LastDir is the parent dir
1088 * of LastDirBackup (this occurs mostly when one hit "../"). It should also work
1089 * properly when the user is in examine_mailboxes-mode. */
1091 {
1092 char target_dir[PATH_MAX] = { 0 };
1093
1094 /* Check what kind of dir LastDirBackup is. */
1096 {
1097 mutt_str_copy(target_dir, buf_string(&LastDirBackup), sizeof(target_dir));
1098 imap_clean_path(target_dir, sizeof(target_dir));
1099 }
1100 else
1101 {
1102 mutt_str_copy(target_dir, strrchr(buf_string(&LastDirBackup), '/') + 1,
1103 sizeof(target_dir));
1104 }
1105
1106 /* If we get here, it means that LastDir is the parent directory of
1107 * LastDirBackup. I.e., we're returning from a subdirectory, and we want
1108 * to position the cursor on the directory we're returning from. */
1109 bool matched = false;
1110 struct FolderFile *ff = NULL;
1111 ARRAY_FOREACH(ff, &state->entry)
1112 {
1113 if (mutt_str_equal(ff->name, target_dir))
1114 {
1115 menu_set_index(menu, ARRAY_FOREACH_IDX);
1116 matched = true;
1117 break;
1118 }
1119 }
1120 if (!matched)
1121 browser_highlight_default(state, menu);
1122 }
1123 else
1124 {
1125 browser_highlight_default(state, menu);
1126 }
1127
1129}
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:212
#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:600
void browser_highlight_default(struct BrowserState *state, struct Menu *menu)
Decide which browser item should be highlighted.
Definition: dlg_browser.c:1003
enum MailboxType imap_path_probe(const char *path, const struct stat *st)
Is this an IMAP Mailbox? - Implements MxOps::path_probe() -.
Definition: imap.c:2345
void imap_clean_path(char *path, size_t plen)
Cleans an IMAP path using imap_fix_path.
Definition: util.c:189
#define MENU_REDRAW_FULL
Redraw everything.
Definition: lib.h:59
void menu_queue_redraw(struct Menu *menu, MenuRedrawFlags redraw)
Queue a request for a redraw.
Definition: menu.c:184
int menu_get_index(struct Menu *menu)
Get the current selection in the Menu.
Definition: menu.c:160
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:575
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:37
char host[128]
Server to login to.
Definition: connaccount.h:54
struct ConnAccount account
Account details: username, password, etc.
Definition: connection.h:49
int num_tagged
Number of tagged entries.
Definition: lib.h:93
struct Connection * conn
Connection to NNTP Server.
Definition: adata.h:62
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 1273 of file dlg_browser.c.

1274{
1275 init_lastdir();
1276
1278
1279 /* Method that will fetch the parent path depending on the type of the path. */
1280 char buf[PATH_MAX] = { 0 };
1281 mutt_get_parent_path(buf_string(&LastDirBackup), buf, sizeof(buf));
1282 buf_strcpy(&LastDir, buf);
1283}
static void init_lastdir(void)
Initialise the browser directories.
Definition: dlg_browser.c:149
void mutt_get_parent_path(const char *path, char *buf, size_t buflen)
Find the parent of a path (or mailbox)
Definition: muttlib.c:971
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ FolderRenderData

const struct ExpandoRenderData FolderRenderData
Initial value:
= {
{ -1, -1, NULL, NULL },
}
@ ED_FOL_POLL
FolderFile.poll_new_mail.
Definition: lib.h:134
@ ED_FOL_NOTIFY
FolderFile.notify_user.
Definition: lib.h:132
@ ED_FOL_FILE_OWNER
FolderFile.uid.
Definition: lib.h:123
@ ED_FOL_FILE_GROUP
FolderFile.gid.
Definition: lib.h:121
@ ED_FOL_FILENAME
FolderFile.name.
Definition: lib.h:120
@ ED_FOL_DATE_FORMAT
FolderFile.mtime.
Definition: lib.h:118
@ ED_FOL_UNREAD_COUNT
FolderFile.msg_unread.
Definition: lib.h:137
@ ED_FOL_FILE_MODE
FolderFile.move.
Definition: lib.h:122
@ ED_FOL_NEW_MAIL
FolderFile.has_new_mail.
Definition: lib.h:131
@ ED_FOL_FILE_SIZE
FolderFile.size.
Definition: lib.h:124
@ ED_FOL_HARD_LINKS
FolderFile.nlink.
Definition: lib.h:127
@ ED_FOL_DATE
FolderFile.mtime.
Definition: lib.h:117
@ ED_FOL_STRF
FolderFile.mtime.
Definition: lib.h:135
@ ED_FOL_TAGGED
FolderFile.tagged.
Definition: lib.h:136
@ ED_FOL_NUMBER
Folder.num.
Definition: lib.h:133
@ ED_FOL_DESCRIPTION
FolderFile.desc, FolderFile.name.
Definition: lib.h:119
@ ED_FOL_MESSAGE_COUNT
FolderFile.msg_count.
Definition: lib.h:128
@ ED_FOLDER
Folder ED_FOL_ ExpandoDataFolder.
Definition: domain.h:43
@ ED_GLOBAL
Global ED_GLO_ ExpandoDataGlobal.
Definition: domain.h:44
long folder_date_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
Browser: Last modified (strftime) - Implements ExpandoRenderData::get_number() -.
Definition: dlg_browser.c:195
long folder_d_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
Browser: Last modified - Implements ExpandoRenderData::get_number() -.
Definition: dlg_browser.c:276
long folder_s_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
Browser: Size in bytes - Implements ExpandoRenderData::get_number() -.
Definition: dlg_browser.c:565
long folder_t_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
Browser: Is Tagged - Implements ExpandoRenderData::get_number() -.
Definition: dlg_browser.c:588
long folder_l_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
Browser: Hard links - Implements ExpandoRenderData::get_number() -.
Definition: dlg_browser.c:455
long folder_D_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
Browser: Last modified ($date_format) - Implements ExpandoRenderData::get_number() -.
Definition: dlg_browser.c:310
long folder_N_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
Browser: New mail flag - Implements ExpandoRenderData::get_number() -.
Definition: dlg_browser.c:533
long folder_m_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
Browser: Number of messages - Implements ExpandoRenderData::get_number() -.
Definition: dlg_browser.c:481
long folder_n_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
Browser: Number of unread messages - Implements ExpandoRenderData::get_number() -.
Definition: dlg_browser.c:507
long folder_p_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
Browser: Poll for new mail - Implements ExpandoRenderData::get_number() -.
Definition: dlg_browser.c:555
long folder_a_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
Browser: Alert for new mail - Implements ExpandoRenderData::get_number() -.
Definition: dlg_browser.c:256
long folder_C_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
Browser: Index number - Implements ExpandoRenderData::get_number() -.
Definition: dlg_browser.c:266
void folder_g(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, int max_cols, struct Buffer *buf)
Browser: Group name - Implements ExpandoRenderData::get_string() -.
Definition: dlg_browser.c:410
void folder_N(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, int max_cols, struct Buffer *buf)
Browser: New mail flag - Implements ExpandoRenderData::get_string() -.
Definition: dlg_browser.c:542
void folder_D(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, int max_cols, struct Buffer *buf)
Browser: Last modified ($date_format) - Implements ExpandoRenderData::get_string() -.
Definition: dlg_browser.c:322
void folder_d(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, int max_cols, struct Buffer *buf)
Browser: Last modified - Implements ExpandoRenderData::get_string() -.
Definition: dlg_browser.c:288
void folder_l(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, int max_cols, struct Buffer *buf)
Browser: Hard links - Implements ExpandoRenderData::get_string() -.
Definition: dlg_browser.c:468
void folder_u(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, int max_cols, struct Buffer *buf)
Browser: Owner name - Implements ExpandoRenderData::get_string() -.
Definition: dlg_browser.c:610
void folder_t(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, int max_cols, struct Buffer *buf)
Browser: Is Tagged - Implements ExpandoRenderData::get_string() -.
Definition: dlg_browser.c:597
void folder_n(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, int max_cols, struct Buffer *buf)
Browser: Number of unread messages - Implements ExpandoRenderData::get_string() -.
Definition: dlg_browser.c:520
void folder_date(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, int max_cols, struct Buffer *buf)
Browser: Last modified (strftime) - Implements ExpandoRenderData::get_string() -.
Definition: dlg_browser.c:208
void folder_space(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, int max_cols, struct Buffer *buf)
Fixed whitespace - Implements ExpandoRenderData::get_string() -.
Definition: dlg_browser.c:247
void folder_m(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, int max_cols, struct Buffer *buf)
Browser: Number of messages - Implements ExpandoRenderData::get_string() -.
Definition: dlg_browser.c:494
void folder_F(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, int max_cols, struct Buffer *buf)
Browser: File permissions - Implements ExpandoRenderData::get_string() -.
Definition: dlg_browser.c:375
void folder_s(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, int max_cols, struct Buffer *buf)
Browser: Size in bytes - Implements ExpandoRenderData::get_string() -.
Definition: dlg_browser.c:574
void folder_f(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, int max_cols, struct Buffer *buf)
Browser: Filename - Implements ExpandoRenderData::get_string() -.
Definition: dlg_browser.c:355
void folder_i(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, int max_cols, struct Buffer *buf)
Browser: Description - Implements ExpandoRenderData::get_string() -.
Definition: dlg_browser.c:431
@ ED_GLO_PADDING_SPACE
Space Padding.
Definition: uid.h:39

Callbacks for Browser Expandos.

See also
FolderFormatDef, ExpandoDataFolder, ExpandoDataGlobal

Definition at line 110 of file dlg_browser.c.

◆ GroupIndexRenderData

const struct ExpandoRenderData GroupIndexRenderData
Initial value:
= {
{ -1, -1, NULL, NULL },
}
@ ED_FOL_NEW_COUNT
FolderFile.nd (NntpMboxData)
Definition: lib.h:130
@ ED_FOL_FLAGS2
FolderFile.nd (NntpMboxData)
Definition: lib.h:126
@ ED_FOL_NEWSGROUP
FolderFile.name.
Definition: lib.h:129
@ ED_FOL_FLAGS
FolderFile.nd (NntpMboxData)
Definition: lib.h:125
long group_index_a_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
NNTP: Alert for new mail - Implements ExpandoRenderData::get_number() -.
Definition: browse.c:45
long group_index_p_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
NNTP: Poll for new mail - Implements ExpandoRenderData::get_number() -.
Definition: browse.c:166
long group_index_s_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
NNTP: Number of unread articles - Implements ExpandoRenderData::get_number() -.
Definition: browse.c:176
long group_index_C_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
NNTP: Index number - Implements ExpandoRenderData::get_number() -.
Definition: browse.c:55
long group_index_n_num(const struct ExpandoNode *node, void *data, MuttFormatFlags flags)
NNTP: Number of new articles - Implements ExpandoRenderData::get_number() -.
Definition: browse.c:125
void group_index_M(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, int max_cols, struct Buffer *buf)
NNTP: Moderated flag - Implements ExpandoRenderData::get_string() -.
Definition: browse.c:103
void group_index_d(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, int max_cols, struct Buffer *buf)
NNTP: Description - Implements ExpandoRenderData::get_string() -.
Definition: browse.c:65
void group_index_f(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, int max_cols, struct Buffer *buf)
NNTP: Newsgroup name - Implements ExpandoRenderData::get_string() -.
Definition: browse.c:91
void group_index_N(const struct ExpandoNode *node, void *data, MuttFormatFlags flags, int max_cols, struct Buffer *buf)
NNTP: New flag - Implements ExpandoRenderData::get_string() -.
Definition: browse.c:144

Callbacks for Nntp Browser Expandos.

See also
GroupIndexFormatDef, ExpandoDataFolder

Definition at line 111 of file dlg_browser.c.

◆ 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 114 of file dlg_browser.c.

◆ 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 126 of file dlg_browser.c.

◆ LastDir

struct Buffer LastDir = { 0 }

Browser: previous selected directory.

Definition at line 140 of file dlg_browser.c.

◆ LastDirBackup

struct Buffer LastDirBackup = { 0 }

Browser: backup copy of the current directory.

Definition at line 142 of file dlg_browser.c.