NeoMutt  2022-04-29-215-gc12b98
Teaching an old dog new tricks
DOXYGEN
browser.c
Go to the documentation of this file.
1
69#include "config.h"
70#include <dirent.h>
71#include <errno.h>
72#include <grp.h>
73#include <limits.h>
74#include <locale.h>
75#include <pwd.h>
76#include <stdbool.h>
77#include <stdint.h>
78#include <stdio.h>
79#include <string.h>
80#include <sys/stat.h>
81#include "mutt/lib.h"
82#include "config/lib.h"
83#include "core/lib.h"
84#include "conn/lib.h"
85#include "gui/lib.h"
86#include "lib.h"
87#include "menu/lib.h"
88#include "format_flags.h"
89#include "functions.h"
90#include "keymap.h"
91#include "mutt_globals.h"
92#include "mutt_logging.h"
93#include "mutt_mailbox.h"
94#include "muttlib.h"
95#include "mx.h"
96#include "opcodes.h"
97#include "options.h"
98#include "private_data.h"
99#ifdef USE_IMAP
100#include "imap/lib.h"
101#endif
102#ifdef USE_NNTP
103#include "nntp/lib.h"
104#include "nntp/adata.h" // IWYU pragma: keep
105#include "nntp/mdata.h" // IWYU pragma: keep
106#endif
107
109static const struct Mapping FolderHelp[] = {
110 // clang-format off
111 { N_("Exit"), OP_EXIT },
112 { N_("Chdir"), OP_CHANGE_DIRECTORY },
113 { N_("Goto"), OP_BROWSER_GOTO_FOLDER },
114 { N_("Mask"), OP_ENTER_MASK },
115 { N_("Help"), OP_HELP },
116 { NULL, 0 },
117 // clang-format on
118};
119
120#ifdef USE_NNTP
122static const struct Mapping FolderNewsHelp[] = {
123 // clang-format off
124 { N_("Exit"), OP_EXIT },
125 { N_("List"), OP_TOGGLE_MAILBOXES },
126 { N_("Subscribe"), OP_BROWSER_SUBSCRIBE },
127 { N_("Unsubscribe"), OP_BROWSER_UNSUBSCRIBE },
128 { N_("Catchup"), OP_CATCHUP },
129 { N_("Mask"), OP_ENTER_MASK },
130 { N_("Help"), OP_HELP },
131 { NULL, 0 },
132 // clang-format on
133};
134#endif
135
136struct Buffer LastDir = { 0 };
137struct Buffer LastDirBackup = { 0 };
138
144static void init_lastdir(void)
145{
146 static bool done = false;
147 if (!done)
148 {
151 done = true;
152 }
153}
154
159{
162}
163
171bool link_is_dir(const char *folder, const char *path)
172{
173 struct stat st = { 0 };
174 bool retval = false;
175
176 struct Buffer *fullpath = mutt_buffer_pool_get();
177 mutt_buffer_concat_path(fullpath, folder, path);
178
179 if (stat(mutt_buffer_string(fullpath), &st) == 0)
180 retval = S_ISDIR(st.st_mode);
181
182 mutt_buffer_pool_release(&fullpath);
183
184 return retval;
185}
186
207static const char *folder_format_str(char *buf, size_t buflen, size_t col, int cols,
208 char op, const char *src, const char *prec,
209 const char *if_str, const char *else_str,
210 intptr_t data, MuttFormatFlags flags)
211{
212 char fn[128], fmt[128];
213 struct Folder *folder = (struct Folder *) data;
214 bool optional = (flags & MUTT_FORMAT_OPTIONAL);
215
216 switch (op)
217 {
218 case 'C':
219 snprintf(fmt, sizeof(fmt), "%%%sd", prec);
220 snprintf(buf, buflen, fmt, folder->num + 1);
221 break;
222
223 case 'd':
224 case 'D':
225 if (folder->ff->local)
226 {
227 bool do_locales = true;
228
229 const char *t_fmt = NULL;
230 if (op == 'D')
231 {
232 const char *const c_date_format = cs_subset_string(NeoMutt->sub, "date_format");
233 t_fmt = NONULL(c_date_format);
234 if (*t_fmt == '!')
235 {
236 t_fmt++;
237 do_locales = false;
238 }
239 }
240 else
241 {
242 static const time_t one_year = 31536000;
243 t_fmt = ((mutt_date_epoch() - folder->ff->mtime) < one_year) ? "%b %d %H:%M" : "%b %d %Y";
244 }
245
246 if (!do_locales)
247 setlocale(LC_TIME, "C");
248 char date[128] = { 0 };
249 mutt_date_localtime_format(date, sizeof(date), t_fmt, folder->ff->mtime);
250 if (!do_locales)
251 setlocale(LC_TIME, "");
252
253 mutt_format_s(buf, buflen, prec, date);
254 }
255 else
256 {
257 mutt_format_s(buf, buflen, prec, "");
258 }
259 break;
260
261 case 'f':
262 {
263 char *s = NULL;
264
265 s = NONULL(folder->ff->name);
266
267 snprintf(fn, sizeof(fn), "%s%s", s,
268 folder->ff->local ?
269 (S_ISLNK(folder->ff->mode) ?
270 "@" :
271 (S_ISDIR(folder->ff->mode) ?
272 "/" :
273 (((folder->ff->mode & S_IXUSR) != 0) ? "*" : ""))) :
274 "");
275
276 mutt_format_s(buf, buflen, prec, fn);
277 break;
278 }
279 case 'F':
280 {
281 if (folder->ff->local)
282 {
283 char permission[11] = { 0 };
284 snprintf(permission, sizeof(permission), "%c%c%c%c%c%c%c%c%c%c",
285 S_ISDIR(folder->ff->mode) ? 'd' : (S_ISLNK(folder->ff->mode) ? 'l' : '-'),
286 ((folder->ff->mode & S_IRUSR) != 0) ? 'r' : '-',
287 ((folder->ff->mode & S_IWUSR) != 0) ? 'w' : '-',
288 ((folder->ff->mode & S_ISUID) != 0) ? 's' :
289 ((folder->ff->mode & S_IXUSR) != 0) ? 'x' :
290 '-',
291 ((folder->ff->mode & S_IRGRP) != 0) ? 'r' : '-',
292 ((folder->ff->mode & S_IWGRP) != 0) ? 'w' : '-',
293 ((folder->ff->mode & S_ISGID) != 0) ? 's' :
294 ((folder->ff->mode & S_IXGRP) != 0) ? 'x' :
295 '-',
296 ((folder->ff->mode & S_IROTH) != 0) ? 'r' : '-',
297 ((folder->ff->mode & S_IWOTH) != 0) ? 'w' : '-',
298 ((folder->ff->mode & S_ISVTX) != 0) ? 't' :
299 ((folder->ff->mode & S_IXOTH) != 0) ? 'x' :
300 '-');
301 mutt_format_s(buf, buflen, prec, permission);
302 }
303#ifdef USE_IMAP
304 else if (folder->ff->imap)
305 {
306 char permission[11] = { 0 };
307 /* mark folders with subfolders AND mail */
308 snprintf(permission, sizeof(permission), "IMAP %c",
309 (folder->ff->inferiors && folder->ff->selectable) ? '+' : ' ');
310 mutt_format_s(buf, buflen, prec, permission);
311 }
312#endif
313 else
314 mutt_format_s(buf, buflen, prec, "");
315 break;
316 }
317
318 case 'g':
319 if (folder->ff->local)
320 {
321 struct group *gr = getgrgid(folder->ff->gid);
322 if (gr)
323 {
324 mutt_format_s(buf, buflen, prec, gr->gr_name);
325 }
326 else
327 {
328 snprintf(fmt, sizeof(fmt), "%%%sld", prec);
329 snprintf(buf, buflen, fmt, folder->ff->gid);
330 }
331 }
332 else
333 {
334 mutt_format_s(buf, buflen, prec, "");
335 }
336 break;
337
338 case 'i':
339 {
340 char *s = NULL;
341 if (folder->ff->desc)
342 s = folder->ff->desc;
343 else
344 s = folder->ff->name;
345
346 snprintf(fn, sizeof(fn), "%s%s", s,
347 folder->ff->local ?
348 (S_ISLNK(folder->ff->mode) ?
349 "@" :
350 (S_ISDIR(folder->ff->mode) ?
351 "/" :
352 (((folder->ff->mode & S_IXUSR) != 0) ? "*" : ""))) :
353 "");
354
355 mutt_format_s(buf, buflen, prec, fn);
356 break;
357 }
358
359 case 'l':
360 if (folder->ff->local)
361 {
362 snprintf(fmt, sizeof(fmt), "%%%sd", prec);
363 snprintf(buf, buflen, fmt, folder->ff->nlink);
364 }
365 else
366 {
367 mutt_format_s(buf, buflen, prec, "");
368 }
369 break;
370
371 case 'm':
372 if (!optional)
373 {
374 if (folder->ff->has_mailbox)
375 {
376 snprintf(fmt, sizeof(fmt), "%%%sd", prec);
377 snprintf(buf, buflen, fmt, folder->ff->msg_count);
378 }
379 else
380 {
381 mutt_format_s(buf, buflen, prec, "");
382 }
383 }
384 else if (folder->ff->msg_count == 0)
385 optional = false;
386 break;
387
388 case 'N':
389 snprintf(fmt, sizeof(fmt), "%%%sc", prec);
390 snprintf(buf, buflen, fmt, folder->ff->has_new_mail ? 'N' : ' ');
391 break;
392
393 case 'n':
394 if (!optional)
395 {
396 if (folder->ff->has_mailbox)
397 {
398 snprintf(fmt, sizeof(fmt), "%%%sd", prec);
399 snprintf(buf, buflen, fmt, folder->ff->msg_unread);
400 }
401 else
402 {
403 mutt_format_s(buf, buflen, prec, "");
404 }
405 }
406 else if (folder->ff->msg_unread == 0)
407 optional = false;
408 break;
409
410 case 's':
411 if (folder->ff->local)
412 {
413 mutt_str_pretty_size(fn, sizeof(fn), folder->ff->size);
414 snprintf(fmt, sizeof(fmt), "%%%ss", prec);
415 snprintf(buf, buflen, fmt, fn);
416 }
417 else
418 {
419 mutt_format_s(buf, buflen, prec, "");
420 }
421 break;
422
423 case 't':
424 snprintf(fmt, sizeof(fmt), "%%%sc", prec);
425 snprintf(buf, buflen, fmt, folder->ff->tagged ? '*' : ' ');
426 break;
427
428 case 'u':
429 if (folder->ff->local)
430 {
431 struct passwd *pw = getpwuid(folder->ff->uid);
432 if (pw)
433 {
434 mutt_format_s(buf, buflen, prec, pw->pw_name);
435 }
436 else
437 {
438 snprintf(fmt, sizeof(fmt), "%%%sld", prec);
439 snprintf(buf, buflen, fmt, folder->ff->uid);
440 }
441 }
442 else
443 {
444 mutt_format_s(buf, buflen, prec, "");
445 }
446 break;
447
448 default:
449 snprintf(fmt, sizeof(fmt), "%%%sc", prec);
450 snprintf(buf, buflen, fmt, op);
451 break;
452 }
453
454 if (optional)
455 {
456 mutt_expando_format(buf, buflen, col, cols, if_str, folder_format_str, data,
458 }
459 else if (flags & MUTT_FORMAT_OPTIONAL)
460 {
461 mutt_expando_format(buf, buflen, col, cols, else_str, folder_format_str,
463 }
464
465 /* We return the format string, unchanged */
466 return src;
467}
468
479void browser_add_folder(const struct Menu *menu, struct BrowserState *state,
480 const char *name, const char *desc,
481 const struct stat *st, struct Mailbox *m, void *data)
482{
483 if ((!menu || state->is_mailbox_list) && m && !m->visible)
484 {
485 return;
486 }
487
488 struct FolderFile ff = { 0 };
489
490 if (st)
491 {
492 ff.mode = st->st_mode;
493 ff.mtime = st->st_mtime;
494 ff.size = st->st_size;
495 ff.gid = st->st_gid;
496 ff.uid = st->st_uid;
497 ff.nlink = st->st_nlink;
498 ff.local = true;
499 }
500 else
501 {
502 ff.local = false;
503 }
504
505 if (m)
506 {
507 ff.has_mailbox = true;
508 ff.gen = m->gen;
509 ff.has_new_mail = m->has_new;
510 ff.msg_count = m->msg_count;
511 ff.msg_unread = m->msg_unread;
512 }
513
514 ff.name = mutt_str_dup(name);
515 ff.desc = mutt_str_dup(desc ? desc : name);
516#ifdef USE_IMAP
517 ff.imap = false;
518#endif
519#ifdef USE_NNTP
520 if (OptNews)
521 ff.nd = data;
522#endif
523
524 ARRAY_ADD(&state->entry, ff);
525}
526
532void init_state(struct BrowserState *state, struct Menu *menu)
533{
534 ARRAY_INIT(&state->entry);
535 ARRAY_RESERVE(&state->entry, 256);
536#ifdef USE_IMAP
537 state->imap_browse = false;
538#endif
539 if (menu)
540 {
541 menu->mdata = &state->entry;
542 menu->mdata_free = NULL; // Menu doesn't own the data
543 }
544}
545
556int examine_directory(struct Mailbox *m, struct Menu *menu,
557 struct BrowserState *state, const char *d, const char *prefix)
558{
559 int rc = -1;
560 struct Buffer *buf = mutt_buffer_pool_get();
561#ifdef USE_NNTP
562 if (OptNews)
563 {
565
566 init_state(state, menu);
567
568 for (unsigned int i = 0; i < adata->groups_num; i++)
569 {
570 struct NntpMboxData *mdata = adata->groups_list[i];
571 if (!mdata)
572 continue;
573 if (prefix && *prefix && !mutt_str_startswith(mdata->group, prefix))
574 continue;
575 const struct Regex *c_mask = cs_subset_regex(NeoMutt->sub, "mask");
576 if (!mutt_regex_match(c_mask, mdata->group))
577 {
578 continue;
579 }
580 browser_add_folder(menu, state, mdata->group, NULL, NULL, NULL, mdata);
581 }
582 }
583 else
584#endif /* USE_NNTP */
585 {
586 struct stat st = { 0 };
587 DIR *dp = NULL;
588 struct dirent *de = NULL;
589
590 while (stat(d, &st) == -1)
591 {
592 if (errno == ENOENT)
593 {
594 /* The last used directory is deleted, try to use the parent dir. */
595 char *c = strrchr(d, '/');
596
597 if (c && (c > d))
598 {
599 *c = '\0';
600 continue;
601 }
602 }
603 mutt_perror(d);
604 goto ed_out;
605 }
606
607 if (!S_ISDIR(st.st_mode))
608 {
609 mutt_error(_("%s is not a directory"), d);
610 goto ed_out;
611 }
612
613 if (m)
615
616 dp = opendir(d);
617 if (!dp)
618 {
619 mutt_perror(d);
620 goto ed_out;
621 }
622
623 init_state(state, menu);
624
625 struct MailboxList ml = STAILQ_HEAD_INITIALIZER(ml);
627 while ((de = readdir(dp)))
628 {
629 if (mutt_str_equal(de->d_name, "."))
630 continue; /* we don't need . */
631
632 if (prefix && *prefix && !mutt_str_startswith(de->d_name, prefix))
633 {
634 continue;
635 }
636 const struct Regex *c_mask = cs_subset_regex(NeoMutt->sub, "mask");
637 if (!mutt_regex_match(c_mask, de->d_name))
638 {
639 continue;
640 }
641
642 mutt_buffer_concat_path(buf, d, de->d_name);
643 if (lstat(mutt_buffer_string(buf), &st) == -1)
644 continue;
645
646 /* No size for directories or symlinks */
647 if (S_ISDIR(st.st_mode) || S_ISLNK(st.st_mode))
648 st.st_size = 0;
649 else if (!S_ISREG(st.st_mode))
650 continue;
651
652 struct MailboxNode *np = NULL;
653 STAILQ_FOREACH(np, &ml, entries)
654 {
656 break;
657 }
658
659 if (np && m && mutt_str_equal(np->mailbox->realpath, m->realpath))
660 {
661 np->mailbox->msg_count = m->msg_count;
662 np->mailbox->msg_unread = m->msg_unread;
663 }
664 browser_add_folder(menu, state, de->d_name, NULL, &st, np ? np->mailbox : NULL, NULL);
665 }
667 closedir(dp);
668 }
669 browser_sort(state);
670 rc = 0;
671ed_out:
673 return rc;
674}
675
684int examine_mailboxes(struct Mailbox *m, struct Menu *menu, struct BrowserState *state)
685{
686 struct stat st = { 0 };
687 struct Buffer *md = NULL;
688 struct Buffer *mailbox = NULL;
689
690#ifdef USE_NNTP
691 if (OptNews)
692 {
694
695 init_state(state, menu);
696
697 for (unsigned int i = 0; i < adata->groups_num; i++)
698 {
699 const bool c_show_only_unread = cs_subset_bool(NeoMutt->sub, "show_only_unread");
700 struct NntpMboxData *mdata = adata->groups_list[i];
701 if (mdata && (mdata->has_new_mail ||
702 (mdata->subscribed && (mdata->unread || !c_show_only_unread))))
703 {
704 browser_add_folder(menu, state, mdata->group, NULL, NULL, NULL, mdata);
705 }
706 }
707 }
708 else
709#endif
710 {
711 init_state(state, menu);
712
714 return -1;
715 mailbox = mutt_buffer_pool_get();
717
719
720 struct MailboxList ml = STAILQ_HEAD_INITIALIZER(ml);
722 struct MailboxNode *np = NULL;
723 STAILQ_FOREACH(np, &ml, entries)
724 {
725 if (!np->mailbox)
726 continue;
727
728 if (m && mutt_str_equal(np->mailbox->realpath, m->realpath))
729 {
730 np->mailbox->msg_count = m->msg_count;
731 np->mailbox->msg_unread = m->msg_unread;
732 }
733
735 const bool c_browser_abbreviate_mailboxes = cs_subset_bool(NeoMutt->sub, "browser_abbreviate_mailboxes");
736 if (c_browser_abbreviate_mailboxes)
738
739 switch (np->mailbox->type)
740 {
741 case MUTT_IMAP:
742 case MUTT_POP:
744 np->mailbox->name, NULL, np->mailbox, NULL);
745 continue;
746 case MUTT_NOTMUCH:
747 case MUTT_NNTP:
748 browser_add_folder(menu, state, mailbox_path(np->mailbox),
749 np->mailbox->name, NULL, np->mailbox, NULL);
750 continue;
751 default: /* Continue */
752 break;
753 }
754
755 if (lstat(mailbox_path(np->mailbox), &st) == -1)
756 continue;
757
758 if ((!S_ISREG(st.st_mode)) && (!S_ISDIR(st.st_mode)) && (!S_ISLNK(st.st_mode)))
759 continue;
760
761 if (np->mailbox->type == MUTT_MAILDIR)
762 {
763 struct stat st2 = { 0 };
764
765 mutt_buffer_printf(md, "%s/new", mailbox_path(np->mailbox));
766 if (stat(mutt_buffer_string(md), &st) < 0)
767 st.st_mtime = 0;
768 mutt_buffer_printf(md, "%s/cur", mailbox_path(np->mailbox));
769 if (stat(mutt_buffer_string(md), &st2) < 0)
770 st2.st_mtime = 0;
771 if (st2.st_mtime > st.st_mtime)
772 st.st_mtime = st2.st_mtime;
773 }
774
775 browser_add_folder(menu, state, mutt_buffer_string(mailbox),
776 np->mailbox->name, &st, np->mailbox, NULL);
777 }
779 }
780 browser_sort(state);
781
782 mutt_buffer_pool_release(&mailbox);
784 return 0;
785}
786
790static int select_file_search(struct Menu *menu, regex_t *rx, int line)
791{
792 struct BrowserStateEntry *entry = menu->mdata;
793#ifdef USE_NNTP
794 if (OptNews)
795 return regexec(rx, ARRAY_GET(entry, line)->desc, 0, NULL, 0);
796#endif
797 struct FolderFile *ff = ARRAY_GET(entry, line);
798 char *search_on = ff->desc ? ff->desc : ff->name;
799
800 return regexec(rx, search_on, 0, NULL, 0);
801}
802
806static void folder_make_entry(struct Menu *menu, char *buf, size_t buflen, int line)
807{
808 struct BrowserState *state = menu->mdata;
809 struct BrowserStateEntry *entry = &state->entry;
810 struct Folder folder = {
811 .ff = ARRAY_GET(entry, line),
812 .num = line,
813 };
814
815#ifdef USE_NNTP
816 if (OptNews)
817 {
818 const char *const c_group_index_format = cs_subset_string(NeoMutt->sub, "group_index_format");
819 mutt_expando_format(buf, buflen, 0, menu->win->state.cols,
820 NONULL(c_group_index_format), group_index_format_str,
821 (intptr_t) &folder, MUTT_FORMAT_ARROWCURSOR);
822 }
823 else
824#endif
825 if (state->is_mailbox_list)
826 {
827 const char *const c_mailbox_folder_format = cs_subset_string(NeoMutt->sub, "mailbox_folder_format");
828 mutt_expando_format(buf, buflen, 0, menu->win->state.cols,
829 NONULL(c_mailbox_folder_format), folder_format_str,
830 (intptr_t) &folder, MUTT_FORMAT_ARROWCURSOR);
831 }
832 else
833 {
834 const char *const c_folder_format = cs_subset_string(NeoMutt->sub, "folder_format");
835 mutt_expando_format(buf, buflen, 0, menu->win->state.cols, NONULL(c_folder_format),
836 folder_format_str, (intptr_t) &folder, MUTT_FORMAT_ARROWCURSOR);
837 }
838}
839
848void browser_highlight_default(struct BrowserState *state, struct Menu *menu)
849{
850 menu->top = 0;
851 /* Reset menu position to 1.
852 * We do not risk overflow as the init_menu function changes
853 * current if it is bigger than state->entrylen. */
854 if (!ARRAY_EMPTY(&state->entry) &&
855 (mutt_str_equal(ARRAY_FIRST(&state->entry)->desc, "..") ||
856 mutt_str_equal(ARRAY_FIRST(&state->entry)->desc, "../")))
857 {
858 /* Skip the first entry, unless there's only one entry. */
859 menu_set_index(menu, (menu->max > 1));
860 }
861 else
862 {
863 menu_set_index(menu, 0);
864 }
865}
866
874void init_menu(struct BrowserState *state, struct Menu *menu, struct Mailbox *m,
875 struct MuttWindow *sbar)
876{
877 char title[256] = { 0 };
878 menu->max = ARRAY_SIZE(&state->entry);
879
880 int index = menu_get_index(menu);
881 if (index >= menu->max)
882 menu_set_index(menu, menu->max - 1);
883 if (index < 0)
884 menu_set_index(menu, 0);
885 if (menu->top > index)
886 menu->top = 0;
887
888 menu->num_tagged = 0;
889
890#ifdef USE_NNTP
891 if (OptNews)
892 {
893 if (state->is_mailbox_list)
894 {
895 snprintf(title, sizeof(title), _("Subscribed newsgroups"));
896 }
897 else
898 {
899 snprintf(title, sizeof(title), _("Newsgroups on server [%s]"),
901 }
902 }
903 else
904#endif
905 {
906 if (state->is_mailbox_list)
907 {
908 snprintf(title, sizeof(title), _("Mailboxes [%d]"),
910 }
911 else
912 {
913 struct Buffer *path = mutt_buffer_pool_get();
916 const struct Regex *c_mask = cs_subset_regex(NeoMutt->sub, "mask");
917#ifdef USE_IMAP
918 const bool c_imap_list_subscribed = cs_subset_bool(NeoMutt->sub, "imap_list_subscribed");
919 if (state->imap_browse && c_imap_list_subscribed)
920 {
921 snprintf(title, sizeof(title), _("Subscribed [%s], File mask: %s"),
922 mutt_buffer_string(path), NONULL(c_mask ? c_mask->pattern : NULL));
923 }
924 else
925#endif
926 {
927 snprintf(title, sizeof(title), _("Directory [%s], File mask: %s"),
928 mutt_buffer_string(path), NONULL(c_mask ? c_mask->pattern : NULL));
929 }
931 }
932 }
933 sbar_set_title(sbar, title);
934
935 /* Browser tracking feature.
936 * The goal is to highlight the good directory if LastDir is the parent dir
937 * of LastDirBackup (this occurs mostly when one hit "../"). It should also work
938 * properly when the user is in examine_mailboxes-mode. */
940 {
941 char target_dir[PATH_MAX] = { 0 };
942
943#ifdef USE_IMAP
944 /* Check what kind of dir LastDirBackup is. */
946 {
947 mutt_str_copy(target_dir, mutt_buffer_string(&LastDirBackup), sizeof(target_dir));
948 imap_clean_path(target_dir, sizeof(target_dir));
949 }
950 else
951#endif
952 mutt_str_copy(target_dir, strrchr(mutt_buffer_string(&LastDirBackup), '/') + 1,
953 sizeof(target_dir));
954
955 /* If we get here, it means that LastDir is the parent directory of
956 * LastDirBackup. I.e., we're returning from a subdirectory, and we want
957 * to position the cursor on the directory we're returning from. */
958 bool matched = false;
959 struct FolderFile *ff = NULL;
960 ARRAY_FOREACH(ff, &state->entry)
961 {
962 if (mutt_str_equal(ff->name, target_dir))
963 {
964 menu_set_index(menu, ARRAY_FOREACH_IDX);
965 matched = true;
966 break;
967 }
968 }
969 if (!matched)
970 browser_highlight_default(state, menu);
971 }
972 else
973 {
974 browser_highlight_default(state, menu);
975 }
976
978}
979
983static int file_tag(struct Menu *menu, int sel, int act)
984{
985 struct BrowserStateEntry *entry = menu->mdata;
986 struct FolderFile *ff = ARRAY_GET(entry, sel);
987 if (S_ISDIR(ff->mode) ||
988 (S_ISLNK(ff->mode) && link_is_dir(mutt_buffer_string(&LastDir), ff->name)))
989 {
990 mutt_error(_("Can't attach a directory"));
991 return 0;
992 }
993
994 bool ot = ff->tagged;
995 ff->tagged = ((act >= 0) ? act : !ff->tagged);
996
997 return ff->tagged - ot;
998}
999
1004{
1005 if (nc->event_type != NT_CONFIG)
1006 return 0;
1007 if (!nc->global_data || !nc->event_data)
1008 return -1;
1009
1010 struct EventConfig *ev_c = nc->event_data;
1011
1012 if (!mutt_str_equal(ev_c->name, "browser_abbreviate_mailboxes") &&
1013 !mutt_str_equal(ev_c->name, "date_format") && !mutt_str_equal(ev_c->name, "folder") &&
1014 !mutt_str_equal(ev_c->name, "folder_format") &&
1015 !mutt_str_equal(ev_c->name, "group_index_format") &&
1016 !mutt_str_equal(ev_c->name, "sort_browser"))
1017 {
1018 return 0;
1019 }
1020
1021 struct Menu *menu = nc->global_data;
1023 mutt_debug(LL_DEBUG5, "config done, request WA_RECALC, MENU_REDRAW_FULL\n");
1024
1025 return 0;
1026}
1027
1036{
1037 if (nc->event_type != NT_WINDOW)
1038 return 0;
1039 if (!nc->global_data || !nc->event_data)
1040 return -1;
1042 return 0;
1043
1044 struct MuttWindow *win_menu = nc->global_data;
1045 struct EventWindow *ev_w = nc->event_data;
1046 if (ev_w->win != win_menu)
1047 return 0;
1048
1049 struct Menu *menu = win_menu->wdata;
1050
1053
1054 mutt_debug(LL_DEBUG5, "window delete done\n");
1055 return 0;
1056}
1057
1068void mutt_browser_select_dir(const char *f)
1069{
1070 init_lastdir();
1071
1073
1074 /* Method that will fetch the parent path depending on the type of the path. */
1075 char buf[PATH_MAX] = { 0 };
1078}
1079
1089 struct Mailbox *m, char ***files, int *numfiles)
1090{
1092 priv->file = file;
1093 priv->mailbox = m;
1094 priv->files = files;
1095 priv->numfiles = numfiles;
1096 struct MuttWindow *dlg = NULL;
1097
1098 priv->multiple = (flags & MUTT_SEL_MULTI);
1099 priv->folder = (flags & MUTT_SEL_FOLDER);
1100 priv->state.is_mailbox_list = (flags & MUTT_SEL_MAILBOX) && priv->folder;
1101 priv->last_selected_mailbox = -1;
1102
1103 init_lastdir();
1104
1105#ifdef USE_NNTP
1106 if (OptNews)
1107 {
1108 if (mutt_buffer_is_empty(file))
1109 {
1111
1112 /* default state for news reader mode is browse subscribed newsgroups */
1113 priv->state.is_mailbox_list = false;
1114 for (size_t i = 0; i < adata->groups_num; i++)
1115 {
1116 struct NntpMboxData *mdata = adata->groups_list[i];
1117 if (mdata && mdata->subscribed)
1118 {
1119 priv->state.is_mailbox_list = true;
1120 break;
1121 }
1122 }
1123 }
1124 else
1125 {
1126 mutt_buffer_copy(priv->prefix, file);
1127 }
1128 }
1129 else
1130#endif
1131 if (!mutt_buffer_is_empty(file))
1132 {
1134#ifdef USE_IMAP
1135 if (imap_path_probe(mutt_buffer_string(file), NULL) == MUTT_IMAP)
1136 {
1137 init_state(&priv->state, NULL);
1138 priv->state.imap_browse = true;
1139 if (imap_browse(mutt_buffer_string(file), &priv->state) == 0)
1140 {
1142 browser_sort(&priv->state);
1143 }
1144 }
1145 else
1146 {
1147#endif
1148 int i;
1149 for (i = mutt_buffer_len(file) - 1;
1150 (i > 0) && ((mutt_buffer_string(file))[i] != '/'); i--)
1151 {
1152 ; // do nothing
1153 }
1154
1155 if (i > 0)
1156 {
1157 if ((mutt_buffer_string(file))[0] == '/')
1158 {
1160 }
1161 else
1162 {
1166 }
1167 }
1168 else
1169 {
1170 if ((mutt_buffer_string(file))[0] == '/')
1172 else
1174 }
1175
1176 if ((i <= 0) && (mutt_buffer_string(file)[0] != '/'))
1177 mutt_buffer_copy(priv->prefix, file);
1178 else
1179 mutt_buffer_strcpy(priv->prefix, mutt_buffer_string(file) + i + 1);
1180 priv->kill_prefix = true;
1181#ifdef USE_IMAP
1182 }
1183#endif
1184 }
1185 else
1186 {
1187 if (!priv->folder)
1188 {
1190 }
1191 else
1192 {
1193 /* Whether we use the tracking feature of the browser depends
1194 * on which sort method we chose to use. This variable is defined
1195 * only to help readability of the code. */
1196 bool browser_track = false;
1197
1198 const short c_sort_browser = cs_subset_sort(NeoMutt->sub, "sort_browser");
1199 switch (c_sort_browser & SORT_MASK)
1200 {
1201 case SORT_DESC:
1202 case SORT_SUBJECT:
1203 case SORT_ORDER:
1204 browser_track = true;
1205 break;
1206 }
1207
1208 /* We use mutt_browser_select_dir to initialize the two
1209 * variables (LastDir, LastDirBackup) at the appropriate
1210 * values.
1211 *
1212 * We do it only when LastDir is not set (first pass there)
1213 * or when CurrentFolder and LastDirBackup are not the same.
1214 * This code is executed only when we list files, not when
1215 * we press up/down keys to navigate in a displayed list.
1216 *
1217 * We only do this when CurrentFolder has been set (ie, not
1218 * when listing folders on startup with "neomutt -y").
1219 *
1220 * This tracker is only used when browser_track is true,
1221 * meaning only with sort methods SUBJECT/DESC for now. */
1222 if (CurrentFolder)
1223 {
1225 {
1226 /* If browsing in "local"-mode, than we chose to define LastDir to
1227 * MailDir */
1229 {
1230 case MUTT_IMAP:
1231 case MUTT_MAILDIR:
1232 case MUTT_MBOX:
1233 case MUTT_MH:
1234 case MUTT_MMDF:
1235 {
1236 const char *const c_folder = cs_subset_string(NeoMutt->sub, "folder");
1237 const char *const c_spool_file = cs_subset_string(NeoMutt->sub, "spool_file");
1238 if (c_folder)
1239 mutt_buffer_strcpy(&LastDir, c_folder);
1240 else if (c_spool_file)
1241 mutt_browser_select_dir(c_spool_file);
1242 break;
1243 }
1244 default:
1246 break;
1247 }
1248 }
1250 {
1252 }
1253 }
1254
1255 /* When browser tracking feature is disabled, clear LastDirBackup */
1256 if (!browser_track)
1258 }
1259
1260#ifdef USE_IMAP
1261 if (!priv->state.is_mailbox_list &&
1263 {
1264 init_state(&priv->state, NULL);
1265 priv->state.imap_browse = true;
1267 browser_sort(&priv->state);
1268 }
1269 else
1270#endif
1271 {
1272 size_t i = mutt_buffer_len(&LastDir);
1273 while ((i > 0) && (mutt_buffer_string(&LastDir)[--i] == '/'))
1274 LastDir.data[i] = '\0';
1278 }
1279 }
1280
1281 mutt_buffer_reset(file);
1282
1283 const struct Mapping *help_data = NULL;
1284#ifdef USE_NNTP
1285 if (OptNews)
1286 help_data = FolderNewsHelp;
1287 else
1288#endif
1289 help_data = FolderHelp;
1290
1291 dlg = simple_dialog_new(MENU_FOLDER, WT_DLG_BROWSER, help_data);
1292
1293 priv->menu = dlg->wdata;
1294 dlg->wdata = priv;
1297 if (priv->multiple)
1298 priv->menu->tag = file_tag;
1299
1300 priv->sbar = window_find_child(dlg, WT_STATUS_BAR);
1302
1303 struct MuttWindow *win_menu = priv->menu->win;
1304
1305 // NT_COLOR is handled by the SimpleDialog
1308
1309 if (priv->state.is_mailbox_list)
1310 {
1311 examine_mailboxes(m, NULL, &priv->state);
1312 }
1313 else
1314#ifdef USE_IMAP
1315 if (!priv->state.imap_browse)
1316#endif
1317 {
1318 // examine_directory() calls browser_add_folder() which needs the menu
1319 if (examine_directory(m, priv->menu, &priv->state, mutt_buffer_string(&LastDir),
1320 mutt_buffer_string(priv->prefix)) == -1)
1321 {
1322 goto bail;
1323 }
1324 }
1325
1326 init_menu(&priv->state, priv->menu, m, priv->sbar);
1327 // only now do we have a valid priv->state to attach
1328 priv->menu->mdata = &priv->state;
1329
1330 // ---------------------------------------------------------------------------
1331 // Event Loop
1332 int op = OP_NULL;
1333 do
1334 {
1335 menu_tagging_dispatcher(priv->menu->win, op);
1336 window_redraw(NULL);
1337
1338 op = km_dokey(MENU_FOLDER);
1339 mutt_debug(LL_DEBUG1, "Got op %s (%d)\n", opcodes_get_name(op), op);
1340 if (op < 0)
1341 continue;
1342 if (op == OP_NULL)
1343 {
1345 continue;
1346 }
1348
1349 int rc = browser_function_dispatcher(priv->win_browser, op);
1350
1351 if (rc == FR_UNKNOWN)
1352 rc = menu_function_dispatcher(priv->menu->win, op);
1353 if (rc == FR_UNKNOWN)
1354 rc = global_function_dispatcher(NULL, op);
1355 } while (!priv->done);
1356 // ---------------------------------------------------------------------------
1357
1358bail:
1359 simple_dialog_free(&dlg);
1361}
1362
1372void mutt_select_file(char *file, size_t filelen, SelectFileFlags flags,
1373 struct Mailbox *m, char ***files, int *numfiles)
1374{
1375 struct Buffer *f_buf = mutt_buffer_pool_get();
1376
1377 mutt_buffer_strcpy(f_buf, NONULL(file));
1378 mutt_buffer_select_file(f_buf, flags, m, files, numfiles);
1379 mutt_str_copy(file, mutt_buffer_string(f_buf), filelen);
1380
1382}
#define ARRAY_RESERVE(head, num)
Reserve memory for the array.
Definition: array.h:188
#define ARRAY_FIRST(head)
Convenience method to get the first element.
Definition: array.h:134
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition: array.h:155
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:211
#define ARRAY_EMPTY(head)
Check if an array is empty.
Definition: array.h:73
#define ARRAY_SIZE(head)
The number of elements stored.
Definition: array.h:86
#define ARRAY_INIT(head)
Initialize an array.
Definition: array.h:64
#define ARRAY_GET(head, idx)
Return the element at index.
Definition: array.h:108
int browser_function_dispatcher(struct MuttWindow *win_browser, int op)
Perform a Browser function.
Definition: functions.c:1143
#define MUTT_SEL_MAILBOX
Select a mailbox.
Definition: lib.h:56
void browser_sort(struct BrowserState *state)
Sort the entries in the browser.
Definition: sort.c:194
#define MUTT_SEL_FOLDER
Select a local directory.
Definition: lib.h:58
#define MUTT_SEL_MULTI
Multi-selection is enabled.
Definition: lib.h:57
uint8_t SelectFileFlags
Flags for mutt_select_file(), e.g. MUTT_SEL_MAILBOX.
Definition: lib.h:54
struct BrowserPrivateData * browser_private_data_new(void)
Create new Browser Data.
Definition: private_data.c:54
void mutt_select_file(char *file, size_t filelen, SelectFileFlags flags, struct Mailbox *m, char ***files, int *numfiles)
Let the user select a file.
Definition: browser.c:1372
void init_state(struct BrowserState *state, struct Menu *menu)
Initialise a browser state.
Definition: browser.c:532
void init_menu(struct BrowserState *state, struct Menu *menu, struct Mailbox *m, struct MuttWindow *sbar)
Set up a new menu.
Definition: browser.c:874
static void init_lastdir(void)
Initialise the browser directories.
Definition: browser.c:144
static const struct Mapping FolderNewsHelp[]
Help Bar for the NNTP Mailbox browser dialog.
Definition: browser.c:122
struct Buffer LastDir
Definition: browser.c:136
void mutt_browser_select_dir(const char *f)
Remember the last directory selected.
Definition: browser.c:1068
struct Buffer LastDirBackup
Definition: browser.c:137
void mutt_buffer_select_file(struct Buffer *file, SelectFileFlags flags, struct Mailbox *m, char ***files, int *numfiles)
Let the user select a file.
Definition: browser.c:1088
static const struct Mapping FolderHelp[]
Help Bar for the File/Dir/Mailbox browser dialog.
Definition: browser.c:109
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.
Definition: browser.c:556
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: browser.c:479
void mutt_browser_cleanup(void)
Clean up working Buffers.
Definition: browser.c:158
void browser_highlight_default(struct BrowserState *state, struct Menu *menu)
Decide which browser item should be highlighted.
Definition: browser.c:848
int examine_mailboxes(struct Mailbox *m, struct Menu *menu, struct BrowserState *state)
Get list of mailboxes/subscribed newsgroups.
Definition: browser.c:684
bool link_is_dir(const char *folder, const char *path)
Does this symlink point to a directory?
Definition: browser.c:171
void mutt_buffer_alloc(struct Buffer *buf, size_t new_size)
Make sure a buffer can store at least new_size bytes.
Definition: buffer.c:275
bool mutt_buffer_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:260
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:327
void mutt_buffer_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
Definition: buffer.c:309
size_t mutt_buffer_addstr_n(struct Buffer *buf, const char *s, size_t len)
Add a string to a Buffer, expanding it if necessary.
Definition: buffer.c:105
size_t mutt_buffer_len(const struct Buffer *buf)
Calculate the length of a Buffer.
Definition: buffer.c:371
size_t mutt_buffer_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
Definition: buffer.c:248
void mutt_buffer_fix_dptr(struct Buffer *buf)
Move the dptr to end of the Buffer.
Definition: buffer.c:189
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:168
size_t mutt_buffer_copy(struct Buffer *dst, const struct Buffer *src)
Copy a Buffer's contents to another Buffer.
Definition: buffer.c:462
void mutt_buffer_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:85
size_t mutt_buffer_strcpy_n(struct Buffer *buf, const char *s, size_t len)
Copy a string into a Buffer.
Definition: buffer.c:342
size_t mutt_buffer_concat_path(struct Buffer *buf, const char *dir, const char *fname)
Join a directory name and a filename.
Definition: buffer.c:389
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:77
const struct Regex * cs_subset_regex(const struct ConfigSubset *sub, const char *name)
Get a regex config item by name.
Definition: helpers.c:243
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:317
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
short cs_subset_sort(const struct ConfigSubset *sub, const char *name)
Get a sort config item by name.
Definition: helpers.c:292
Convenience wrapper for the config headers.
Connection Library.
Convenience wrapper for the core headers.
void mutt_format_s(char *buf, size_t buflen, const char *prec, const char *s)
Format a simple string.
Definition: curs_lib.c:793
size_t mutt_date_localtime_format(char *buf, size_t buflen, const char *format, time_t t)
Format localtime.
Definition: date.c:692
time_t mutt_date_epoch(void)
Return the number of seconds since the Unix epoch.
Definition: date.c:428
@ FR_UNKNOWN
Unknown function.
Definition: dispatcher.h:33
Flags to control mutt_expando_format()
#define MUTT_FORMAT_NO_FLAGS
No flags are set.
Definition: format_flags.h:30
#define MUTT_FORMAT_OPTIONAL
Allow optional field processing.
Definition: format_flags.h:33
#define MUTT_FORMAT_ARROWCURSOR
Reserve space for arrow_cursor.
Definition: format_flags.h:35
uint8_t MuttFormatFlags
Flags for mutt_expando_format(), e.g. MUTT_FORMAT_FORCESUBJ.
Definition: format_flags.h:29
int menu_tagging_dispatcher(struct MuttWindow *win, int op)
Perform tagging operations on the Menu - Implements function_dispatcher_t -.
Definition: tagging.c:223
int global_function_dispatcher(struct MuttWindow *win, int op)
Perform a Global function - Implements function_dispatcher_t -.
Definition: global.c:164
int menu_function_dispatcher(struct MuttWindow *win, int op)
Perform a Menu function - Implements function_dispatcher_t -.
Definition: functions.c:320
void mutt_expando_format(char *buf, size_t buflen, size_t col, int cols, const char *src, format_t callback, intptr_t data, MuttFormatFlags flags)
Expand expandos (x) in a string -.
Definition: muttlib.c:777
const char * group_index_format_str(char *buf, size_t buflen, size_t col, int cols, char op, const char *src, const char *prec, const char *if_str, const char *else_str, intptr_t data, MuttFormatFlags flags)
Format a string for the newsgroup menu - Implements format_t -.
Definition: browse.c:55
static const char * folder_format_str(char *buf, size_t buflen, size_t col, int cols, char op, const char *src, const char *prec, const char *if_str, const char *else_str, intptr_t data, MuttFormatFlags flags)
Format a string for the folder browser - Implements format_t -.
Definition: browser.c:207
#define mutt_error(...)
Definition: logging.h:87
#define mutt_debug(LEVEL,...)
Definition: logging.h:84
#define mutt_perror(...)
Definition: logging.h:88
static void folder_make_entry(struct Menu *menu, char *buf, size_t buflen, int line)
Format a menu item for the folder browser - Implements Menu::make_entry() -.
Definition: browser.c:806
static int select_file_search(struct Menu *menu, regex_t *rx, int line)
Menu search callback for matching files - Implements Menu::search() -.
Definition: browser.c:790
static int file_tag(struct Menu *menu, int sel, int act)
Tag an entry in the menu - Implements Menu::tag() -.
Definition: browser.c:983
enum MailboxType imap_path_probe(const char *path, const struct stat *st)
Is this an IMAP Mailbox? - Implements MxOps::path_probe() -.
Definition: imap.c:2400
static int browser_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t -.
Definition: browser.c:1003
static int browser_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t -.
Definition: browser.c:1035
void browser_private_data_free(struct BrowserPrivateData **ptr)
Free Private Browser Data - Implements MuttWindow::wdata_free() -.
Definition: private_data.c:36
Convenience wrapper for the gui headers.
void simple_dialog_free(struct MuttWindow **ptr)
Destroy a simple index Dialog.
Definition: simple.c:166
struct MuttWindow * simple_dialog_new(enum MenuType mtype, enum WindowType wtype, const struct Mapping *help_data)
Create a simple index Dialog.
Definition: simple.c:129
int imap_browse(const char *path, struct BrowserState *state)
IMAP hook into the folder browser.
Definition: browse.c:182
IMAP network mailbox.
void imap_clean_path(char *path, size_t plen)
Cleans an IMAP path using imap_fix_path.
Definition: util.c:188
int km_dokey(enum MenuType mtype)
Determine what a keypress should do.
Definition: keymap.c:795
void km_error_key(enum MenuType mtype)
Handle an unbound key sequence.
Definition: keymap.c:1061
Manage keymappings.
@ LL_DEBUG5
Log at debug level 5.
Definition: logging.h:44
@ LL_DEBUG1
Log at debug level 1.
Definition: logging.h:40
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox's path string.
Definition: mailbox.h:210
@ MUTT_NOTMUCH
'Notmuch' (virtual) Mailbox type
Definition: mailbox.h:51
@ MUTT_MMDF
'mmdf' Mailbox type
Definition: mailbox.h:46
@ MUTT_POP
'POP3' Mailbox type
Definition: mailbox.h:52
@ MUTT_MH
'MH' Mailbox type
Definition: mailbox.h:47
@ MUTT_NNTP
'NNTP' (Usenet) Mailbox type
Definition: mailbox.h:49
@ MUTT_IMAP
'IMAP' Mailbox type
Definition: mailbox.h:50
@ MUTT_MBOX
'mbox' Mailbox type
Definition: mailbox.h:45
@ MUTT_MAILBOX_ANY
Match any Mailbox type.
Definition: mailbox.h:42
@ MUTT_MAILDIR
'Maildir' Mailbox type
Definition: mailbox.h:48
GUI present the user with a selectable list.
#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:178
int menu_get_index(struct Menu *menu)
Get the current selection in the Menu.
Definition: menu.c:154
MenuRedrawFlags menu_set_index(struct Menu *menu, int index)
Set the current selection in the Menu.
Definition: menu.c:168
Convenience wrapper for the library headers.
#define N_(a)
Definition: message.h:32
#define _(a)
Definition: message.h:28
bool notify_observer_remove(struct Notify *notify, const observer_t callback, const void *global_data)
Remove an observer from an object.
Definition: notify.c:228
bool notify_observer_add(struct Notify *notify, enum NotifyType type, observer_t callback, void *global_data)
Add an observer to an object.
Definition: notify.c:189
const char * mutt_path_getcwd(struct Buffer *cwd)
Get the current working directory.
Definition: path.c:561
bool mutt_regex_match(const struct Regex *regex, const char *str)
Shorthand to mutt_regex_capture()
Definition: regex.c:631
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:250
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:807
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
Definition: string.c:227
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:652
#define PATH_MAX
Definition: mutt.h:40
Hundreds of global variables to back the user variables.
char * CurrentFolder
Currently selected mailbox.
Definition: mutt_globals.h:54
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:74
NeoMutt Logging.
int mutt_mailbox_check(struct Mailbox *m_cur, CheckStatsFlags flags)
Check all all Mailboxes for new mail.
Definition: mutt_mailbox.c:156
Mailbox helper functions.
void window_redraw(struct MuttWindow *win)
Reflow, recalc and repaint a tree of Windows.
Definition: mutt_window.c:604
struct MuttWindow * window_find_child(struct MuttWindow *win, enum WindowType type)
Recursively find a child Window of a given type.
Definition: mutt_window.c:522
@ WT_DLG_BROWSER
Browser Dialog, mutt_buffer_select_file()
Definition: mutt_window.h:80
@ WT_STATUS_BAR
Status Bar containing extra info about the Index/Pager/etc.
Definition: mutt_window.h:102
@ WT_MENU
An Window containing a Menu.
Definition: mutt_window.h:98
@ NT_WINDOW_DELETE
Window is about to be deleted.
Definition: mutt_window.h:206
void mutt_get_parent_path(const char *path, char *buf, size_t buflen)
Find the parent of a path (or mailbox)
Definition: muttlib.c:1549
void mutt_buffer_pretty_mailbox(struct Buffer *buf)
Shorten a mailbox path using '~' or '='.
Definition: muttlib.c:599
void mutt_buffer_expand_path(struct Buffer *buf)
Create the canonical path.
Definition: muttlib.c:322
void mutt_str_pretty_size(char *buf, size_t buflen, size_t num)
Display an abbreviated size, like 3.4K.
Definition: muttlib.c:1673
Some miscellaneous functions.
enum MailboxType mx_path_probe(const char *path)
Find a mailbox that understands a path.
Definition: mx.c:1327
API for mailboxes.
#define MUTT_MAILBOX_CHECK_NO_FLAGS
No flags are set.
Definition: mxapi.h:74
void neomutt_mailboxlist_clear(struct MailboxList *ml)
Free a Mailbox List.
Definition: neomutt.c:141
size_t neomutt_mailboxlist_get_all(struct MailboxList *head, struct NeoMutt *n, enum MailboxType type)
Get a List of all Mailboxes.
Definition: neomutt.c:164
Nntp-specific Account data.
Usenet network mailbox type; talk to an NNTP server.
struct NntpAccountData * CurrentNewsSrv
Current NNTP news server.
Definition: nntp.c:77
Nntp-specific Mailbox data.
@ NT_WINDOW
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:55
@ NT_CONFIG
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:43
const char * opcodes_get_name(int op)
Get the name of an opcode.
Definition: opcodes.c:46
All user-callable functions.
Handling of global boolean variables.
bool OptNews
(pseudo) used to change reader mode
Definition: options.h:50
Private state data for the Pager.
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:112
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:101
#define STAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:324
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
#define TAILQ_EMPTY(head)
Definition: queue.h:721
void sbar_set_title(struct MuttWindow *win, const char *title)
Set the title for the Simple Bar.
Definition: sbar.c:224
Sidebar functions.
#define SORT_MASK
Mask for the sort id.
Definition: sort2.h:78
@ SORT_SUBJECT
Sort by the email's subject.
Definition: sort2.h:46
@ SORT_ORDER
Sort by the order the messages appear in the mailbox.
Definition: sort2.h:48
@ SORT_DESC
Sort by the folder's description.
Definition: sort2.h:63
Key value store.
#define NONULL(x)
Definition: string2.h:37
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
Private state data for the Browser.
Definition: private_data.h:34
char *** files
Array of selected files.
Definition: private_data.h:38
struct Menu * menu
Menu.
Definition: private_data.h:43
struct Buffer * prefix
Folder prefix string.
Definition: private_data.h:49
bool kill_prefix
Prefix is in use.
Definition: private_data.h:44
bool done
Should we close the Dialog?
Definition: private_data.h:53
bool folder
Select folders.
Definition: private_data.h:46
int last_selected_mailbox
Index of last selected Mailbox.
Definition: private_data.h:50
int * numfiles
Number of selected files.
Definition: private_data.h:39
struct Mailbox * mailbox
Mailbox.
Definition: private_data.h:37
struct BrowserState state
State containing list of files/dir/mailboxes.
Definition: private_data.h:42
struct Buffer * file
Buffer for the result.
Definition: private_data.h:36
bool multiple
Allow mulitple selections.
Definition: private_data.h:45
struct MuttWindow * win_browser
Browser Window.
Definition: private_data.h:52
struct MuttWindow * sbar
Status Bar.
Definition: private_data.h:51
State of the file/mailbox browser.
Definition: lib.h:111
char * folder
Folder name.
Definition: lib.h:115
bool is_mailbox_list
Viewing mailboxes.
Definition: lib.h:117
struct BrowserStateEntry entry
Array of files / dirs / mailboxes.
Definition: lib.h:112
bool imap_browse
IMAP folder.
Definition: lib.h:114
String manipulation buffer.
Definition: buffer.h:34
char * data
Pointer to data.
Definition: buffer.h:35
char host[128]
Server to login to.
Definition: connaccount.h:54
struct ConnAccount account
Account details: username, password, etc.
Definition: connection.h:50
A config-change event.
Definition: subset.h:70
const char * name
Name of config item that changed.
Definition: subset.h:72
An Event that happened to a Window.
Definition: mutt_window.h:216
struct MuttWindow * win
Window that changed.
Definition: mutt_window.h:217
Browser entry representing a folder/dir.
Definition: lib.h:73
bool selectable
Folder can be selected.
Definition: lib.h:92
bool imap
This is an IMAP folder.
Definition: lib.h:91
bool has_mailbox
This is a mailbox.
Definition: lib.h:95
char * name
Name of file/dir/mailbox.
Definition: lib.h:81
uid_t uid
File's User ID.
Definition: lib.h:77
bool tagged
Folder is tagged.
Definition: lib.h:97
gid_t gid
File's Group ID.
Definition: lib.h:78
bool has_new_mail
true if mailbox has "new mail"
Definition: lib.h:84
nlink_t nlink
Number of hard links.
Definition: lib.h:79
char * desc
Description of mailbox.
Definition: lib.h:82
struct NntpMboxData * nd
Extra NNTP data.
Definition: lib.h:99
off_t size
File size.
Definition: lib.h:75
int gen
Unique id, used for (un)sorting.
Definition: lib.h:102
time_t mtime
Modification time.
Definition: lib.h:76
int msg_count
total number of messages
Definition: lib.h:85
mode_t mode
File permissions.
Definition: lib.h:74
bool inferiors
Folder has children.
Definition: lib.h:93
int msg_unread
number of unread messages
Definition: lib.h:86
A folder/dir in the browser.
Definition: lib.h:64
int num
Number in the index.
Definition: lib.h:66
struct FolderFile * ff
File / Dir / Mailbox.
Definition: lib.h:65
List of Mailboxes.
Definition: mailbox.h:153
struct Mailbox * mailbox
Mailbox in the list.
Definition: mailbox.h:154
A mailbox.
Definition: mailbox.h:79
bool has_new
Mailbox has new mail.
Definition: mailbox.h:85
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition: mailbox.h:81
int msg_count
Total number of messages.
Definition: mailbox.h:88
enum MailboxType type
Mailbox type.
Definition: mailbox.h:102
void * mdata
Driver specific data.
Definition: mailbox.h:132
char * name
A short name for the Mailbox.
Definition: mailbox.h:82
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:146
Mapping between user-readable string and a constant.
Definition: mapping.h:32
Definition: lib.h:69
struct MuttWindow * win
Window holding the Menu.
Definition: lib.h:76
void(* make_entry)(struct Menu *menu, char *buf, size_t buflen, int line)
Definition: lib.h:96
int num_tagged
Number of tagged entries.
Definition: lib.h:83
void(* mdata_free)(struct Menu *menu, void **ptr)
Definition: lib.h:152
int(* search)(struct Menu *menu, regex_t *rx, int line)
Definition: lib.h:109
int top
Entry that is the top of the current page.
Definition: lib.h:80
int(* tag)(struct Menu *menu, int sel, int act)
Definition: lib.h:121
void * mdata
Private data.
Definition: lib.h:137
int max
Number of entries in the menu.
Definition: lib.h:71
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:127
void * wdata
Private data.
Definition: mutt_window.h:145
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
Container for Accounts, Notifications.
Definition: neomutt.h:37
struct AccountList accounts
List of all Accounts.
Definition: neomutt.h:40
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
NNTP-specific Account data -.
Definition: adata.h:37
struct Connection * conn
Connection to NNTP Server.
Definition: adata.h:63
void ** groups_list
Definition: adata.h:61
NNTP-specific Mailbox data -.
Definition: mdata.h:33
char * group
Name of newsgroup.
Definition: mdata.h:34
struct NntpAccountData * adata
Definition: mdata.h:47
Data passed to a notification function.
Definition: observer.h:34
void * event_data
Data from notify_send()
Definition: observer.h:38
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition: observer.h:36
int event_subtype
Send: Event subtype, e.g. NT_ACCOUNT_ADD.
Definition: observer.h:37
void * global_data
Data from notify_observer_add()
Definition: observer.h:39
Cached regular expression.
Definition: regex3.h:89
char * pattern
printable version
Definition: regex3.h:90
short cols
Number of columns, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:60
@ MENU_FOLDER
General file/mailbox browser.
Definition: type.h:44