]> granicus.if.org Git - mutt/commitdiff
New function: rename-mailbox (bound to 'r' by default).
authorBrendan Cully <brendan@kublai.com>
Thu, 17 Feb 2005 03:33:00 +0000 (03:33 +0000)
committerBrendan Cully <brendan@kublai.com>
Thu, 17 Feb 2005 03:33:00 +0000 (03:33 +0000)
The lack of a rename-mailbox command for IMAP finally got too annoying.
It's a bit of a cut-and-paste job, but I've put my dreams of cleaning
up the IMAP codebase on hold. Gotta grow up some time.

OPS
browser.c
doc/manual.sgml.head
functions.h
imap/browse.c
imap/imap.c
imap/imap.h
imap/imap_private.h

diff --git a/OPS b/OPS
index f090fb2c715f568b75887df139a66fb826563eeb..0844487f8bf21b99d85c642fd73e545281a6b5b5 100644 (file)
--- a/OPS
+++ b/OPS
@@ -144,6 +144,7 @@ OP_QUIT "save changes to mailbox and quit"
 OP_RECALL_MESSAGE "recall a postponed message"
 OP_REDRAW "clear and redraw the screen"
 OP_REFORMAT_WINCH "{internal}"
+OP_RENAME_MAILBOX "rename the current mailbox (IMAP only)"
 OP_REPLY "reply to a message"
 OP_RESEND "use the current message as a template for a new one"
 OP_SAVE "save message/attachment to a file"
index d38f76893370387b1b324c53bccd40ed2e543c3d..108efd4ea18750640b933a43a3fc741c21696616 100644 (file)
--- a/browser.c
+++ b/browser.c
@@ -875,7 +875,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
index a974537ec61e49a73945ecfd4502a368fd30f62c..c8e65f9977549b748ad31675544ccfeb7623a67b 100644 (file)
@@ -2461,8 +2461,10 @@ following differences:
   will choose to descend into the subfolder view. If you wish to view
   the messages in that folder, you must use <tt>view-file</tt> instead
   (bound to <tt>space</tt> by default).
-<item>You can delete mailboxes with the <tt>delete-mailbox</tt>
-  command (bound to <tt>d</tt> by default. You may also
+<item>You can create, delete and rename mailboxes with the
+  <tt>create-mailbox</tt>, <tt>delete-mailbox</tt>, and
+  <tt>rename-mailbox</tt> commands (default bindings: <tt>C</tt>,
+  <tt>d</tt> and <tt>r</tt>, respectively). You may also
   <tt>subscribe</tt> and <tt>unsubscribe</tt> to mailboxes (normally
   these are bound to <tt>s</tt> and <tt>u</tt>, respectively).
 </itemize>
index d1a7ca1051cf15967796b7c44b056d5aa728fcc9..47181cc765a9abc9dc63347625a5e074b3dc2b7f 100644 (file)
@@ -350,6 +350,7 @@ struct binding_t OpBrowser[] = {
 #ifdef USE_IMAP
   { "create-mailbox",   OP_CREATE_MAILBOX,      "C" },
   { "delete-mailbox",   OP_DELETE_MAILBOX,      "d" },
+  { "rename-mailbox",   OP_RENAME_MAILBOX,      "r" },
   { "subscribe",       OP_BROWSER_SUBSCRIBE,   "s" },
   { "unsubscribe",     OP_BROWSER_UNSUBSCRIBE, "u" },
   { "toggle-subscribed", OP_BROWSER_TOGGLE_LSUB, "T" },
index 760870e68a433641267224b7d00885adc53c7825..f2b01f4dabfeceb07a9865ed4752c5f7f427d923 100644 (file)
@@ -302,6 +302,55 @@ int imap_mailbox_create (const char* folder)
   return -1;
 }
 
+int imap_mailbox_rename(const char* mailbox)
+{
+  IMAP_DATA* idata;
+  IMAP_MBOX mx;
+  char buf[LONG_STRING];
+  char newname[SHORT_STRING];
+
+  if (imap_parse_path (mailbox, &mx) < 0)
+  {
+    dprint (1, (debugfile, "imap_mailbox_rename: Bad source mailbox %s\n",
+      mailbox));
+    return -1;
+  }
+
+  if (!(idata = imap_conn_find (&mx.account, M_IMAP_CONN_NONEW)))
+  {
+    dprint (1, (debugfile, "imap_mailbox_rename: Couldn't find open connection to %s", mx.account.host));
+    goto fail;
+  }
+
+  snprintf(buf, sizeof (buf), _("Rename mailbox %s to: "), mx.mbox);
+  
+ if (mutt_get_field (buf, newname, sizeof (newname), M_FILE) < 0)
+    goto fail;
+
+  if (!mutt_strlen (newname))
+  {
+    mutt_error (_("Mailbox must have a name."));
+    mutt_sleep (1);
+    goto fail;
+  }
+
+  if (imap_rename_mailbox (idata, &mx, newname) < 0) {
+    mutt_error (_("Rename failed: %s"), imap_get_qualifier (idata->cmd.buf));
+    mutt_sleep (1);
+    goto fail;
+  }
+
+  mutt_message (_("Mailbox renamed."));
+  mutt_sleep (0);
+
+  FREE (&mx.mbox);
+  return 0;
+
+ fail:
+  FREE (&mx.mbox);
+  return -1;
+}
+
 static int browse_add_list_result (IMAP_DATA* idata, const char* cmd,
   struct browser_state* state, short isparent)
 {
index 675edab28894a61092c036fe76acdeda9be975eb..fde8b9a6cc0251d1e079f5210fc71127189d081c 100644 (file)
@@ -108,20 +108,37 @@ int imap_create_mailbox (IMAP_DATA* idata, char* mailbox)
   return 0;
 }
 
+int imap_rename_mailbox (IMAP_DATA* idata, IMAP_MBOX* mx, const char* newname)
+{
+  char oldmbox[LONG_STRING];
+  char newmbox[LONG_STRING];
+  char buf[LONG_STRING];
+
+  imap_munge_mbox_name (oldmbox, sizeof (oldmbox), mx->mbox);
+  imap_munge_mbox_name (newmbox, sizeof (newmbox), newname);
+
+  snprintf (buf, sizeof (buf), "RENAME %s %s", oldmbox, newmbox);
+
+  if (imap_exec (idata, buf, 0) != 0)
+    return -1;
+
+  return 0;
+}
+
 int imap_delete_mailbox (CONTEXT* ctx, IMAP_MBOX mx)
 {
   char buf[LONG_STRING], mbox[LONG_STRING];
   IMAP_DATA *idata;
 
   if (!ctx || !ctx->data) {
-       if (!(idata = imap_conn_find (&mx.account,
-               option (OPTIMAPPASSIVE) ? M_IMAP_CONN_NONEW : 0)))
-       {
-               FREE (&mx.mbox);
-               return -1;
-       }
+    if (!(idata = imap_conn_find (&mx.account,
+          option (OPTIMAPPASSIVE) ? M_IMAP_CONN_NONEW : 0)))
+    {
+      FREE (&mx.mbox);
+      return -1;
+    }
   } else {
-         idata = ctx->data;
+    idata = ctx->data;
   }
 
   imap_munge_mbox_name (mbox, sizeof (mbox), mx.mbox);
index ae42ff2f8f806af21fbc50b1c628bd47a1ce4d00..9ac7a95e67da606842655c8ef046f59699efeefa 100644 (file)
@@ -50,6 +50,7 @@ void imap_disallow_reopen (CONTEXT *ctx);
 /* browse.c */
 int imap_browse (char* path, struct browser_state* state);
 int imap_mailbox_create (const char* folder);
+int imap_mailbox_rename (const char* mailbox);
 
 /* message.c */
 int imap_append_message (CONTEXT* ctx, MESSAGE* msg);
index 056fbcfc2cade652fc5911c52f1c128b4028f63e..848326bc6dfdbc158133aab2c36fbfd8e223e456 100644 (file)
@@ -194,6 +194,7 @@ typedef struct
 /* -- private IMAP functions -- */
 /* imap.c */
 int imap_create_mailbox (IMAP_DATA* idata, char* mailbox);
+int imap_rename_mailbox (IMAP_DATA* idata, IMAP_MBOX* mx, const char* newname);
 int imap_make_msg_set (IMAP_DATA* idata, BUFFER* buf, int flag, int changed);
 int imap_open_connection (IMAP_DATA* idata);
 IMAP_DATA* imap_conn_find (const ACCOUNT* account, int flags);