NeoMutt
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 "complete/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.
 

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, struct Menu *menu)
 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.

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

1226{
1227 init_lastdir();
1228
1230
1231 /* Method that will fetch the parent path depending on the type of the path. */
1232 char buf[PATH_MAX] = { 0 };
1233 mutt_get_parent_path(buf_string(&LastDirBackup), buf, sizeof(buf));
1234 buf_strcpy(&LastDir, buf);
1235}
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:407
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:93
static void init_lastdir(void)
Initialise the browser directories.
Definition: dlg_browser.c:145
struct Buffer LastDir
Browser: previous selected directory.
Definition: dlg_browser.c:136
struct Buffer LastDirBackup
Browser: backup copy of the current directory.
Definition: dlg_browser.c:138
#define PATH_MAX
Definition: mutt.h:41
void mutt_get_parent_path(const char *path, char *buf, size_t buflen)
Find the parent of a path (or mailbox)
Definition: muttlib.c:1521
+ 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:389
+ 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 185 of file sort.c.

186{
187 const enum SortType c_sort_browser = cs_subset_sort(NeoMutt->sub, "sort_browser");
188 switch (c_sort_browser & SORT_MASK)
189 {
190#ifdef USE_NNTP
191 case SORT_SIZE:
192 case SORT_DATE:
193 if (OptNews)
194 return;
195#endif
196 default:
197 break;
198 }
199
200 sort_t f = NULL;
201 switch (c_sort_browser & SORT_MASK)
202 {
203 case SORT_COUNT:
205 break;
206 case SORT_DATE:
208 break;
209 case SORT_DESC:
211 break;
212 case SORT_SIZE:
214 break;
215 case SORT_UNREAD:
217 break;
218 case SORT_SUBJECT:
220 break;
221 default:
222 case SORT_ORDER:
224 break;
225 }
226
227 struct CompareData cd = {
228 .sort_fn = f,
229 .sort_reverse = c_sort_browser & 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:278
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:48
short cs_subset_sort(const struct ConfigSubset *sub, const char *name)
Get a sort config item by name.
Definition: helpers.c:267
bool OptNews
(pseudo) used to change reader mode
Definition: globals.c:76
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:83
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:94
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:116
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:105
static int browser_sort_count_new(const void *a, const void *b, void *sdata)
Compare two browser entries by their new count - Implements sort_t -.
Definition: sort.c:135
static int browser_sort_order(const void *a, const void *b, void *sdata)
Compare two browser entries by their order - Implements sort_t -.
Definition: sort.c:72
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:158
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:54
int(* sort_t)(const void *a, const void *b, void *sdata)
Definition: qsort_r.h:40
#define SORT_MASK
Mask for the sort id.
Definition: sort2.h:74
SortType
Methods for sorting.
Definition: sort2.h:38
@ SORT_SUBJECT
Sort by the email's subject.
Definition: sort2.h:42
@ SORT_ORDER
Sort by the order the messages appear in the mailbox.
Definition: sort2.h:44
@ SORT_SIZE
Sort by the size of the email.
Definition: sort2.h:40
@ SORT_DESC
Sort by the folder's description.
Definition: sort2.h:59
@ SORT_DATE
Sort by the date the email was sent.
Definition: sort2.h:39
@ SORT_COUNT
Sort by number of emails in a folder.
Definition: sort2.h:54
@ SORT_UNREAD
Sort by the number of unread emails.
Definition: sort2.h:55
#define SORT_REVERSE
Reverse the order of the sort.
Definition: sort2.h:75
struct BrowserEntryArray entry
Array of files / dirs / mailboxes.
Definition: lib.h:119
Private data for browser_sort_helper()
Definition: sort.c:45
sort_t sort_fn
Function to perform $browser_sort.
Definition: sort.c:48
Container for Accounts, Notifications.
Definition: neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:45
+ 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 578 of file dlg_browser.c.

581{
582 if ((!menu || state->is_mailbox_list) && m && !m->visible)
583 {
584 return;
585 }
586
587 struct FolderFile ff = { 0 };
588
589 if (st)
590 {
591 ff.mode = st->st_mode;
592 ff.mtime = st->st_mtime;
593 ff.size = st->st_size;
594 ff.gid = st->st_gid;
595 ff.uid = st->st_uid;
596 ff.nlink = st->st_nlink;
597 ff.local = true;
598 }
599 else
600 {
601 ff.local = false;
602 }
603
604 if (m)
605 {
606 ff.has_mailbox = true;
607 ff.gen = m->gen;
608 ff.has_new_mail = m->has_new;
609 ff.msg_count = m->msg_count;
610 ff.msg_unread = m->msg_unread;
611 ff.notify_user = m->notify_user;
613 }
614
615 ff.name = mutt_str_dup(name);
616 ff.desc = mutt_str_dup(desc ? desc : name);
617#ifdef USE_IMAP
618 ff.imap = false;
619#endif
620#ifdef USE_NNTP
621 if (OptNews)
622 ff.nd = data;
623#endif
624
625 ARRAY_ADD(&state->entry, ff);
626}
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition: array.h:155
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:251
bool is_mailbox_list
Viewing mailboxes.
Definition: lib.h:124
Browser entry representing a folder/dir.
Definition: lib.h:78
bool imap
This is an IMAP folder.
Definition: lib.h:96
bool has_mailbox
This is a mailbox.
Definition: lib.h:100
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:103
bool notify_user
User will be notified of new mail.
Definition: lib.h:102
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:106
off_t size
File size.
Definition: lib.h:80
int gen
Unique id, used for (un)sorting.
Definition: lib.h:109
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:114
bool notify_user
Notify the user of new mail.
Definition: mailbox.h:112
bool visible
True if a result of "mailboxes".
Definition: mailbox.h:131
int msg_unread
Number of unread messages.
Definition: mailbox.h:89
int gen
Generation number, for sorting.
Definition: mailbox.h:146
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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

952{
953 menu->top = 0;
954 /* Reset menu position to 1.
955 * We do not risk overflow as the init_menu function changes
956 * current if it is bigger than state->entrylen. */
957 if (!ARRAY_EMPTY(&state->entry) &&
958 (mutt_str_equal(ARRAY_FIRST(&state->entry)->desc, "..") ||
959 mutt_str_equal(ARRAY_FIRST(&state->entry)->desc, "../")))
960 {
961 /* Skip the first entry, unless there's only one entry. */
962 menu_set_index(menu, (menu->max > 1));
963 }
964 else
965 {
966 menu_set_index(menu, 0);
967 }
968}
#define ARRAY_FIRST(head)
Convenience method to get the first element.
Definition: array.h:134
#define ARRAY_EMPTY(head)
Check if an array is empty.
Definition: array.h:73
MenuRedrawFlags menu_set_index(struct Menu *menu, int index)
Set the current selection in the Menu.
Definition: menu.c:170
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:798
int top
Entry that is the top of the current page.
Definition: lib.h:81
int max
Number of entries in the menu.
Definition: lib.h:72
+ 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 657 of file dlg_browser.c.

659{
660 int rc = -1;
661 struct Buffer *buf = buf_pool_get();
662#ifdef USE_NNTP
663 if (OptNews)
664 {
666
667 init_state(state, menu);
668
669 const struct Regex *c_mask = cs_subset_regex(NeoMutt->sub, "mask");
670 for (unsigned int i = 0; i < adata->groups_num; i++)
671 {
672 struct NntpMboxData *mdata = adata->groups_list[i];
673 if (!mdata)
674 continue;
675 if (prefix && *prefix && !mutt_str_startswith(mdata->group, prefix))
676 continue;
677 if (!mutt_regex_match(c_mask, mdata->group))
678 {
679 continue;
680 }
681 browser_add_folder(menu, state, mdata->group, NULL, NULL, NULL, mdata);
682 }
683 }
684 else
685#endif /* USE_NNTP */
686 {
687 struct stat st = { 0 };
688 DIR *dir = NULL;
689 struct dirent *de = NULL;
690
691 while (stat(dirname, &st) == -1)
692 {
693 if (errno == ENOENT)
694 {
695 /* The last used directory is deleted, try to use the parent dir. */
696 char *c = strrchr(dirname, '/');
697
698 if (c && (c > dirname))
699 {
700 *c = '\0';
701 continue;
702 }
703 }
704 mutt_perror("%s", dirname);
705 goto ed_out;
706 }
707
708 if (!S_ISDIR(st.st_mode))
709 {
710 mutt_error(_("%s is not a directory"), dirname);
711 goto ed_out;
712 }
713
714 if (m)
716
717 dir = mutt_file_opendir(dirname, MUTT_OPENDIR_NONE);
718 if (!dir)
719 {
720 mutt_perror("%s", dirname);
721 goto ed_out;
722 }
723
724 init_state(state, menu);
725
726 struct MailboxList ml = STAILQ_HEAD_INITIALIZER(ml);
728
729 const struct Regex *c_mask = cs_subset_regex(NeoMutt->sub, "mask");
730 while ((de = readdir(dir)))
731 {
732 if (mutt_str_equal(de->d_name, "."))
733 continue; /* we don't need . */
734
735 if (prefix && *prefix && !mutt_str_startswith(de->d_name, prefix))
736 {
737 continue;
738 }
739 if (!mutt_regex_match(c_mask, de->d_name))
740 {
741 continue;
742 }
743
744 buf_concat_path(buf, dirname, de->d_name);
745 if (lstat(buf_string(buf), &st) == -1)
746 continue;
747
748 /* No size for directories or symlinks */
749 if (S_ISDIR(st.st_mode) || S_ISLNK(st.st_mode))
750 st.st_size = 0;
751 else if (!S_ISREG(st.st_mode))
752 continue;
753
754 struct MailboxNode *np = NULL;
755 STAILQ_FOREACH(np, &ml, entries)
756 {
758 break;
759 }
760
761 if (np && m && m->poll_new_mail && mutt_str_equal(np->mailbox->realpath, m->realpath))
762 {
763 np->mailbox->msg_count = m->msg_count;
764 np->mailbox->msg_unread = m->msg_unread;
765 }
766 browser_add_folder(menu, state, de->d_name, NULL, &st, np ? np->mailbox : NULL, NULL);
767 }
769 closedir(dir);
770 }
771 browser_sort(state);
772 rc = 0;
773ed_out:
774 buf_pool_release(&buf);
775 return rc;
776}
void browser_sort(struct BrowserState *state)
Sort the entries in the browser.
Definition: sort.c:185
size_t buf_concat_path(struct Buffer *buf, const char *dir, const char *fname)
Join a directory name and a filename.
Definition: buffer.c:484
const struct Regex * cs_subset_regex(const struct ConfigSubset *sub, const char *name)
Get a regex config item by name.
Definition: helpers.c:218
void init_state(struct BrowserState *state, struct Menu *menu)
Initialise a browser state.
Definition: dlg_browser.c:633
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:578
DIR * mutt_file_opendir(const char *path, enum MuttOpenDirMode mode)
Open a directory.
Definition: file.c:616
@ MUTT_OPENDIR_NONE
Plain opendir()
Definition: file.h:73
#define mutt_error(...)
Definition: logging2.h:92
#define mutt_perror(...)
Definition: logging2.h:93
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox's path string.
Definition: mailbox.h:210
@ MUTT_MAILBOX_ANY
Match any Mailbox type.
Definition: mailbox.h:42
#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:636
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
Definition: string.c:228
int mutt_mailbox_check(struct Mailbox *m_cur, CheckStatsFlags flags)
Check all all Mailboxes for new mail.
Definition: mutt_mailbox.c:165
#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:162
size_t neomutt_mailboxlist_get_all(struct MailboxList *head, struct NeoMutt *n, enum MailboxType type)
Get a List of all Mailboxes.
Definition: neomutt.c:185
struct NntpAccountData * CurrentNewsSrv
Current NNTP news server.
Definition: nntp.c:77
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
#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:43
String manipulation buffer.
Definition: buffer.h:34
List of Mailboxes.
Definition: mailbox.h:153
struct Mailbox * mailbox
Mailbox in the list.
Definition: mailbox.h:154
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition: mailbox.h:81
void * mdata
Driver specific data.
Definition: mailbox.h:133
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:89
+ 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 786 of file dlg_browser.c.

787{
788 struct stat st = { 0 };
789 struct Buffer *md = NULL;
790 struct Buffer *mailbox = NULL;
791
792#ifdef USE_NNTP
793 if (OptNews)
794 {
796
797 init_state(state, menu);
798
799 const bool c_show_only_unread = cs_subset_bool(NeoMutt->sub, "show_only_unread");
800 for (unsigned int i = 0; i < adata->groups_num; i++)
801 {
802 struct NntpMboxData *mdata = adata->groups_list[i];
803 if (mdata && (mdata->has_new_mail ||
804 (mdata->subscribed && (mdata->unread || !c_show_only_unread))))
805 {
806 browser_add_folder(menu, state, mdata->group, NULL, NULL, NULL, mdata);
807 }
808 }
809 }
810 else
811#endif
812 {
813 init_state(state, menu);
814
816 return -1;
817 mailbox = buf_pool_get();
818 md = buf_pool_get();
819
821
822 struct MailboxList ml = STAILQ_HEAD_INITIALIZER(ml);
824 struct MailboxNode *np = NULL;
825 const bool c_browser_abbreviate_mailboxes = cs_subset_bool(NeoMutt->sub, "browser_abbreviate_mailboxes");
826
827 STAILQ_FOREACH(np, &ml, entries)
828 {
829 if (!np->mailbox)
830 continue;
831
832 if (m && m->poll_new_mail && mutt_str_equal(np->mailbox->realpath, m->realpath))
833 {
834 np->mailbox->msg_count = m->msg_count;
835 np->mailbox->msg_unread = m->msg_unread;
836 }
837
839 if (c_browser_abbreviate_mailboxes)
841
842 switch (np->mailbox->type)
843 {
844 case MUTT_IMAP:
845 case MUTT_POP:
847 np->mailbox->name, NULL, np->mailbox, NULL);
848 continue;
849 case MUTT_NOTMUCH:
850 case MUTT_NNTP:
851 browser_add_folder(menu, state, mailbox_path(np->mailbox),
852 np->mailbox->name, NULL, np->mailbox, NULL);
853 continue;
854 default: /* Continue */
855 break;
856 }
857
858 if (lstat(mailbox_path(np->mailbox), &st) == -1)
859 continue;
860
861 if ((!S_ISREG(st.st_mode)) && (!S_ISDIR(st.st_mode)) && (!S_ISLNK(st.st_mode)))
862 continue;
863
864 if (np->mailbox->type == MUTT_MAILDIR)
865 {
866 struct stat st2 = { 0 };
867
868 buf_printf(md, "%s/new", mailbox_path(np->mailbox));
869 if (stat(buf_string(md), &st) < 0)
870 st.st_mtime = 0;
871 buf_printf(md, "%s/cur", mailbox_path(np->mailbox));
872 if (stat(buf_string(md), &st2) < 0)
873 st2.st_mtime = 0;
874 if (st2.st_mtime > st.st_mtime)
875 st.st_mtime = st2.st_mtime;
876 }
877
878 browser_add_folder(menu, state, buf_string(mailbox), np->mailbox->name,
879 &st, np->mailbox, NULL);
880 }
882 }
883 browser_sort(state);
884
885 buf_pool_release(&mailbox);
886 buf_pool_release(&md);
887 return 0;
888}
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:173
@ 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:562
#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:

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

979{
980 char title[256] = { 0 };
981 menu->max = ARRAY_SIZE(&state->entry);
982
983 int index = menu_get_index(menu);
984 if (index >= menu->max)
985 menu_set_index(menu, menu->max - 1);
986 if (index < 0)
987 menu_set_index(menu, 0);
988 if (menu->top > index)
989 menu->top = 0;
990
991 menu->num_tagged = 0;
992
993#ifdef USE_NNTP
994 if (OptNews)
995 {
996 if (state->is_mailbox_list)
997 {
998 snprintf(title, sizeof(title), _("Subscribed newsgroups"));
999 }
1000 else
1001 {
1002 snprintf(title, sizeof(title), _("Newsgroups on server [%s]"),
1004 }
1005 }
1006 else
1007#endif
1008 {
1009 if (state->is_mailbox_list)
1010 {
1011 snprintf(title, sizeof(title), _("Mailboxes [%d]"),
1013 }
1014 else
1015 {
1016 struct Buffer *path = buf_pool_get();
1017 buf_copy(path, &LastDir);
1018 buf_pretty_mailbox(path);
1019 const struct Regex *c_mask = cs_subset_regex(NeoMutt->sub, "mask");
1020#ifdef USE_IMAP
1021 const bool c_imap_list_subscribed = cs_subset_bool(NeoMutt->sub, "imap_list_subscribed");
1022 if (state->imap_browse && c_imap_list_subscribed)
1023 {
1024 snprintf(title, sizeof(title), _("Subscribed [%s], File mask: %s"),
1025 buf_string(path), NONULL(c_mask ? c_mask->pattern : NULL));
1026 }
1027 else
1028#endif
1029 {
1030 snprintf(title, sizeof(title), _("Directory [%s], File mask: %s"),
1031 buf_string(path), NONULL(c_mask ? c_mask->pattern : NULL));
1032 }
1033 buf_pool_release(&path);
1034 }
1035 }
1036 sbar_set_title(sbar, title);
1037
1038 /* Browser tracking feature.
1039 * The goal is to highlight the good directory if LastDir is the parent dir
1040 * of LastDirBackup (this occurs mostly when one hit "../"). It should also work
1041 * properly when the user is in examine_mailboxes-mode. */
1043 {
1044 char target_dir[PATH_MAX] = { 0 };
1045
1046#ifdef USE_IMAP
1047 /* Check what kind of dir LastDirBackup is. */
1049 {
1050 mutt_str_copy(target_dir, buf_string(&LastDirBackup), sizeof(target_dir));
1051 imap_clean_path(target_dir, sizeof(target_dir));
1052 }
1053 else
1054#endif
1055 mutt_str_copy(target_dir, strrchr(buf_string(&LastDirBackup), '/') + 1,
1056 sizeof(target_dir));
1057
1058 /* If we get here, it means that LastDir is the parent directory of
1059 * LastDirBackup. I.e., we're returning from a subdirectory, and we want
1060 * to position the cursor on the directory we're returning from. */
1061 bool matched = false;
1062 struct FolderFile *ff = NULL;
1063 ARRAY_FOREACH(ff, &state->entry)
1064 {
1065 if (mutt_str_equal(ff->name, target_dir))
1066 {
1067 menu_set_index(menu, ARRAY_FOREACH_IDX);
1068 matched = true;
1069 break;
1070 }
1071 }
1072 if (!matched)
1073 browser_highlight_default(state, menu);
1074 }
1075 else
1076 {
1077 browser_highlight_default(state, menu);
1078 }
1079
1081}
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:211
#define ARRAY_SIZE(head)
The number of elements stored.
Definition: array.h:86
size_t buf_copy(struct Buffer *dst, const struct Buffer *src)
Copy a Buffer's contents to another Buffer.
Definition: buffer.c:572
void browser_highlight_default(struct BrowserState *state, struct Menu *menu)
Decide which browser item should be highlighted.
Definition: dlg_browser.c:951
enum MailboxType imap_path_probe(const char *path, const struct stat *st)
Is this an IMAP Mailbox? - Implements MxOps::path_probe() -.
Definition: imap.c:2329
void imap_clean_path(char *path, size_t plen)
Cleans an IMAP path using imap_fix_path.
Definition: util.c:187
#define MENU_REDRAW_FULL
Redraw everything.
Definition: lib.h:60
void menu_queue_redraw(struct Menu *menu, MenuRedrawFlags redraw)
Queue a request for a redraw.
Definition: menu.c:180
int menu_get_index(struct Menu *menu)
Get the current selection in the Menu.
Definition: menu.c:156
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:653
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
bool imap_browse
IMAP folder.
Definition: lib.h:121
char host[128]
Server to login to.
Definition: connaccount.h:54
struct ConnAccount account
Account details: username, password, etc.
Definition: connection.h:50
int num_tagged
Number of tagged entries.
Definition: lib.h:84
struct Connection * conn
Connection to NNTP Server.
Definition: adata.h:62
char * pattern
printable version
Definition: regex3.h:90
+ 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 633 of file dlg_browser.c.

634{
635 ARRAY_INIT(&state->entry);
636 ARRAY_RESERVE(&state->entry, 256);
637#ifdef USE_IMAP
638 state->imap_browse = false;
639#endif
640 if (menu)
641 {
642 menu->mdata = &state->entry;
643 menu->mdata_free = NULL; // Menu doesn't own the data
644 }
645}
#define ARRAY_RESERVE(head, num)
Reserve memory for the array.
Definition: array.h:188
#define ARRAY_INIT(head)
Initialize an array.
Definition: array.h:64
void(* mdata_free)(struct Menu *menu, void **ptr)
Definition: lib.h:151
void * mdata
Private data.
Definition: lib.h:137
+ 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 173 of file functions.c.

174{
175 struct FolderFile *ff = NULL;
176 ARRAY_FOREACH(ff, &state->entry)
177 {
178 FREE(&ff->name);
179 FREE(&ff->desc);
180 }
181 ARRAY_FREE(&state->entry);
182
183#ifdef USE_IMAP
184 FREE(&state->folder);
185#endif
186}
#define ARRAY_FREE(head)
Release all memory.
Definition: array.h:203
#define FREE(x)
Definition: memory.h:45
char * folder
Folder name.
Definition: lib.h:122
+ 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.

◆ LastDirBackup

struct Buffer LastDirBackup
extern

Browser: backup copy of the current directory.

Definition at line 138 of file dlg_browser.c.

◆ CompleteFileOps

const struct CompleteOps CompleteFileOps
extern

Auto-Completion of Files.

Definition at line 153 of file complete.c.

◆ CompleteMailboxOps

const struct CompleteOps CompleteMailboxOps
extern

Auto-Completion of Files / Mailboxes.

Definition at line 160 of file complete.c.