+
+ m_strcpy(buf, sizeof(buf), LastDir);
+ if (!state.imap_browse)
+ {
+ /* add '/' at the end of the directory name if not already there */
+ ssize_t len = m_strlen(LastDir);
+
+ if (len && LastDir[len - 1] != '/' && ssizeof(buf) > len)
+ buf[len] = '/';
+ }
+
+ if (mutt_get_field (_("Chdir to: "), buf, sizeof (buf), M_FILE) == 0 &&
+ buf[0]) {
+ buffy = 0;
+ mutt_expand_path (buf, sizeof (buf));
+ if (imap_is_magic (buf, NULL) == M_IMAP) {
+ m_strcpy(LastDir, sizeof(LastDir), buf);
+ destroy_state (&state);
+ init_state (&state, NULL);
+ state.imap_browse = 1;
+ imap_browse (LastDir, &state);
+ browser_sort (&state);
+ menu->data = state.entry;
+ menu->current = 0;
+ menu->top = 0;
+ init_menu (&state, menu, title, sizeof (title), buffy);
+ }
+ else
+ if (stat (buf, &st) == 0) {
+ if (S_ISDIR (st.st_mode)) {
+ destroy_state (&state);
+ if (examine_directory (menu, &state, buf, prefix) == 0)
+ m_strcpy(LastDir, sizeof(LastDir), buf);
+ else {
+ mutt_error _("Error scanning directory.");
+
+ if (examine_directory (menu, &state, LastDir, prefix) == -1) {
+ mutt_menuDestroy (&menu);
+ goto bail;
+ }
+ }
+ menu->current = 0;
+ menu->top = 0;
+ init_menu (&state, menu, title, sizeof (title), buffy);
+ }
+ else
+ mutt_error (_("%s is not a directory."), buf);
+ }
+ else
+ mutt_perror (buf);
+ }
+ MAYBE_REDRAW (menu->redraw);
+ break;
+
+ case OP_ENTER_MASK:
+
+ m_strcpy(buf, sizeof(buf), NONULL(Mask.pattern));
+ if (mutt_get_field (_("File Mask: "), buf, sizeof (buf), 0) == 0) {
+ regex_t *rx = p_new(regex_t, 1);
+ char *s = buf;
+ int not = 0, err;
+
+ buffy = 0;
+ /* assume that the user wants to see everything */
+ if (!buf[0])
+ m_strcpy(buf, sizeof(buf), ".");
+ s = vskipspaces(s);
+ if (*s == '!') {
+ s = vskipspaces(s + 1);
+ not = 1;
+ }
+
+ if ((err = REGCOMP (rx, s, REG_NOSUB)) != 0) {
+ regerror (err, rx, buf, sizeof (buf));
+ regfree (rx);
+ p_delete(&rx);
+ mutt_error ("%s", buf);
+ }
+ else {
+ m_strreplace(&Mask.pattern, buf);
+ regfree (Mask.rx);
+ p_delete(&Mask.rx);
+ Mask.rx = rx;
+ Mask.not = not;
+
+ destroy_state (&state);
+ if (state.imap_browse) {
+ init_state (&state, NULL);
+ state.imap_browse = 1;
+ imap_browse (LastDir, &state);
+ browser_sort (&state);
+ menu->data = state.entry;
+ init_menu (&state, menu, title, sizeof (title), buffy);
+ }
+ else
+ if (examine_directory (menu, &state, LastDir, NULL) == 0)
+ init_menu (&state, menu, title, sizeof (title), buffy);
+ else {
+ mutt_error _("Error scanning directory.");
+
+ mutt_menuDestroy (&menu);
+ goto bail;
+ }
+ killPrefix = 0;
+ if (!state.entrylen) {
+ mutt_error _("No files match the file mask");
+
+ break;
+ }
+ }
+ }
+ MAYBE_REDRAW (menu->redraw);
+ break;
+
+ case OP_SORT:
+ case OP_SORT_REVERSE:
+
+ {
+ int resort = 1;
+ int reverse = (i == OP_SORT_REVERSE);
+
+ switch (mutt_multi_choice ((reverse) ?
+ _
+ ("Reverse sort by (d)ate, (a)lpha, si(z)e or do(n)'t sort? ")
+ :
+ _
+ ("Sort by (d)ate, (a)lpha, si(z)e or do(n)'t sort? "),
+ _("dazn"))) {
+ case -1: /* abort */
+ resort = 0;
+ break;
+
+ case 1: /* (d)ate */
+ BrowserSort = SORT_DATE;
+ break;
+
+ case 2: /* (a)lpha */
+ BrowserSort = SORT_SUBJECT;
+ break;
+
+ case 3: /* si(z)e */
+ BrowserSort = SORT_SIZE;
+ break;
+
+ case 4: /* do(n)'t sort */
+ BrowserSort = SORT_ORDER;
+ resort = 0;
+ break;
+ }
+ if (resort) {
+ BrowserSort |= reverse ? SORT_REVERSE : 0;
+ browser_sort (&state);
+ menu->redraw = REDRAW_FULL;
+ }
+ break;
+ }
+
+ case OP_TOGGLE_MAILBOXES:
+ buffy = 1 - buffy;
+
+ case OP_CHECK_NEW:
+ destroy_state (&state);
+ prefix[0] = 0;
+ killPrefix = 0;
+
+ if (buffy) {
+ if (examine_mailboxes (menu, &state) == -1)
+ goto bail;
+ }
+ else if (imap_is_magic (LastDir, NULL) == M_IMAP) {
+ init_state (&state, NULL);
+ state.imap_browse = 1;
+ imap_browse (LastDir, &state);
+ browser_sort (&state);
+ menu->data = state.entry;
+ }
+ else if (examine_directory (menu, &state, LastDir, prefix) == -1)
+ goto bail;
+ init_menu (&state, menu, title, sizeof (title), buffy);
+ break;
+
+ case OP_BUFFY_LIST:
+ if (option (OPTFORCEBUFFYCHECK))
+ buffy_check (1);
+ buffy_list ();
+ break;
+
+ case OP_BROWSER_NEW_FILE:
+
+ snprintf (buf, sizeof (buf), "%s/", LastDir);
+ if (mutt_get_field (_("New file name: "), buf, sizeof (buf), M_FILE) ==
+ 0) {
+ m_strcpy(f, flen, buf);
+ destroy_state (&state);
+ mutt_menuDestroy (&menu);
+ goto bail;
+ }
+ MAYBE_REDRAW (menu->redraw);
+ break;
+
+ case OP_BROWSER_VIEW_FILE:
+ if (!state.entrylen) {
+ mutt_error _("No files match the file mask");
+
+ break;
+ }
+
+ if (state.entry[menu->current].selectable) {
+ m_strcpy(f, flen, state.entry[menu->current].name);
+ destroy_state (&state);
+ mutt_menuDestroy (&menu);
+ goto bail;
+ }
+ else
+ if (S_ISDIR (state.entry[menu->current].mode) ||
+ (S_ISLNK (state.entry[menu->current].mode) &&
+ link_is_dir (LastDir, state.entry[menu->current].name))) {
+ mutt_error _("Can't view a directory");
+
+ break;
+ }
+ else {
+ BODY *b;
+ char nbuf[_POSIX_PATH_MAX];
+
+ mutt_concat_path(nbuf, sizeof(nbuf), LastDir,
+ state.entry[menu->current].name);
+ b = mutt_make_file_attach (nbuf);
+ if (b != NULL) {
+ mutt_view_attachment (NULL, b, M_REGULAR, NULL, NULL, 0);
+ body_list_wipe(&b);
+ menu->redraw = REDRAW_FULL;
+ }
+ else
+ mutt_error _("Error trying to view file");
+ }
+ break;