X-Git-Url: http://git.madism.org/?a=blobdiff_plain;f=imap%2Fbrowse.c;h=f2b01f4dabfeceb07a9865ed4752c5f7f427d923;hb=777c7ccc259a8b7f5fadac70267c59e62a2cb300;hp=760870e68a433641267224b7d00885adc53c7825;hpb=f404a0ca916be07049af51a3022baaaaab94def6;p=apps%2Fmadmutt.git diff --git a/imap/browse.c b/imap/browse.c index 760870e..f2b01f4 100644 --- a/imap/browse.c +++ b/imap/browse.c @@ -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) {