NeoMutt  2025-12-11-911-gd8d604
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
lib.h File Reference

Select a Mailbox from a list. More...

#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...
 

Typedefs

typedef uint8_t SelectFileFlags
 

Enumerations

enum  SelectFileFlag { MUTT_SEL_NONE = 0 , MUTT_SEL_MAILBOX = 1U << 0 , MUTT_SEL_MULTI = 1U << 1 , MUTT_SEL_FOLDER = 1U << 2 }
 Flags for mutt_select_file(), e.g. More...
 
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)
 
 ARRAY_HEAD (FolderFilePtrArray, struct FolderFile *)
 
void browser_init_keys (struct NeoMutt *n, struct SubMenu *sm_generic)
 Initialise the Browser Keybindings - Implements ::init_keys_api.
 
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 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

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.

Typedef Documentation

◆ SelectFileFlags

typedef uint8_t SelectFileFlags

Definition at line 64 of file lib.h.

Enumeration Type Documentation

◆ SelectFileFlag

Flags for mutt_select_file(), e.g.

MUTT_SEL_MAILBOX

Enumerator
MUTT_SEL_NONE 

No flags are set.

MUTT_SEL_MAILBOX 

Select a mailbox.

MUTT_SEL_MULTI 

Multi-selection is enabled.

MUTT_SEL_FOLDER 

Select a local directory.

Definition at line 57 of file lib.h.

58{
59 MUTT_SEL_NONE = 0,
60 MUTT_SEL_MAILBOX = 1U << 0,
61 MUTT_SEL_MULTI = 1U << 1,
62 MUTT_SEL_FOLDER = 1U << 2,
63};
@ MUTT_SEL_MAILBOX
Select a mailbox.
Definition lib.h:60
@ MUTT_SEL_MULTI
Multi-selection is enabled.
Definition lib.h:61
@ MUTT_SEL_FOLDER
Select a local directory.
Definition lib.h:62
@ MUTT_SEL_NONE
No flags are set.
Definition lib.h:59

◆ 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 119 of file lib.h.

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

Function Documentation

◆ ARRAY_HEAD() [1/2]

ARRAY_HEAD ( BrowserEntryArray ,
struct FolderFile  )

◆ ARRAY_HEAD() [2/2]

ARRAY_HEAD ( FolderFilePtrArray ,
struct FolderFile *  )

◆ browser_init_keys()

void browser_init_keys ( struct NeoMutt * n,
struct SubMenu * sm_generic )

Initialise the Browser Keybindings - Implements ::init_keys_api.

Definition at line 129 of file functions.c.

130{
132 ASSERT(mod_data);
133
134 struct MenuDefinition *md = NULL;
135 struct SubMenu *sm = NULL;
136
138 md = km_register_menu(MENU_BROWSER, "browser");
139 km_menu_add_submenu(md, sm);
140 km_menu_add_submenu(md, sm_generic);
142
143 mod_data->menu_browser = md;
144}
static const struct MenuOpSeq BrowserDefaultBindings[]
Key bindings for the file Browser Menu.
Definition functions.c:103
static const struct MenuFuncOp OpBrowser[]
Functions for the file Browser Menu.
Definition functions.c:69
void km_menu_add_submenu(struct MenuDefinition *md, struct SubMenu *sm)
Add a SubMenu to a Menu Definition.
Definition init.c:121
struct SubMenu * km_register_submenu(const struct MenuFuncOp functions[])
Register a submenu.
Definition init.c:87
struct MenuDefinition * km_register_menu(int menu, const char *name)
Register a menu.
Definition init.c:104
void km_menu_add_bindings(struct MenuDefinition *md, const struct MenuOpSeq bindings[])
Add Keybindings to a Menu.
Definition init.c:134
@ MODULE_ID_BROWSER
ModuleBrowser, Mailbox Browser
Definition module_api.h:52
void * neomutt_get_module_data(struct NeoMutt *n, enum ModuleId id)
Get the private data for a Module.
Definition neomutt.c:663
#define ASSERT(COND)
Definition signal2.h:59
Browser private Module data.
Definition module_data.h:32
struct MenuDefinition * menu_browser
Browser menu definition.
Definition module_data.h:34
Functions for a Dialog or Window.
Definition menu.h:77
Collection of related functions.
Definition menu.h:65
@ MENU_BROWSER
General file/mailbox browser.
Definition type.h:39
+ 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 823 of file dlg_browser.c.

824{
826
827 buf_strcpy(&mod_data->last_dir_backup, f);
828
829 /* Method that will fetch the parent path depending on the type of the path. */
830 char buf[PATH_MAX] = { 0 };
831 mutt_get_parent_path(buf_string(&mod_data->last_dir_backup), buf, sizeof(buf));
832 buf_strcpy(&mod_data->last_dir, buf);
833}
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
#define PATH_MAX
Definition mutt.h:49
void mutt_get_parent_path(const char *path, char *buf, size_t buflen)
Find the parent of a path (or mailbox)
Definition muttlib.c:867
struct Buffer last_dir
Browser: previous selected directory.
Definition module_data.h:35
struct Buffer last_dir_backup
Browser: backup copy of the current directory.
Definition module_data.h:36
Container for Accounts, Notifications.
Definition neomutt.h:41
+ 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:373
@ BROWSER_SORT_ALPHA
Sort by name.
Definition sort.h:31
@ BROWSER_SORT_UNSORTED
Sort into the raw order.
Definition sort.h:37
@ BROWSER_SORT_COUNT
Sort by total message count.
Definition sort.h:32
@ BROWSER_SORT_DATE
Sort by date.
Definition sort.h:33
@ BROWSER_SORT_NEW
Sort by count of new messages.
Definition sort.h:35
@ BROWSER_SORT_SIZE
Sort by size.
Definition sort.h:36
@ BROWSER_SORT_DESC
Sort by description.
Definition sort.h:34
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:39
#define SORT_REVERSE
Reverse the order of the sort.
Definition sort.h:40
EmailSortType
Methods for sorting Emails.
Definition sort.h:53
bool OptNews
(pseudo) used to change reader mode
Definition globals.c:53
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:117
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:149
Private data for browser_sort_helper()
Definition sort.c:46
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:49
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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

171{
172 if ((!menu || state->is_mailbox_list) && m && !m->visible)
173 {
174 return;
175 }
176
177 struct FolderFile ff = { 0 };
178
179 if (st)
180 {
181 ff.mode = st->st_mode;
182 ff.mtime = st->st_mtime;
183 ff.size = st->st_size;
184 ff.gid = st->st_gid;
185 ff.uid = st->st_uid;
186 ff.nlink = st->st_nlink;
187 ff.local = true;
188 }
189 else
190 {
191 ff.local = false;
192 }
193
194 if (m)
195 {
196 ff.has_mailbox = true;
197 ff.gen = m->gen;
198 ff.has_new_mail = m->has_new;
199 ff.msg_count = m->msg_count;
200 ff.msg_unread = m->msg_unread;
201 ff.notify_user = m->notify_user;
203 }
204
205 ff.name = mutt_str_dup(name);
206 ff.desc = mutt_str_dup(desc ? desc : name);
207 ff.imap = false;
208 if (OptNews)
209 ff.nd = data;
210
211 ARRAY_ADD(&state->entry, ff);
212}
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition array.h:157
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition string.c:257
bool is_mailbox_list
Viewing mailboxes.
Definition lib.h:152
Browser entry representing a folder/dir.
Definition lib.h:82
bool imap
This is an IMAP folder.
Definition lib.h:99
bool has_mailbox
This is a mailbox.
Definition lib.h:102
char * name
Name of file/dir/mailbox.
Definition lib.h:90
uid_t uid
File's User ID.
Definition lib.h:86
gid_t gid
File's Group ID.
Definition lib.h:87
bool has_new_mail
true if mailbox has "new mail"
Definition lib.h:93
bool poll_new_mail
Check mailbox for new mail.
Definition lib.h:105
bool notify_user
User will be notified of new mail.
Definition lib.h:104
nlink_t nlink
Number of hard links.
Definition lib.h:88
char * desc
Description of mailbox.
Definition lib.h:91
struct NntpMboxData * nd
Extra NNTP data.
Definition lib.h:107
off_t size
File size.
Definition lib.h:84
int gen
Unique id, used for (un)sorting.
Definition lib.h:109
bool local
Folder is on local filesystem.
Definition lib.h:103
time_t mtime
Modification time.
Definition lib.h:85
int msg_count
total number of messages
Definition lib.h:94
mode_t mode
File permissions.
Definition lib.h:83
int msg_unread
number of unread messages
Definition lib.h:95
bool has_new
Mailbox has new mail.
Definition mailbox.h:87
int msg_count
Total number of messages.
Definition mailbox.h:90
bool poll_new_mail
Check for new mail.
Definition mailbox.h:117
bool notify_user
Notify the user of new mail.
Definition mailbox.h:115
bool visible
True if a result of "mailboxes".
Definition mailbox.h:132
int msg_unread
Number of unread messages.
Definition mailbox.h:91
int gen
Generation number, for sorting.
Definition mailbox.h:149
+ 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 533 of file dlg_browser.c.

534{
535 menu->top = 0;
536 /* Reset menu position to 1.
537 * We do not risk overflow as the init_menu function changes
538 * current if it is bigger than state->entrylen. */
539 if (!ARRAY_EMPTY(&state->entry) &&
540 (mutt_str_equal(ARRAY_FIRST(&state->entry)->desc, "..") ||
541 mutt_str_equal(ARRAY_FIRST(&state->entry)->desc, "../")))
542 {
543 /* Skip the first entry, unless there's only one entry. */
544 menu_set_index(menu, (menu->max > 1));
545 }
546 else
547 {
548 menu_set_index(menu, 0);
549 }
550}
#define ARRAY_FIRST(head)
Convenience method to get the first element.
Definition array.h:136
#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:169
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition string.c:665
int top
Entry that is the top of the current page.
Definition lib.h:98
int max
Number of entries in the menu.
Definition lib.h:88
+ 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 235 of file dlg_browser.c.

237{
239 int rc = -1;
240 struct Buffer *buf = buf_pool_get();
241 if (OptNews)
242 {
243 struct NntpAccountData *adata = mod_data->current_news_srv;
244
245 init_state(state);
246
247 const struct Regex *c_mask = cs_subset_regex(NeoMutt->sub, "mask");
248 for (unsigned int i = 0; i < adata->groups_num; i++)
249 {
250 struct NntpMboxData *mdata = adata->groups_list[i];
251 if (!mdata)
252 continue;
253 if (prefix && *prefix && !mutt_str_startswith(mdata->group, prefix))
254 continue;
255 if (!mutt_regex_match(c_mask, mdata->group))
256 {
257 continue;
258 }
259 browser_add_folder(menu, state, mdata->group, NULL, NULL, NULL, mdata);
260 }
261 }
262 else
263 {
264 struct stat st = { 0 };
265 DIR *dir = NULL;
266 struct dirent *de = NULL;
267
268 // Work on a mutable copy to avoid modifying the const dirname parameter
269 char dstrbuf[PATH_MAX] = { 0 };
270 mutt_str_copy(dstrbuf, dirname, sizeof(dstrbuf));
271
272 while (stat(dstrbuf, &st) == -1)
273 {
274 if (errno == ENOENT)
275 {
276 /* The last used directory is deleted, try to use the parent dir. */
277 char *c = strrchr(dstrbuf, '/');
278
279 if (c && (c > dstrbuf))
280 {
281 *c = '\0';
282 continue;
283 }
284 }
285 mutt_perror("%s", dstrbuf);
286 goto ed_out;
287 }
288
289 if (!S_ISDIR(st.st_mode))
290 {
291 mutt_error(_("%s is not a directory"), dstrbuf);
292 goto ed_out;
293 }
294
295 if (m)
297
298 dir = mutt_file_opendir(dstrbuf, MUTT_OPENDIR_NONE);
299 if (!dir)
300 {
301 mutt_perror("%s", dstrbuf);
302 goto ed_out;
303 }
304
305 init_state(state);
306
307 struct MailboxArray ma = neomutt_mailboxes_get(NeoMutt, MUTT_MAILBOX_ANY);
308
309 const struct Regex *c_mask = cs_subset_regex(NeoMutt->sub, "mask");
310 while ((de = readdir(dir)))
311 {
312 if (mutt_str_equal(de->d_name, "."))
313 continue; /* we don't need . */
314
315 if (prefix && *prefix && !mutt_str_startswith(de->d_name, prefix))
316 {
317 continue;
318 }
319 if (!mutt_regex_match(c_mask, de->d_name))
320 {
321 continue;
322 }
323
324 buf_concat_path(buf, dstrbuf, de->d_name);
325 if (lstat(buf_string(buf), &st) == -1)
326 continue;
327
328 /* No size for directories or symlinks */
329 if (S_ISDIR(st.st_mode) || S_ISLNK(st.st_mode))
330 st.st_size = 0;
331 else if (!S_ISREG(st.st_mode))
332 continue;
333
334 struct Mailbox **mp = NULL;
335 ARRAY_FOREACH(mp, &ma)
336 {
337 if (mutt_str_equal(buf_string(buf), mailbox_path(*mp)))
338 break;
339 }
340
341 struct Mailbox *m_match = mp ? *mp : NULL;
342 if (m_match && m && m->poll_new_mail && mutt_str_equal(m_match->realpath, m->realpath))
343 {
344 m_match->msg_count = m->msg_count;
345 m_match->msg_unread = m->msg_unread;
346 }
347 browser_add_folder(menu, state, de->d_name, NULL, &st, m_match, NULL);
348 }
349 ARRAY_FREE(&ma); // Clean up the ARRAY, but not the Mailboxes
350 closedir(dir);
351 }
352 browser_sort(state);
353 rc = 0;
354ed_out:
355 buf_pool_release(&buf);
356 return rc;
357}
#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
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:216
@ 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:68
#define mutt_error(...)
Definition logging2.h:94
#define mutt_perror(...)
Definition logging2.h:95
@ MODULE_ID_NNTP
ModuleNntp, Nntp
Definition module_api.h:81
#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: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.
@ MUTT_MAILBOX_CHECK_NONE
No flags are set.
Definition mxapi.h:58
struct MailboxArray neomutt_mailboxes_get(struct NeoMutt *n, enum MailboxType type)
Get an Array of matching Mailboxes.
Definition neomutt.c:604
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
void * adata
Private data (for Mailbox backends)
Definition account.h:42
String manipulation buffer.
Definition buffer.h:36
A mailbox.
Definition mailbox.h:81
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition mailbox.h:83
void * mdata
Driver specific data.
Definition mailbox.h:134
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
Nntp private Module data.
Definition module_data.h:30
struct NntpAccountData * current_news_srv
Current NNTP news server.
Definition module_data.h:32
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 367 of file dlg_browser.c.

368{
370 struct stat st = { 0 };
371 struct Buffer *md = NULL;
372 struct Buffer *mailbox = NULL;
373
374 if (OptNews)
375 {
376 struct NntpAccountData *adata = mod_data->current_news_srv;
377
378 init_state(state);
379
380 const bool c_show_only_unread = cs_subset_bool(NeoMutt->sub, "show_only_unread");
381 for (unsigned int i = 0; i < adata->groups_num; i++)
382 {
383 struct NntpMboxData *mdata = adata->groups_list[i];
384 if (mdata && (mdata->has_new_mail ||
385 (mdata->subscribed && (mdata->unread || !c_show_only_unread))))
386 {
387 browser_add_folder(menu, state, mdata->group, NULL, NULL, NULL, mdata);
388 }
389 }
390 }
391 else
392 {
393 init_state(state);
394
396 return -1;
397
398 mailbox = buf_pool_get();
399 md = buf_pool_get();
400
402
403 struct MailboxArray ma = neomutt_mailboxes_get(NeoMutt, MUTT_MAILBOX_ANY);
404 const bool c_browser_abbreviate_mailboxes = cs_subset_bool(NeoMutt->sub, "browser_abbreviate_mailboxes");
405
406 struct Mailbox **mp = NULL;
407 ARRAY_FOREACH(mp, &ma)
408 {
409 struct Mailbox *m_match = *mp;
410
411 if (m && m->poll_new_mail && mutt_str_equal(m_match->realpath, m->realpath))
412 {
413 m_match->msg_count = m->msg_count;
414 m_match->msg_unread = m->msg_unread;
415 }
416
417 buf_strcpy(mailbox, mailbox_path(m_match));
418 if (c_browser_abbreviate_mailboxes)
419 pretty_mailbox(mailbox);
420
421 switch (m_match->type)
422 {
423 case MUTT_IMAP:
424 case MUTT_POP:
425 browser_add_folder(menu, state, buf_string(mailbox), m_match->name,
426 NULL, m_match, NULL);
427 continue;
428 case MUTT_NOTMUCH:
429 case MUTT_NNTP:
430 browser_add_folder(menu, state, mailbox_path(m_match), m_match->name,
431 NULL, m_match, NULL);
432 continue;
433 default: /* Continue */
434 break;
435 }
436
437 if (lstat(mailbox_path(m_match), &st) == -1)
438 continue;
439
440 if ((!S_ISREG(st.st_mode)) && (!S_ISDIR(st.st_mode)) && (!S_ISLNK(st.st_mode)))
441 continue;
442
443 if (m_match->type == MUTT_MAILDIR)
444 {
445 struct stat st2 = { 0 };
446
447 buf_printf(md, "%s/new", mailbox_path(m_match));
448 if (stat(buf_string(md), &st) < 0)
449 st.st_mtime = 0;
450 buf_printf(md, "%s/cur", mailbox_path(m_match));
451 if (stat(buf_string(md), &st2) < 0)
452 st2.st_mtime = 0;
453 if (st2.st_mtime > st.st_mtime)
454 st.st_mtime = st2.st_mtime;
455 }
456
457 browser_add_folder(menu, state, buf_string(mailbox), m_match->name, &st, m_match, NULL);
458 }
459 ARRAY_FREE(&ma); // Clean up the ARRAY, but not the Mailboxes
460 }
461 browser_sort(state);
462
463 buf_pool_release(&mailbox);
464 buf_pool_release(&md);
465 return 0;
466}
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: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:104
char * name
A short name for the Mailbox.
Definition mailbox.h:84
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:

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

561{
564 char title[256] = { 0 };
565 menu->max = ARRAY_SIZE(&state->entry);
566
567 int index = menu_get_index(menu);
568 if (index >= menu->max)
569 menu_set_index(menu, menu->max - 1);
570 if (index < 0)
571 menu_set_index(menu, 0);
572 if (menu->top > index)
573 menu->top = 0;
574
575 menu->num_tagged = 0;
576
577 if (OptNews)
578 {
579 if (state->is_mailbox_list)
580 {
581 snprintf(title, sizeof(title), _("Subscribed newsgroups"));
582 }
583 else
584 {
585 snprintf(title, sizeof(title), _("Newsgroups on server [%s]"),
586 nntp_mod_data->current_news_srv->conn->account.host);
587 }
588 }
589 else
590 {
591 if (state->is_mailbox_list)
592 {
593 snprintf(title, sizeof(title), _("Mailboxes [%d]"),
595 }
596 else
597 {
598 struct Buffer *path = buf_pool_get();
599 buf_copy(path, &mod_data->last_dir);
600 pretty_mailbox(path);
601 const struct Regex *c_mask = cs_subset_regex(NeoMutt->sub, "mask");
602 const bool c_imap_list_subscribed = cs_subset_bool(NeoMutt->sub, "imap_list_subscribed");
603 if (state->imap_browse && c_imap_list_subscribed)
604 {
605 snprintf(title, sizeof(title), _("Subscribed [%s], File mask: %s"),
606 buf_string(path), NONULL(c_mask ? c_mask->pattern : NULL));
607 }
608 else
609 {
610 snprintf(title, sizeof(title), _("Directory [%s], File mask: %s"),
611 buf_string(path), NONULL(c_mask ? c_mask->pattern : NULL));
612 }
613 buf_pool_release(&path);
614 }
615 }
616 sbar_set_title(sbar, title);
617
618 /* Browser tracking feature.
619 * The goal is to highlight the good directory if LastDir is the parent dir
620 * of LastDirBackup (this occurs mostly when one hit "../"). It should also work
621 * properly when the user is in examine_mailboxes-mode. */
623 buf_string(&mod_data->last_dir)))
624 {
625 char target_dir[PATH_MAX] = { 0 };
626
627 /* Check what kind of dir LastDirBackup is. */
628 if (imap_path_probe(buf_string(&mod_data->last_dir_backup), NULL) == MUTT_IMAP)
629 {
630 mutt_str_copy(target_dir, buf_string(&mod_data->last_dir_backup), sizeof(target_dir));
631 imap_clean_path(target_dir, sizeof(target_dir));
632 }
633 else
634 {
635 const char *slash = strrchr(buf_string(&mod_data->last_dir_backup), '/');
636 if (slash)
637 mutt_str_copy(target_dir, slash + 1, sizeof(target_dir));
638 else
639 mutt_str_copy(target_dir, buf_string(&mod_data->last_dir_backup), sizeof(target_dir));
640 }
641
642 /* If we get here, it means that LastDir is the parent directory of
643 * LastDirBackup. I.e., we're returning from a subdirectory, and we want
644 * to position the cursor on the directory we're returning from. */
645 bool matched = false;
646 struct FolderFile *ff = NULL;
647 ARRAY_FOREACH(ff, &state->entry)
648 {
649 if (mutt_str_equal(ff->name, target_dir))
650 {
651 menu_set_index(menu, ARRAY_FOREACH_IDX_ff);
652 matched = true;
653 break;
654 }
655 }
656 if (!matched)
657 browser_highlight_default(state, menu);
658 }
659 else
660 {
661 browser_highlight_default(state, menu);
662 }
663
665}
#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:2681
void imap_clean_path(char *path, size_t plen)
Cleans an IMAP path using imap_fix_path.
Definition util.c:195
void menu_queue_redraw(struct Menu *menu, MenuRedrawFlags redraw)
Queue a request for a redraw.
Definition menu.c:179
int menu_get_index(struct Menu *menu)
Get the current selection in the Menu.
Definition menu.c:155
@ MENU_REDRAW_FULL
Redraw everything.
Definition lib.h:64
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
bool imap_browse
IMAP folder.
Definition lib.h:150
char host[128]
Server to login to.
Definition connaccount.h:60
struct ConnAccount account
Account details: username, password, etc.
Definition connection.h:49
int num_tagged
Number of tagged entries.
Definition lib.h:101
struct Connection * conn
Connection to NNTP Server.
Definition adata.h:63
char * pattern
printable version
Definition regex3.h:86
+ 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 218 of file dlg_browser.c.

219{
220 ARRAY_INIT(&state->entry);
221 ARRAY_RESERVE(&state->entry, 256);
222 state->imap_browse = false;
223}
#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
+ 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 142 of file dlg_browser.c.

143{
144 struct stat st = { 0 };
145 bool rc = false;
146
147 struct Buffer *fullpath = buf_pool_get();
148 buf_concat_path(fullpath, folder, path);
149
150 if (stat(buf_string(fullpath), &st) == 0)
151 rc = S_ISDIR(st.st_mode);
152
153 buf_pool_release(&fullpath);
154
155 return rc;
156}
+ 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 152 of file functions.c.

153{
154 struct FolderFile *ff = NULL;
155 ARRAY_FOREACH(ff, &state->entry)
156 {
157 FREE(&ff->name);
158 FREE(&ff->desc);
159 }
160 ARRAY_FREE(&state->entry);
161 FREE(&state->folder);
162}
#define FREE(x)
Free memory and set the pointer to NULL.
Definition memory.h:68
char * folder
Folder name.
Definition lib.h:151
+ Here is the caller graph for this function:

◆ dump_state()

void dump_state ( struct BrowserState * state)

Variable Documentation

◆ CompleteFileOps

const struct CompleteOps CompleteFileOps
extern

Auto-Completion of Files.

Definition at line 152 of file complete.c.

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

◆ CompleteMailboxOps

const struct CompleteOps CompleteMailboxOps
extern

Auto-Completion of Files / Mailboxes.

Definition at line 159 of file complete.c.

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