2 * Copyright notice from original mutt:
3 * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
5 * This file is part of mutt-ng, see http://www.muttng.org/.
6 * It's licensed under the GNU General Public License,
7 * please see the file GPL in the top level source directory.
10 #include <lib-lib/lib-lib.h>
16 #include <lib-ui/lib-ui.h>
17 #include <lib-ui/enter.h>
18 #include <lib-ui/menu.h>
19 #include <lib-ui/sidebar.h>
20 #include <lib-mx/mx.h>
28 #include <imap/imap.h>
30 typedef struct folder_t {
31 struct folder_file *ff;
35 static char LastDir[_POSIX_PATH_MAX] = "";
36 static char LastDirBackup[_POSIX_PATH_MAX] = "";
38 /* Frees up the memory allocated for the local-global variables. */
39 static void destroy_state (struct browser_state *state)
43 for (c = 0; c < state->entrylen; c++) {
44 p_delete(&state->entry[c].name);
45 p_delete(&state->entry[c].desc);
46 p_delete(&state->entry[c].st);
48 p_delete(&state->folder);
49 p_delete(&state->entry);
52 static int browser_compare_subject (const void *a, const void *b)
54 struct folder_file *pa = (struct folder_file *) a;
55 struct folder_file *pb = (struct folder_file *) b;
57 int r = strcoll(NONULL(pa->name), NONULL(pb->name));
59 return ((BrowserSort & SORT_REVERSE) ? -r : r);
62 static int browser_compare_date (const void *a, const void *b)
64 struct folder_file *pa = (struct folder_file *) a;
65 struct folder_file *pb = (struct folder_file *) b;
67 int r = pa->mtime - pb->mtime;
69 return ((BrowserSort & SORT_REVERSE) ? -r : r);
72 static int browser_compare_size (const void *a, const void *b)
74 struct folder_file *pa = (struct folder_file *) a;
75 struct folder_file *pb = (struct folder_file *) b;
77 int r = pa->size - pb->size;
79 return ((BrowserSort & SORT_REVERSE) ? -r : r);
82 static void browser_sort (struct browser_state *state)
84 int (*f) (const void *, const void *);
86 switch (BrowserSort & SORT_MASK) {
90 f = browser_compare_date;
93 f = browser_compare_size;
97 f = browser_compare_subject;
100 qsort (state->entry, state->entrylen, sizeof (struct folder_file), f);
103 static int link_is_dir (const char *folder, const char *path)
106 char fullpath[_POSIX_PATH_MAX];
108 mutt_concat_path(fullpath, sizeof(fullpath), folder, path);
110 if (stat (fullpath, &st) == 0)
111 return (S_ISDIR (st.st_mode));
117 folder_format_str(char *dest, ssize_t destlen, char op,
118 const char *src, const char *fmt,
119 const char *ifstr, const char *elstr,
120 anytype data, format_flag flags)
122 char fn[STRING], tmp[STRING], permission[11], date[16];
125 FOLDER *folder = data.ptr;
128 int optional = (flags & M_FORMAT_OPTIONAL);
132 snprintf (tmp, sizeof (tmp), "%%%sd", fmt);
133 snprintf (dest, destlen, tmp, folder->num + 1);
137 if (folder->ff->st != NULL) {
140 tnow - folder->ff->st->st_mtime <
141 31536000 ? "%b %d %H:%M" : "%b %d %Y";
142 strftime (date, sizeof (date), t_fmt,
143 localtime (&folder->ff->st->st_mtime));
144 mutt_format_s (dest, destlen, fmt, date);
147 mutt_format_s (dest, destlen, fmt, "");
154 if (folder->ff->imap)
155 s = NONULL(folder->ff->desc);
157 s = NONULL(folder->ff->name);
159 snprintf (fn, sizeof (fn), "%s%s", s,
160 folder->ff->st ? (S_ISLNK (folder->ff->st->st_mode) ? "@" :
161 (S_ISDIR (folder->ff->st->st_mode) ? "/" :
162 ((folder->ff->st->st_mode & S_IXUSR) !=
163 0 ? "*" : ""))) : "");
165 mutt_format_s (dest, destlen, fmt, fn);
169 if (folder->ff->st != NULL) {
170 snprintf (permission, sizeof (permission), "%c%c%c%c%c%c%c%c%c%c",
171 S_ISDIR(folder->ff->st-> st_mode)
172 ? 'd' : (S_ISLNK(folder->ff->st-> st_mode) ? 'l' : '-'),
173 (folder->ff->st->st_mode & S_IRUSR) != 0 ? 'r' : '-',
174 (folder->ff->st->st_mode & S_IWUSR) != 0 ? 'w' : '-',
175 (folder->ff->st->st_mode & S_ISUID) !=
176 0 ? 's' : (folder->ff->st->st_mode & S_IXUSR) !=
178 (folder->ff->st->st_mode & S_IRGRP) != 0 ? 'r' : '-',
179 (folder->ff->st->st_mode & S_IWGRP) != 0 ? 'w' : '-',
180 (folder->ff->st->st_mode & S_ISGID) !=
181 0 ? 's' : (folder->ff->st->st_mode & S_IXGRP) !=
183 (folder->ff->st->st_mode & S_IROTH) != 0 ? 'r' : '-',
184 (folder->ff->st->st_mode & S_IWOTH) != 0 ? 'w' : '-',
185 (folder->ff->st->st_mode & S_ISVTX) !=
186 0 ? 't' : (folder->ff->st->st_mode & S_IXOTH) !=
188 mutt_format_s (dest, destlen, fmt, permission);
190 else if (folder->ff->imap) {
191 /* mark folders with subfolders AND mail */
192 snprintf (permission, sizeof (permission), "IMAP %c",
193 (folder->ff->inferiors
194 && folder->ff->selectable) ? '+' : ' ');
195 mutt_format_s (dest, destlen, fmt, permission);
198 mutt_format_s (dest, destlen, fmt, "");
202 if (folder->ff->st != NULL) {
203 if ((gr = getgrgid (folder->ff->st->st_gid)))
204 mutt_format_s (dest, destlen, fmt, gr->gr_name);
206 snprintf (tmp, sizeof (tmp), "%%%sld", fmt);
207 snprintf (dest, destlen, tmp, folder->ff->st->st_gid);
211 mutt_format_s (dest, destlen, fmt, "");
215 if (folder->ff->st != NULL) {
216 snprintf (tmp, sizeof (tmp), "%%%sd", fmt);
217 snprintf (dest, destlen, tmp, folder->ff->st->st_nlink);
220 mutt_format_s (dest, destlen, fmt, "");
224 if (imap_is_magic (folder->ff->desc, NULL) == M_IMAP) {
226 snprintf (tmp, sizeof (tmp), "%%%sd", fmt);
227 snprintf (dest, destlen, tmp, folder->ff->new);
229 else if (!folder->ff->new)
233 snprintf (tmp, sizeof (tmp), "%%%sc", fmt);
234 snprintf (dest, destlen, tmp, folder->ff->new ? 'N' : ' ');
238 if (folder->ff->st != NULL) {
239 snprintf (tmp, sizeof (tmp), "%%%sld", fmt);
240 snprintf (dest, destlen, tmp, (long) folder->ff->st->st_size);
243 mutt_format_s (dest, destlen, fmt, "");
247 snprintf (tmp, sizeof (tmp), "%%%sc", fmt);
248 snprintf (dest, destlen, tmp, folder->ff->tagged ? '*' : ' ');
252 if (folder->ff->st != NULL) {
253 if ((pw = getpwuid (folder->ff->st->st_uid)))
254 mutt_format_s (dest, destlen, fmt, pw->pw_name);
256 snprintf (tmp, sizeof (tmp), "%%%sld", fmt);
257 snprintf (dest, destlen, tmp, folder->ff->st->st_uid);
261 mutt_format_s (dest, destlen, fmt, "");
265 snprintf (tmp, sizeof (tmp), "%%%sc", fmt);
266 snprintf (dest, destlen, tmp, op);
271 if (flags & M_FORMAT_OPTIONAL)
272 m_strformat(dest, destlen, 0, optional ? ifstr : elstr,
273 folder_format_str, data, 0);
279 static void add_folder (MUTTMENU * m, struct browser_state *state,
280 const char *name, const struct stat *s, int new)
282 if (state->entrylen == state->entrymax) {
283 /* need to allocate more space */
284 p_realloc(&state->entry, state->entrymax += 256);
285 p_clear(&state->entry[state->entrylen], 256);
287 m->data = state->entry;
291 (state->entry)[state->entrylen].mode = s->st_mode;
292 (state->entry)[state->entrylen].mtime = s->st_mtime;
293 (state->entry)[state->entrylen].size = s->st_size;
294 (state->entry)[state->entrylen].st = p_dup(s, 1);
297 (state->entry)[state->entrylen].new = new;
298 (state->entry)[state->entrylen].name = m_strdup(name);
299 (state->entry)[state->entrylen].desc = m_strdup(name);
300 (state->entry)[state->entrylen].imap = 0;
304 static void init_state (struct browser_state *state, MUTTMENU * menu)
307 state->entrymax = 256;
308 state->entry = p_new(struct folder_file, state->entrymax);
309 state->imap_browse = 0;
311 menu->data = state->entry;
314 /* get list of all files/newsgroups with mask */
315 static int examine_directory (MUTTMENU * menu, struct browser_state *state,
316 char *d, const char *prefix)
322 char buffer[_POSIX_PATH_MAX + STRING];
325 while (stat (d, &s) == -1) {
326 if (errno == ENOENT) {
327 /* The last used directory is deleted, try to use the parent dir. */
328 char *c = strrchr (d, '/');
339 if (!S_ISDIR (s.st_mode)) {
340 mutt_error (_("%s is not a directory."), d);
346 if ((dp = opendir (d)) == NULL) {
351 init_state (state, menu);
353 while ((de = readdir (dp)) != NULL) {
354 if (m_strcmp(de->d_name, ".") == 0)
355 continue; /* we don't need . */
357 if (m_strncmp(prefix, de->d_name, m_strlen(prefix)) != 0)
359 if (!((regexec (Mask.rx, de->d_name, 0, NULL, 0) == 0) ^ Mask.neg))
362 mutt_concat_path(buffer, sizeof(buffer), d, de->d_name);
363 if (lstat (buffer, &s) == -1)
366 if ((!S_ISREG (s.st_mode)) && (!S_ISDIR (s.st_mode)) &&
367 (!S_ISLNK (s.st_mode)))
370 i = buffy_lookup (buffer);
371 add_folder (menu, state, de->d_name, &s, i >= 0 ? Incoming.arr[i]->new : 0);
375 browser_sort (state);
379 /* get list of mailboxes/subscribed newsgroups */
380 static int examine_mailboxes (MUTTMENU * menu, struct browser_state *state)
383 char buffer[LONG_STRING];
391 init_state (state, menu);
393 for (i = 0; i < Incoming.len; i++) {
394 tmp = Incoming.arr[i];
395 tmp->magic = mx_get_magic (tmp->path);
396 if (tmp->magic == M_IMAP) {
397 add_folder (menu, state, tmp->path, NULL, tmp->new);
400 if (tmp->magic == M_POP) {
401 add_folder (menu, state, tmp->path, NULL, tmp->new);
404 if (lstat (tmp->path, &s) == -1)
407 if ((!S_ISREG (s.st_mode)) && (!S_ISDIR (s.st_mode)) &&
408 (!S_ISLNK (s.st_mode)))
411 m_strcpy(buffer, sizeof(buffer), NONULL(tmp->path));
412 mutt_pretty_mailbox (buffer);
413 add_folder (menu, state, buffer, &s, tmp->new);
416 browser_sort (state);
420 static int select_file_search (MUTTMENU * menu, regex_t * re, int n)
423 (re, ((struct folder_file *) menu->data)[n].name, 0, NULL, 0));
426 static void folder_entry (char *s, ssize_t slen, MUTTMENU * menu, int num)
430 folder.ff = &((struct folder_file *) menu->data)[num];
433 m_strformat(s, slen, getmaxx(main_w), FolderFormat, folder_format_str,
437 static void init_menu (struct browser_state *state, MUTTMENU * menu,
438 char *title, ssize_t titlelen, int buffy)
440 char path[_POSIX_PATH_MAX];
442 menu->max = state->entrylen;
444 if (menu->current >= menu->max)
445 menu->current = menu->max - 1;
446 if (menu->current < 0)
448 if (menu->top > menu->current)
454 snprintf(title, titlelen, _("Mailboxes [%d]"), buffy_check(0));
456 m_strcpy(path, sizeof(path), LastDir);
457 mutt_pretty_mailbox (path);
458 if (state->imap_browse && option (OPTIMAPLSUB))
459 snprintf (title, titlelen, _("Subscribed [%s], File mask: %s"),
460 path, NONULL (Mask.pattern));
462 snprintf (title, titlelen, _("Directory [%s], File mask: %s"),
463 path, NONULL (Mask.pattern));
465 menu->redraw = REDRAW_FULL;
468 static int file_tag (MUTTMENU * menu, int n, int m)
470 struct folder_file *ff = &(((struct folder_file *) menu->data)[n]);
473 if (S_ISDIR (ff->mode)
474 || (S_ISLNK (ff->mode) && link_is_dir (LastDir, ff->name))) {
475 mutt_error _("Can't attach a directory!");
481 ff->tagged = (m >= 0 ? m : !ff->tagged);
483 return ff->tagged - ot;
486 void mutt_select_file (char *f, ssize_t flen, int flags, char ***files,
489 char buf[_POSIX_PATH_MAX];
490 char prefix[_POSIX_PATH_MAX] = "";
492 struct browser_state state;
495 int i, killPrefix = 0;
496 int multiple = (flags & M_SEL_MULTI) ? 1 : 0;
497 int folder = (flags & M_SEL_FOLDER) ? 1 : 0;
498 int buffy = (flags & M_SEL_BUFFY) ? 1 : 0;
500 buffy = buffy && folder;
505 m_strcpy(LastDirBackup, sizeof(LastDirBackup), LastDir);
508 mutt_expand_path (f, flen);
509 if (imap_is_magic (f, NULL) == M_IMAP) {
510 init_state (&state, NULL);
511 state.imap_browse = 1;
512 if (!imap_browse (f, &state))
513 m_strcpy(LastDir, sizeof(LastDir), state.folder);
516 for (i = m_strlen(f) - 1; i > 0 && f[i] != '/'; i--);
519 i = MIN(ssizeof(LastDir) - 1, i);
520 m_strcpy(LastDir, sizeof(LastDir), f);
523 getcwd(LastDir, sizeof(LastDir));
524 m_strcat(LastDir, sizeof(LastDir), "/");
525 m_strncat(LastDir, sizeof(LastDir), f, i);
530 m_strcpy(LastDir, sizeof(LastDir), "/");
532 getcwd (LastDir, sizeof (LastDir));
535 if (i <= 0 && f[0] != '/')
536 m_strcpy(prefix, sizeof(prefix), f);
538 m_strcpy(prefix, sizeof(prefix), f + i + 1);
544 getcwd (LastDir, sizeof (LastDir));
545 else if (!LastDir[0])
546 m_strcpy(LastDir, sizeof(LastDir), NONULL(Maildir));
548 if (!buffy && imap_is_magic (LastDir, NULL) == M_IMAP) {
549 init_state (&state, NULL);
550 state.imap_browse = 1;
551 imap_browse (LastDir, &state);
552 browser_sort (&state);
559 if (examine_mailboxes (NULL, &state) == -1)
563 if (!state.imap_browse)
564 if (examine_directory (NULL, &state, LastDir, prefix) == -1)
567 menu = mutt_new_menu ();
568 menu->menu = MENU_FOLDER;
569 menu->make_entry = folder_entry;
570 menu->search = select_file_search;
572 menu->data = state.entry;
574 menu->tag = file_tag;
575 init_menu (&state, menu, title, sizeof (title), buffy);
578 switch (i = mutt_menuLoop (menu)) {
579 case OP_GENERIC_SELECT_ENTRY:
581 if (!state.entrylen) {
582 mutt_error _("No files match the file mask");
587 if (S_ISDIR (state.entry[menu->current].mode) ||
588 (S_ISLNK (state.entry[menu->current].mode) &&
589 link_is_dir (LastDir, state.entry[menu->current].name))
590 || state.entry[menu->current].inferiors
592 /* make sure this isn't a MH or maildir mailbox */
594 m_strcpy(buf, sizeof(buf), state.entry[menu->current].name);
595 mutt_expand_path (buf, sizeof (buf));
597 else if (state.imap_browse) {
598 m_strcpy(buf, sizeof(buf), state.entry[menu->current].name);
601 mutt_concat_path(buf, sizeof(buf), LastDir,
602 state.entry[menu->current].name);
604 if ((mx_get_magic (buf) <= 0)
605 || state.entry[menu->current].inferiors)
607 char OldLastDir[_POSIX_PATH_MAX];
609 /* save the old directory */
610 m_strcpy(OldLastDir, sizeof(OldLastDir), LastDir);
612 if (m_strcmp(state.entry[menu->current].name, "..") == 0) {
613 if (m_strcmp("..", LastDir + m_strlen(LastDir) - 2) == 0)
614 m_strcat(LastDir, sizeof(LastDir), "/..");
616 char *p = strrchr (LastDir + 1, '/');
621 if (LastDir[0] == '/')
624 m_strcat(LastDir, sizeof(LastDir), "/..");
629 m_strcpy(LastDir, sizeof(LastDir),
630 state.entry[menu->current].name);
631 mutt_expand_path (LastDir, sizeof (LastDir));
633 else if (state.imap_browse) {
637 m_strcpy(LastDir, sizeof(LastDir),
638 state.entry[menu->current].name);
639 /* tack on delimiter here */
640 n = m_strlen(LastDir) + 1;
642 /* special case "" needs no delimiter */
643 url_parse_ciss (&url, state.entry[menu->current].name);
645 (state.entry[menu->current].delim != '\0') &&
646 (n < ssizeof (LastDir))) {
648 LastDir[n - 1] = state.entry[menu->current].delim;
652 char tmp[_POSIX_PATH_MAX];
654 mutt_concat_path(tmp, sizeof(tmp), LastDir,
655 state.entry[menu->current].name);
656 m_strcpy(LastDir, sizeof(LastDir), tmp);
659 destroy_state (&state);
665 if (state.imap_browse) {
666 init_state (&state, NULL);
667 state.imap_browse = 1;
668 imap_browse (LastDir, &state);
669 browser_sort (&state);
670 menu->data = state.entry;
673 if (examine_directory (menu, &state, LastDir, prefix) == -1) {
674 /* try to restore the old values */
675 m_strcpy(LastDir, sizeof(LastDir), OldLastDir);
676 if (examine_directory (menu, &state, LastDir, prefix) == -1) {
677 m_strcpy(LastDir, sizeof(LastDir), NONULL(mod_core.homedir));
683 init_menu (&state, menu, title, sizeof (title), buffy);
689 m_strcpy(f, flen, state.entry[menu->current].name);
690 mutt_expand_path (f, flen);
692 else if (state.imap_browse)
693 m_strcpy(f, flen, state.entry[menu->current].name);
695 mutt_concat_path(f, flen, LastDir, state.entry[menu->current].name);
697 /* Fall through to OP_EXIT */
707 *numfiles = menu->tagged;
708 tfiles = p_new(char *, *numfiles);
709 for (h = 0, j = 0; h < state.entrylen; i++) {
710 struct folder_file ff = state.entry[i];
711 char full[_POSIX_PATH_MAX];
714 mutt_concat_path(full, sizeof(full), LastDir, ff.name);
715 mutt_expand_path (full, sizeof (full));
716 tfiles[j++] = m_strdup(full);
721 else if (f[0]) { /* no tagged entries. return selected entry */
723 tfiles = p_new(char *, *numfiles);
724 mutt_expand_path (f, flen);
725 tfiles[0] = m_strdup(f);
730 destroy_state (&state);
731 mutt_menuDestroy (&menu);
734 case OP_BROWSER_TELL:
736 mutt_message ("%s", state.entry[menu->current].name);
739 case OP_BROWSER_TOGGLE_LSUB:
740 if (option (OPTIMAPLSUB)) {
741 unset_option (OPTIMAPLSUB);
744 set_option (OPTIMAPLSUB);
746 mutt_ungetch (0, OP_CHECK_NEW);
749 case OP_CREATE_MAILBOX:
750 if (!state.imap_browse)
751 mutt_error (_("Create is only supported for IMAP mailboxes"));
753 imap_mailbox_create (LastDir);
754 /* TODO: find a way to detect if the new folder would appear in
755 * this window, and insert it without starting over. */
756 destroy_state (&state);
757 init_state (&state, NULL);
758 state.imap_browse = 1;
759 imap_browse (LastDir, &state);
760 browser_sort (&state);
761 menu->data = state.entry;
764 init_menu (&state, menu, title, sizeof (title), buffy);
765 MAYBE_REDRAW (menu->redraw);
769 case OP_RENAME_MAILBOX:
770 if (!state.entry[menu->current].imap)
771 mutt_error (_("Rename is only supported for IMAP mailboxes"));
773 int nentry = menu->current;
775 if (imap_mailbox_rename (state.entry[nentry].name) >= 0) {
776 destroy_state (&state);
777 init_state (&state, NULL);
778 state.imap_browse = 1;
779 imap_browse (LastDir, &state);
780 browser_sort (&state);
781 menu->data = state.entry;
784 init_menu (&state, menu, title, sizeof (title), buffy);
785 MAYBE_REDRAW (menu->redraw);
790 case OP_DELETE_MAILBOX:
791 if (!state.entry[menu->current].imap)
792 mutt_error (_("Delete is only supported for IMAP mailboxes"));
796 int nentry = menu->current;
798 imap_parse_path (state.entry[nentry].name, &mx);
799 snprintf (msg, sizeof (msg), _("Really delete mailbox \"%s\"?"),
801 if (mutt_yesorno (msg, M_NO) == M_YES) {
802 if (!imap_delete_mailbox (Context, mx)) {
803 /* free the mailbox from the browser */
804 p_delete(&((state.entry)[nentry].name));
805 p_delete(&((state.entry)[nentry].desc));
806 /* and move all other entries up */
807 if (nentry + 1 < state.entrylen)
808 memmove (state.entry + nentry, state.entry + nentry + 1,
809 sizeof (struct folder_file) * (state.entrylen -
812 mutt_message _("Mailbox deleted.");
814 init_menu (&state, menu, title, sizeof (title), buffy);
815 MAYBE_REDRAW (menu->redraw);
819 mutt_message _("Mailbox not deleted.");
824 case OP_CHANGE_DIRECTORY:
825 m_strcpy(buf, sizeof(buf), LastDir);
826 if (!state.imap_browse)
828 /* add '/' at the end of the directory name if not already there */
829 ssize_t len = m_strlen(LastDir);
831 if (len && LastDir[len - 1] != '/' && ssizeof(buf) > len)
835 if (mutt_get_field (_("Chdir to: "), buf, sizeof (buf), M_FILE) == 0 &&
838 mutt_expand_path (buf, sizeof (buf));
839 if (imap_is_magic (buf, NULL) == M_IMAP) {
840 m_strcpy(LastDir, sizeof(LastDir), buf);
841 destroy_state (&state);
842 init_state (&state, NULL);
843 state.imap_browse = 1;
844 imap_browse (LastDir, &state);
845 browser_sort (&state);
846 menu->data = state.entry;
849 init_menu (&state, menu, title, sizeof (title), buffy);
852 if (stat (buf, &st) == 0) {
853 if (S_ISDIR (st.st_mode)) {
854 destroy_state (&state);
855 if (examine_directory (menu, &state, buf, prefix) == 0)
856 m_strcpy(LastDir, sizeof(LastDir), buf);
858 mutt_error _("Error scanning directory.");
860 if (examine_directory (menu, &state, LastDir, prefix) == -1) {
861 mutt_menuDestroy (&menu);
867 init_menu (&state, menu, title, sizeof (title), buffy);
870 mutt_error (_("%s is not a directory."), buf);
875 MAYBE_REDRAW (menu->redraw);
880 m_strcpy(buf, sizeof(buf), NONULL(Mask.pattern));
881 if (mutt_get_field (_("File Mask: "), buf, sizeof (buf), 0) == 0) {
882 regex_t *rx = p_new(regex_t, 1);
887 /* assume that the user wants to see everything */
889 m_strcpy(buf, sizeof(buf), ".");
892 s = vskipspaces(s + 1);
896 if ((err = REGCOMP (rx, s, REG_NOSUB)) != 0) {
897 regerror (err, rx, buf, sizeof (buf));
900 mutt_error ("%s", buf);
903 m_strreplace(&Mask.pattern, buf);
909 destroy_state (&state);
910 if (state.imap_browse) {
911 init_state (&state, NULL);
912 state.imap_browse = 1;
913 imap_browse (LastDir, &state);
914 browser_sort (&state);
915 menu->data = state.entry;
916 init_menu (&state, menu, title, sizeof (title), buffy);
919 if (examine_directory (menu, &state, LastDir, NULL) == 0)
920 init_menu (&state, menu, title, sizeof (title), buffy);
922 mutt_error _("Error scanning directory.");
924 mutt_menuDestroy (&menu);
928 if (!state.entrylen) {
929 mutt_error _("No files match the file mask");
935 MAYBE_REDRAW (menu->redraw);
939 case OP_SORT_REVERSE:
943 int reverse = (i == OP_SORT_REVERSE);
945 switch (mutt_multi_choice ((reverse) ?
947 ("Reverse sort by (d)ate, (a)lpha, si(z)e or do(n)'t sort? ")
950 ("Sort by (d)ate, (a)lpha, si(z)e or do(n)'t sort? "),
957 BrowserSort = SORT_DATE;
960 case 2: /* (a)lpha */
961 BrowserSort = SORT_SUBJECT;
965 BrowserSort = SORT_SIZE;
968 case 4: /* do(n)'t sort */
969 BrowserSort = SORT_ORDER;
974 BrowserSort |= reverse ? SORT_REVERSE : 0;
975 browser_sort (&state);
976 menu->redraw = REDRAW_FULL;
981 case OP_TOGGLE_MAILBOXES:
985 destroy_state (&state);
990 if (examine_mailboxes (menu, &state) == -1)
993 else if (imap_is_magic (LastDir, NULL) == M_IMAP) {
994 init_state (&state, NULL);
995 state.imap_browse = 1;
996 imap_browse (LastDir, &state);
997 browser_sort (&state);
998 menu->data = state.entry;
1000 else if (examine_directory (menu, &state, LastDir, prefix) == -1)
1002 init_menu (&state, menu, title, sizeof (title), buffy);
1006 if (option (OPTFORCEBUFFYCHECK))
1011 case OP_BROWSER_NEW_FILE:
1013 snprintf (buf, sizeof (buf), "%s/", LastDir);
1014 if (mutt_get_field (_("New file name: "), buf, sizeof (buf), M_FILE) ==
1016 m_strcpy(f, flen, buf);
1017 destroy_state (&state);
1018 mutt_menuDestroy (&menu);
1021 MAYBE_REDRAW (menu->redraw);
1024 case OP_BROWSER_VIEW_FILE:
1025 if (!state.entrylen) {
1026 mutt_error _("No files match the file mask");
1031 if (state.entry[menu->current].selectable) {
1032 m_strcpy(f, flen, state.entry[menu->current].name);
1033 destroy_state (&state);
1034 mutt_menuDestroy (&menu);
1038 if (S_ISDIR (state.entry[menu->current].mode) ||
1039 (S_ISLNK (state.entry[menu->current].mode) &&
1040 link_is_dir (LastDir, state.entry[menu->current].name))) {
1041 mutt_error _("Can't view a directory");
1047 char nbuf[_POSIX_PATH_MAX];
1049 mutt_concat_path(nbuf, sizeof(nbuf), LastDir,
1050 state.entry[menu->current].name);
1051 b = mutt_make_file_attach (nbuf);
1053 mutt_view_attachment (NULL, b, M_REGULAR, NULL, NULL, 0);
1055 menu->redraw = REDRAW_FULL;
1058 mutt_error _("Error trying to view file");
1062 case OP_BROWSER_SUBSCRIBE:
1063 case OP_BROWSER_UNSUBSCRIBE:
1064 if (i == OP_BROWSER_SUBSCRIBE)
1065 imap_subscribe (state.entry[menu->current].name, 1);
1067 imap_subscribe (state.entry[menu->current].name, 0);
1074 m_strcpy(LastDir, sizeof(LastDir), LastDirBackup);