Nico Golde:
[apps/madmutt.git] / browser.c
index 9ae55ac..21bb588 100644 (file)
--- a/browser.c
+++ b/browser.c
  *     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
  */ 
 
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include "mutt.h"
 #include "mutt_curses.h"
 #include "mutt_menu.h"
@@ -30,6 +34,7 @@
 #ifdef USE_NNTP
 #include "nntp.h"
 #endif
+#include "sidebar.h"
 
 #include <stdlib.h>
 #include <dirent.h>
@@ -565,6 +570,7 @@ static int examine_directory (MUTTMENU *menu, struct browser_state *state,
   }
   closedir (dp);
   }
+  draw_sidebar (CurrentMenu);
   browser_sort (state);
   return 0;
 }
@@ -644,7 +650,7 @@ static int examine_mailboxes (MUTTMENU *menu, struct browser_state *state)
   return 0;
 }
 
-int select_file_search (MUTTMENU *menu, regex_t *re, int n)
+static int select_file_search (MUTTMENU *menu, regex_t *re, int n)
 {
 #ifdef USE_NNTP
   if (option (OPTNEWS))
@@ -653,7 +659,7 @@ int select_file_search (MUTTMENU *menu, regex_t *re, int n)
   return (regexec (re, ((struct folder_file *) menu->data)[n].name, 0, NULL, 0));
 }
 
-void folder_entry (char *s, size_t slen, MUTTMENU *menu, int num)
+static void folder_entry (char *s, size_t slen, MUTTMENU *menu, int num)
 {
   FOLDER folder;
 
@@ -690,7 +696,7 @@ static void init_menu (struct browser_state *state, MUTTMENU *menu, char *title,
   if (option (OPTNEWS))
   {
     if (buffy)
-      snprintf (title, titlelen, _("Subscribed newsgroups"));
+      snprintf (title, titlelen, "%s", _("Subscribed newsgroups"));
     else
       snprintf (title, titlelen, _("Newsgroups on server [%s]"),
                CurrentNewsSrv->conn->account.host);
@@ -715,7 +721,7 @@ static void init_menu (struct browser_state *state, MUTTMENU *menu, char *title,
   menu->redraw = REDRAW_FULL;
 }
 
-int file_tag (MUTTMENU *menu, int n, int m)
+static int file_tag (MUTTMENU *menu, int n, int m)
 {
   struct folder_file *ff = &(((struct folder_file *)menu->data)[n]);
   int ot;
@@ -803,8 +809,8 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, int *num
       else
       {
        getcwd (LastDir, sizeof (LastDir));
-       strcat (LastDir, "/");  /* __STRCAT_CHECKED__ */
-       strncat (LastDir, f, i);
+       safe_strcat (LastDir, sizeof (LastDir), "/");
+       safe_strncat (LastDir, sizeof (LastDir), f, i);
       }
     }
     else
@@ -1099,7 +1105,28 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, int *num
        }
        break;
 
-      case OP_DELETE_MAILBOX:
+      case OP_RENAME_MAILBOX:
+       if (!state.entry[menu->current].imap)
+         mutt_error (_("Rename is only supported for IMAP mailboxes"));
+       else
+       {
+         int nentry = menu->current;
+
+         if (imap_mailbox_rename (state.entry[nentry].name) >= 0) {
+           destroy_state (&state);
+           init_state (&state, NULL);
+           state.imap_browse = 1;
+           imap_browse (LastDir, &state);
+           menu->data = state.entry;
+           menu->current = 0;
+           menu->top = 0;
+           init_menu (&state, menu, title, sizeof (title), buffy);
+           MAYBE_REDRAW (menu->redraw);
+         }
+       }
+       break;
+
+    case OP_DELETE_MAILBOX:
        if (!state.entry[menu->current].imap)
          mutt_error (_("Delete is only supported for IMAP mailboxes"));
        else
@@ -1177,21 +1204,21 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, int *num
          {
            if (S_ISDIR (st.st_mode))
            {
-             strfcpy (LastDir, buf, sizeof (LastDir));
              destroy_state (&state);
-             if (examine_directory (menu, &state, LastDir, prefix) == 0)
-             {
-               menu->current = 0; 
-               menu->top = 0; 
-               init_menu (&state, menu, title, sizeof (title), buffy);
-             }
+             if (examine_directory (menu, &state, buf, prefix) == 0)
+               strfcpy (LastDir, buf, sizeof (LastDir));
              else
              {
                mutt_error _("Error scanning directory.");
-               destroy_state (&state);
-               mutt_menuDestroy (&menu);
-               goto bail;
+               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);