NeoMutt  2025-09-05-43-g177ed6
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
lib.h File Reference

Select a Mailbox from a list. More...

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

Go to the source code of this file.

Data Structures

struct  Folder
 A folder/dir in the browser. More...
 
struct  FolderFile
 Browser entry representing a folder/dir. More...
 
struct  BrowserState
 State of the file/mailbox browser. More...
 

Macros

#define MUTT_SEL_NO_FLAGS   0
 No flags are set.
 
#define MUTT_SEL_MAILBOX   (1 << 0)
 Select a mailbox.
 
#define MUTT_SEL_MULTI   (1 << 1)
 Multi-selection is enabled.
 
#define MUTT_SEL_FOLDER   (1 << 2)
 Select a local directory.
 

Typedefs

typedef uint8_t SelectFileFlags
 Flags for mutt_select_file(), e.g. MUTT_SEL_MAILBOX.
 

Enumerations

enum  ExpandoDataFolder {
  ED_FOL_DATE = 1 , ED_FOL_DATE_FORMAT , ED_FOL_DATE_STRF , ED_FOL_DESCRIPTION ,
  ED_FOL_FILENAME , ED_FOL_FILE_GROUP , ED_FOL_FILE_MODE , ED_FOL_FILE_OWNER ,
  ED_FOL_FILE_SIZE , ED_FOL_FLAGS , ED_FOL_FLAGS2 , ED_FOL_HARD_LINKS ,
  ED_FOL_MESSAGE_COUNT , ED_FOL_NEWSGROUP , ED_FOL_NEW_COUNT , ED_FOL_NEW_MAIL ,
  ED_FOL_NOTIFY , ED_FOL_NUMBER , ED_FOL_POLL , ED_FOL_TAGGED ,
  ED_FOL_UNREAD_COUNT
}
 Expando UIDs for the File Browser. More...
 

Functions

 ARRAY_HEAD (BrowserEntryArray, struct FolderFile)
 
void dlg_browser (struct Buffer *file, SelectFileFlags flags, struct Mailbox *m, char ***files, int *numfiles)
 Let the user select a file -.
 
void mutt_browser_select_dir (const char *f)
 Remember the last directory selected.
 
void mutt_browser_cleanup (void)
 Clean up working Buffers.
 
void browser_sort (struct BrowserState *state)
 Sort the entries in the browser.
 
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 browser_highlight_default (struct BrowserState *state, struct Menu *menu)
 Decide which browser item should be highlighted.
 
int examine_directory (struct Mailbox *m, struct Menu *menu, struct BrowserState *state, const char *d, 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.
 
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.
 
bool link_is_dir (const char *folder, const char *path)
 Does this symlink point to a directory?
 
void destroy_state (struct BrowserState *state)
 Free the BrowserState.
 
void dump_state (struct BrowserState *state)
 

Variables

struct Buffer LastDir
 Browser: previous selected directory.
 
struct Buffer LastDirBackup
 Browser: backup copy of the current directory.
 
const struct CompleteOps CompleteFileOps
 Auto-Completion of Files.
 
const struct CompleteOps CompleteMailboxOps
 Auto-Completion of Files / Mailboxes.
 

Detailed Description

Select a Mailbox from a list.

Authors
  • Richard Russon

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file lib.h.

Macro Definition Documentation

◆ MUTT_SEL_NO_FLAGS

#define MUTT_SEL_NO_FLAGS   0

No flags are set.

Definition at line 57 of file lib.h.

◆ MUTT_SEL_MAILBOX

#define MUTT_SEL_MAILBOX   (1 << 0)

Select a mailbox.

Definition at line 58 of file lib.h.

◆ MUTT_SEL_MULTI

#define MUTT_SEL_MULTI   (1 << 1)

Multi-selection is enabled.

Definition at line 59 of file lib.h.

◆ MUTT_SEL_FOLDER

#define MUTT_SEL_FOLDER   (1 << 2)

Select a local directory.

Definition at line 60 of file lib.h.

Typedef Documentation

◆ SelectFileFlags

typedef uint8_t SelectFileFlags

Flags for mutt_select_file(), e.g. MUTT_SEL_MAILBOX.

Definition at line 56 of file lib.h.

Enumeration Type Documentation

◆ ExpandoDataFolder

Expando UIDs for the File Browser.

See also
ED_FOLDER, ExpandoDomain
Enumerator
ED_FOL_DATE 

FolderFile.mtime.

ED_FOL_DATE_FORMAT 

FolderFile.mtime.

ED_FOL_DATE_STRF 

FolderFile.mtime.

ED_FOL_DESCRIPTION 

FolderFile.desc, FolderFile.name.

ED_FOL_FILENAME 

FolderFile.name.

ED_FOL_FILE_GROUP 

FolderFile.gid.

ED_FOL_FILE_MODE 

FolderFile.move.

ED_FOL_FILE_OWNER 

FolderFile.uid.

ED_FOL_FILE_SIZE 

FolderFile.size.

ED_FOL_FLAGS 

FolderFile.nd (NntpMboxData)

ED_FOL_FLAGS2 

FolderFile.nd (NntpMboxData)

ED_FOL_HARD_LINKS 

FolderFile.nlink.

ED_FOL_MESSAGE_COUNT 

FolderFile.msg_count.

ED_FOL_NEWSGROUP 

FolderFile.name.

ED_FOL_NEW_COUNT 

FolderFile.nd (NntpMboxData)

ED_FOL_NEW_MAIL 

FolderFile.has_new_mail.

ED_FOL_NOTIFY 

FolderFile.notify_user.

ED_FOL_NUMBER 

Folder.num.

ED_FOL_POLL 

FolderFile.poll_new_mail.

ED_FOL_TAGGED 

FolderFile.tagged.

ED_FOL_UNREAD_COUNT 

FolderFile.msg_unread.

Definition at line 115 of file lib.h.

116{
117 ED_FOL_DATE = 1,
138};
@ ED_FOL_POLL
FolderFile.poll_new_mail.
Definition lib.h:135
@ ED_FOL_NOTIFY
FolderFile.notify_user.
Definition lib.h:133
@ ED_FOL_NEW_COUNT
FolderFile.nd (NntpMboxData)
Definition lib.h:131
@ ED_FOL_FILE_OWNER
FolderFile.uid.
Definition lib.h:124
@ ED_FOL_FILE_GROUP
FolderFile.gid.
Definition lib.h:122
@ ED_FOL_FILENAME
FolderFile.name.
Definition lib.h:121
@ ED_FOL_DATE_FORMAT
FolderFile.mtime.
Definition lib.h:118
@ ED_FOL_DATE_STRF
FolderFile.mtime.
Definition lib.h:119
@ ED_FOL_UNREAD_COUNT
FolderFile.msg_unread.
Definition lib.h:137
@ ED_FOL_FLAGS2
FolderFile.nd (NntpMboxData)
Definition lib.h:127
@ ED_FOL_FILE_MODE
FolderFile.move.
Definition lib.h:123
@ ED_FOL_NEW_MAIL
FolderFile.has_new_mail.
Definition lib.h:132
@ ED_FOL_FILE_SIZE
FolderFile.size.
Definition lib.h:125
@ ED_FOL_HARD_LINKS
FolderFile.nlink.
Definition lib.h:128
@ ED_FOL_DATE
FolderFile.mtime.
Definition lib.h:117
@ ED_FOL_TAGGED
FolderFile.tagged.
Definition lib.h:136
@ ED_FOL_NUMBER
Folder.num.
Definition lib.h:134
@ ED_FOL_DESCRIPTION
FolderFile.desc, FolderFile.name.
Definition lib.h:120
@ ED_FOL_MESSAGE_COUNT
FolderFile.msg_count.
Definition lib.h:129
@ ED_FOL_NEWSGROUP
FolderFile.name.
Definition lib.h:130
@ ED_FOL_FLAGS
FolderFile.nd (NntpMboxData)
Definition lib.h:126

Function Documentation

◆ ARRAY_HEAD()

ARRAY_HEAD ( BrowserEntryArray ,
struct FolderFile  )

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

831{
832 init_lastdir();
833
835
836 /* Method that will fetch the parent path depending on the type of the path. */
837 char buf[PATH_MAX] = { 0 };
838 mutt_get_parent_path(buf_string(&LastDirBackup), buf, sizeof(buf));
839 buf_strcpy(&LastDir, buf);
840}
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition buffer.c:395
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition buffer.h:96
static void init_lastdir(void)
Initialise the browser directories.
struct Buffer LastDir
Browser: previous selected directory.
struct Buffer LastDirBackup
Browser: backup copy of the current directory.
#define PATH_MAX
Definition mutt.h:42
void mutt_get_parent_path(const char *path, char *buf, size_t buflen)
Find the parent of a path (or mailbox)
Definition muttlib.c:921
+ 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 159 of file dlg_browser.c.

160{
163}
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:

◆ browser_sort()

void browser_sort ( struct BrowserState * state)

Sort the entries in the browser.

Parameters
stateBrowser state

Call to qsort using browser_sort_helper function. Some specific sort methods are not used via NNTP.

Definition at line 186 of file sort.c.

187{
188 const enum EmailSortType c_browser_sort = cs_subset_sort(NeoMutt->sub, "browser_sort");
189 switch (c_browser_sort & SORT_MASK)
190 {
193 if (OptNews)
194 return;
196 default:
197 break;
198 }
199
200 sort_t f = NULL;
201 switch (c_browser_sort & SORT_MASK)
202 {
205 break;
208 break;
211 break;
214 break;
215 case BROWSER_SORT_NEW:
217 break;
220 break;
222 default:
224 break;
225 }
226
227 struct CompareData cd = {
228 .sort_fn = f,
229 .sort_reverse = c_browser_sort & SORT_REVERSE,
230 .sort_dirs_first = cs_subset_bool(NeoMutt->sub, "browser_sort_dirs_first"),
231 };
232
233 ARRAY_SORT(&state->entry, browser_sort_helper, &cd);
234}
#define ARRAY_SORT(head, fn, sdata)
Sort an array.
Definition array.h:335
@ BROWSER_SORT_ALPHA
Sort alphabetically 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
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition helpers.c:47
short cs_subset_sort(const struct ConfigSubset *sub, const char *name)
Get a sort config item by name.
Definition helpers.c:266
#define SORT_MASK
Mask for the sort id.
Definition sort.h:38
#define SORT_REVERSE
Reverse the order of the sort.
Definition sort.h:39
EmailSortType
Methods for sorting Emails.
Definition sort.h:53
bool OptNews
(pseudo) used to change reader mode
Definition globals.c:64
static int browser_sort_desc(const void *a, const void *b, void *sdata)
Compare two browser entries by their descriptions - Implements sort_t -.
Definition sort.c:84
static int browser_sort_date(const void *a, const void *b, void *sdata)
Compare two browser entries by their date - Implements sort_t -.
Definition sort.c:95
static int browser_sort_count(const void *a, const void *b, void *sdata)
Compare two browser entries by their message count - Implements sort_t -.
Definition sort.c:117
static int browser_sort_size(const void *a, const void *b, void *sdata)
Compare two browser entries by their size - Implements sort_t -.
Definition sort.c:106
static int browser_sort_helper(const void *a, const void *b, void *sdata)
Helper to sort the items in the browser - Implements sort_t -.
Definition sort.c:159
static int browser_sort_new(const void *a, const void *b, void *sdata)
Compare two browser entries by their new count - Implements sort_t -.
Definition sort.c:136
static int browser_sort_subject(const void *a, const void *b, void *sdata)
Compare two browser entries by their subject - Implements sort_t -.
Definition sort.c:55
static int browser_sort_unsorted(const void *a, const void *b, void *sdata)
Compare two browser entries by their order - Implements sort_t -.
Definition sort.c:73
#define FALLTHROUGH
Definition lib.h:113
int(* sort_t)(const void *a, const void *b, void *sdata)
Definition qsort_r.h:41
struct BrowserEntryArray entry
Array of files / dirs / mailboxes.
Definition lib.h:145
Private data for browser_sort_helper()
Definition sort.c:46
Container for Accounts, Notifications.
Definition neomutt.h:43
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:47
+ 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 198 of file dlg_browser.c.

201{
202 if ((!menu || state->is_mailbox_list) && m && !m->visible)
203 {
204 return;
205 }
206
207 struct FolderFile ff = { 0 };
208
209 if (st)
210 {
211 ff.mode = st->st_mode;
212 ff.mtime = st->st_mtime;
213 ff.size = st->st_size;
214 ff.gid = st->st_gid;
215 ff.uid = st->st_uid;
216 ff.nlink = st->st_nlink;
217 ff.local = true;
218 }
219 else
220 {
221 ff.local = false;
222 }
223
224 if (m)
225 {
226 ff.has_mailbox = true;
227 ff.gen = m->gen;
228 ff.has_new_mail = m->has_new;
229 ff.msg_count = m->msg_count;
230 ff.msg_unread = m->msg_unread;
231 ff.notify_user = m->notify_user;
233 }
234
235 ff.name = mutt_str_dup(name);
236 ff.desc = mutt_str_dup(desc ? desc : name);
237 ff.imap = false;
238 if (OptNews)
239 ff.nd = data;
240
241 ARRAY_ADD(&state->entry, ff);
242}
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition array.h:156
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition string.c:255
bool is_mailbox_list
Viewing mailboxes.
Definition lib.h:148
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
bool local
Folder is on local filesystem.
Definition lib.h:99
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:

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

560{
561 menu->top = 0;
562 /* Reset menu position to 1.
563 * We do not risk overflow as the init_menu function changes
564 * current if it is bigger than state->entrylen. */
565 if (!ARRAY_EMPTY(&state->entry) &&
566 (mutt_str_equal(ARRAY_FIRST(&state->entry)->desc, "..") ||
567 mutt_str_equal(ARRAY_FIRST(&state->entry)->desc, "../")))
568 {
569 /* Skip the first entry, unless there's only one entry. */
570 menu_set_index(menu, (menu->max > 1));
571 }
572 else
573 {
574 menu_set_index(menu, 0);
575 }
576}
#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
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition string.c:660
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:

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

267{
268 int rc = -1;
269 struct Buffer *buf = buf_pool_get();
270 if (OptNews)
271 {
273
274 init_state(state);
275
276 const struct Regex *c_mask = cs_subset_regex(NeoMutt->sub, "mask");
277 for (unsigned int i = 0; i < adata->groups_num; i++)
278 {
279 struct NntpMboxData *mdata = adata->groups_list[i];
280 if (!mdata)
281 continue;
282 if (prefix && *prefix && !mutt_str_startswith(mdata->group, prefix))
283 continue;
284 if (!mutt_regex_match(c_mask, mdata->group))
285 {
286 continue;
287 }
288 browser_add_folder(menu, state, mdata->group, NULL, NULL, NULL, mdata);
289 }
290 }
291 else
292 {
293 struct stat st = { 0 };
294 DIR *dir = NULL;
295 struct dirent *de = NULL;
296
297 while (stat(dirname, &st) == -1)
298 {
299 if (errno == ENOENT)
300 {
301 /* The last used directory is deleted, try to use the parent dir. */
302 char *c = strrchr(dirname, '/');
303
304 if (c && (c > dirname))
305 {
306 *c = '\0';
307 continue;
308 }
309 }
310 mutt_perror("%s", dirname);
311 goto ed_out;
312 }
313
314 if (!S_ISDIR(st.st_mode))
315 {
316 mutt_error(_("%s is not a directory"), dirname);
317 goto ed_out;
318 }
319
320 if (m)
322
323 dir = mutt_file_opendir(dirname, MUTT_OPENDIR_NONE);
324 if (!dir)
325 {
326 mutt_perror("%s", dirname);
327 goto ed_out;
328 }
329
330 init_state(state);
331
332 struct MailboxList ml = STAILQ_HEAD_INITIALIZER(ml);
334
335 const struct Regex *c_mask = cs_subset_regex(NeoMutt->sub, "mask");
336 while ((de = readdir(dir)))
337 {
338 if (mutt_str_equal(de->d_name, "."))
339 continue; /* we don't need . */
340
341 if (prefix && *prefix && !mutt_str_startswith(de->d_name, prefix))
342 {
343 continue;
344 }
345 if (!mutt_regex_match(c_mask, de->d_name))
346 {
347 continue;
348 }
349
350 buf_concat_path(buf, dirname, de->d_name);
351 if (lstat(buf_string(buf), &st) == -1)
352 continue;
353
354 /* No size for directories or symlinks */
355 if (S_ISDIR(st.st_mode) || S_ISLNK(st.st_mode))
356 st.st_size = 0;
357 else if (!S_ISREG(st.st_mode))
358 continue;
359
360 struct MailboxNode *np = NULL;
361 STAILQ_FOREACH(np, &ml, entries)
362 {
364 break;
365 }
366
367 if (np && m && m->poll_new_mail && mutt_str_equal(np->mailbox->realpath, m->realpath))
368 {
369 np->mailbox->msg_count = m->msg_count;
370 np->mailbox->msg_unread = m->msg_unread;
371 }
372 browser_add_folder(menu, state, de->d_name, NULL, &st, np ? np->mailbox : NULL, NULL);
373 }
375 closedir(dir);
376 }
377 browser_sort(state);
378 rc = 0;
379ed_out:
380 buf_pool_release(&buf);
381 return rc;
382}
void browser_sort(struct BrowserState *state)
Sort the entries in the browser.
Definition sort.c:186
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
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:223
@ MUTT_MAILBOX_ANY
Match any Mailbox type.
Definition mailbox.h:42
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:542
@ MUTT_OPENDIR_NONE
Plain opendir()
Definition file.h:63
#define mutt_error(...)
Definition logging2.h:93
#define mutt_perror(...)
Definition logging2.h:94
#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
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
Definition string.c:232
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:50
void neomutt_mailboxlist_clear(struct MailboxList *ml)
Free a Mailbox List.
Definition neomutt.c:173
size_t neomutt_mailboxlist_get_all(struct MailboxList *head, struct NeoMutt *n, enum MailboxType type)
Get a List of all Mailboxes.
Definition neomutt.c:196
struct NntpAccountData * CurrentNewsSrv
Current NNTP news server.
Definition nntp.c:76
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition pool.c:82
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition pool.c:96
#define STAILQ_HEAD_INITIALIZER(head)
Definition queue.h:324
#define STAILQ_FOREACH(var, head, field)
Definition queue.h:390
void * adata
Private data (for Mailbox backends)
Definition account.h:42
String manipulation buffer.
Definition buffer.h:36
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
NNTP-specific Account data -.
Definition adata.h:36
struct NntpMboxData ** groups_list
Definition adata.h:60
unsigned int groups_num
Definition adata.h:58
NNTP-specific Mailbox data -.
Definition mdata.h:34
struct NntpAccountData * adata
Definition mdata.h:48
Cached regular expression.
Definition regex3.h:86
+ 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 392 of file dlg_browser.c.

393{
394 struct stat st = { 0 };
395 struct Buffer *md = NULL;
396 struct Buffer *mailbox = NULL;
397
398 if (OptNews)
399 {
401
402 init_state(state);
403
404 const bool c_show_only_unread = cs_subset_bool(NeoMutt->sub, "show_only_unread");
405 for (unsigned int i = 0; i < adata->groups_num; i++)
406 {
407 struct NntpMboxData *mdata = adata->groups_list[i];
408 if (mdata && (mdata->has_new_mail ||
409 (mdata->subscribed && (mdata->unread || !c_show_only_unread))))
410 {
411 browser_add_folder(menu, state, mdata->group, NULL, NULL, NULL, mdata);
412 }
413 }
414 }
415 else
416 {
417 init_state(state);
418
420 return -1;
421 mailbox = buf_pool_get();
422 md = buf_pool_get();
423
425
426 struct MailboxList ml = STAILQ_HEAD_INITIALIZER(ml);
428 struct MailboxNode *np = NULL;
429 const bool c_browser_abbreviate_mailboxes = cs_subset_bool(NeoMutt->sub, "browser_abbreviate_mailboxes");
430
431 STAILQ_FOREACH(np, &ml, entries)
432 {
433 if (!np->mailbox)
434 continue;
435
436 if (m && m->poll_new_mail && mutt_str_equal(np->mailbox->realpath, m->realpath))
437 {
438 np->mailbox->msg_count = m->msg_count;
439 np->mailbox->msg_unread = m->msg_unread;
440 }
441
443 if (c_browser_abbreviate_mailboxes)
445
446 switch (np->mailbox->type)
447 {
448 case MUTT_IMAP:
449 case MUTT_POP:
451 np->mailbox->name, NULL, np->mailbox, NULL);
452 continue;
453 case MUTT_NOTMUCH:
454 case MUTT_NNTP:
455 browser_add_folder(menu, state, mailbox_path(np->mailbox),
456 np->mailbox->name, NULL, np->mailbox, NULL);
457 continue;
458 default: /* Continue */
459 break;
460 }
461
462 if (lstat(mailbox_path(np->mailbox), &st) == -1)
463 continue;
464
465 if ((!S_ISREG(st.st_mode)) && (!S_ISDIR(st.st_mode)) && (!S_ISLNK(st.st_mode)))
466 continue;
467
468 if (np->mailbox->type == MUTT_MAILDIR)
469 {
470 struct stat st2 = { 0 };
471
472 buf_printf(md, "%s/new", mailbox_path(np->mailbox));
473 if (stat(buf_string(md), &st) < 0)
474 st.st_mtime = 0;
475 buf_printf(md, "%s/cur", mailbox_path(np->mailbox));
476 if (stat(buf_string(md), &st2) < 0)
477 st2.st_mtime = 0;
478 if (st2.st_mtime > st.st_mtime)
479 st.st_mtime = st2.st_mtime;
480 }
481
482 browser_add_folder(menu, state, buf_string(mailbox), np->mailbox->name,
483 &st, np->mailbox, NULL);
484 }
486 }
487 browser_sort(state);
488
489 buf_pool_release(&mailbox);
490 buf_pool_release(&md);
491 return 0;
492}
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition buffer.c:161
@ 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:518
#define TAILQ_EMPTY(head)
Definition queue.h:778
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:48
+ 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 585 of file dlg_browser.c.

587{
588 char title[256] = { 0 };
589 menu->max = ARRAY_SIZE(&state->entry);
590
591 int index = menu_get_index(menu);
592 if (index >= menu->max)
593 menu_set_index(menu, menu->max - 1);
594 if (index < 0)
595 menu_set_index(menu, 0);
596 if (menu->top > index)
597 menu->top = 0;
598
599 menu->num_tagged = 0;
600
601 if (OptNews)
602 {
603 if (state->is_mailbox_list)
604 {
605 snprintf(title, sizeof(title), _("Subscribed newsgroups"));
606 }
607 else
608 {
609 snprintf(title, sizeof(title), _("Newsgroups on server [%s]"),
610 CurrentNewsSrv->conn->account.host);
611 }
612 }
613 else
614 {
615 if (state->is_mailbox_list)
616 {
617 snprintf(title, sizeof(title), _("Mailboxes [%d]"),
619 }
620 else
621 {
622 struct Buffer *path = buf_pool_get();
623 buf_copy(path, &LastDir);
624 buf_pretty_mailbox(path);
625 const struct Regex *c_mask = cs_subset_regex(NeoMutt->sub, "mask");
626 const bool c_imap_list_subscribed = cs_subset_bool(NeoMutt->sub, "imap_list_subscribed");
627 if (state->imap_browse && c_imap_list_subscribed)
628 {
629 snprintf(title, sizeof(title), _("Subscribed [%s], File mask: %s"),
630 buf_string(path), NONULL(c_mask ? c_mask->pattern : NULL));
631 }
632 else
633 {
634 snprintf(title, sizeof(title), _("Directory [%s], File mask: %s"),
635 buf_string(path), NONULL(c_mask ? c_mask->pattern : NULL));
636 }
637 buf_pool_release(&path);
638 }
639 }
640 sbar_set_title(sbar, title);
641
642 /* Browser tracking feature.
643 * The goal is to highlight the good directory if LastDir is the parent dir
644 * of LastDirBackup (this occurs mostly when one hit "../"). It should also work
645 * properly when the user is in examine_mailboxes-mode. */
647 {
648 char target_dir[PATH_MAX] = { 0 };
649
650 /* Check what kind of dir LastDirBackup is. */
652 {
653 mutt_str_copy(target_dir, buf_string(&LastDirBackup), sizeof(target_dir));
654 imap_clean_path(target_dir, sizeof(target_dir));
655 }
656 else
657 {
658 mutt_str_copy(target_dir, strrchr(buf_string(&LastDirBackup), '/') + 1,
659 sizeof(target_dir));
660 }
661
662 /* If we get here, it means that LastDir is the parent directory of
663 * LastDirBackup. I.e., we're returning from a subdirectory, and we want
664 * to position the cursor on the directory we're returning from. */
665 bool matched = false;
666 struct FolderFile *ff = NULL;
667 ARRAY_FOREACH(ff, &state->entry)
668 {
669 if (mutt_str_equal(ff->name, target_dir))
670 {
671 menu_set_index(menu, ARRAY_FOREACH_IDX_ff);
672 matched = true;
673 break;
674 }
675 }
676 if (!matched)
677 browser_highlight_default(state, menu);
678 }
679 else
680 {
681 browser_highlight_default(state, menu);
682 }
683
685}
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition array.h:214
#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:2349
void imap_clean_path(char *path, size_t plen)
Cleans an IMAP path using imap_fix_path.
Definition util.c:190
#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:581
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:43
bool imap_browse
IMAP folder.
Definition lib.h:146
int num_tagged
Number of tagged entries.
Definition lib.h:93
char * pattern
printable version
Definition regex3.h:87
+ 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 248 of file dlg_browser.c.

249{
250 ARRAY_INIT(&state->entry);
251 ARRAY_RESERVE(&state->entry, 256);
252 state->imap_browse = false;
253}
#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
+ 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 172 of file dlg_browser.c.

173{
174 struct stat st = { 0 };
175 bool rc = false;
176
177 struct Buffer *fullpath = buf_pool_get();
178 buf_concat_path(fullpath, folder, path);
179
180 if (stat(buf_string(fullpath), &st) == 0)
181 rc = S_ISDIR(st.st_mode);
182
183 buf_pool_release(&fullpath);
184
185 return rc;
186}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ destroy_state()

void destroy_state ( struct BrowserState * state)

Free the BrowserState.

Parameters
stateState to free

Frees up the memory allocated for the local-global variables.

Definition at line 135 of file functions.c.

136{
137 struct FolderFile *ff = NULL;
138 ARRAY_FOREACH(ff, &state->entry)
139 {
140 FREE(&ff->name);
141 FREE(&ff->desc);
142 }
143 ARRAY_FREE(&state->entry);
144 FREE(&state->folder);
145}
#define ARRAY_FREE(head)
Release all memory.
Definition array.h:204
#define FREE(x)
Definition memory.h:62
char * folder
Folder name.
Definition lib.h:147
+ Here is the caller graph for this function:

◆ dump_state()

void dump_state ( struct BrowserState * state)

Variable Documentation

◆ LastDir

struct Buffer LastDir
extern

Browser: previous selected directory.

Definition at line 136 of file dlg_browser.c.

136{ 0 };

◆ LastDirBackup

struct Buffer LastDirBackup
extern

Browser: backup copy of the current directory.

Definition at line 138 of file dlg_browser.c.

138{ 0 };

◆ CompleteFileOps

const struct CompleteOps CompleteFileOps
extern

Auto-Completion of Files.

Definition at line 153 of file complete.c.

153 {
154 .complete = complete_file_simple,
155};
enum FunctionRetval complete_file_simple(struct EnterWindowData *wdata, int op)
Complete a filename - Implements CompleteOps::complete() -.
Definition complete.c:113

◆ CompleteMailboxOps

const struct CompleteOps CompleteMailboxOps
extern

Auto-Completion of Files / Mailboxes.

Definition at line 160 of file complete.c.

160 {
161 .complete = complete_file_mbox,
162};
enum FunctionRetval complete_file_mbox(struct EnterWindowData *wdata, int op)
Complete a Mailbox - Implements CompleteOps::complete() -.
Definition complete.c:46