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.
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"
}
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
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>
#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" },
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)
{
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);
/* 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);
/* -- 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);