720
749
imap_fix_path (idata, mx.mbox, mbox, sizeof (mbox));
722
memset (&sync_cmd, 0, sizeof (sync_cmd));
723
memset (&cmd, 0, sizeof (cmd));
724
mutt_buffer_addstr (&cmd, "UID COPY ");
726
/* Null HEADER* means copy tagged messages */
729
/* if any messages have attachments to delete, fall through to FETCH
730
* and APPEND. TODO: Copy what we can with COPY, fall through for the
732
for (n = 0; n < ctx->msgcount; n++)
734
if (ctx->hdrs[n]->tagged && ctx->hdrs[n]->attach_del)
736
dprint (3, (debugfile, "imap_copy_messages: Message contains attachments to be deleted\n"));
740
if (ctx->hdrs[n]->tagged && ctx->hdrs[n]->active &&
741
ctx->hdrs[n]->changed)
743
rc = imap_sync_message (idata, ctx->hdrs[n], &sync_cmd, &err_continue);
746
dprint (1, (debugfile, "imap_copy_messages: could not sync\n"));
752
rc = imap_make_msg_set (idata, &cmd, M_TAG, 0, 0);
755
dprint (1, (debugfile, "imap_copy_messages: No messages tagged\n"));
758
mutt_message (_("Copying %d messages to %s..."), rc, mbox);
762
mutt_message (_("Copying message %d to %s..."), h->index+1, mbox);
763
snprintf (uid, sizeof (uid), "%u", HEADER_DATA (h)->uid);
764
mutt_buffer_addstr (&cmd, uid);
766
if (h->active && h->changed)
768
rc = imap_sync_message (idata, h, &sync_cmd, &err_continue);
771
dprint (1, (debugfile, "imap_copy_messages: could not sync\n"));
777
/* let's get it on */
778
mutt_buffer_addstr (&cmd, " ");
751
strfcpy (mbox, "INBOX", sizeof (mbox));
779
752
imap_munge_mbox_name (mmbox, sizeof (mmbox), mbox);
780
mutt_buffer_addstr (&cmd, mmbox);
782
rc = imap_exec (idata, cmd.data, IMAP_CMD_FAIL_OK);
754
/* loop in case of TRYCREATE */
785
/* bail out if command failed for reasons other than nonexistent target */
786
if (ascii_strncasecmp (imap_get_qualifier (idata->buf), "[TRYCREATE]", 11))
788
imap_error ("imap_copy_messages", idata->buf);
791
dprint (2, (debugfile, "imap_copy_messages: server suggests TRYCREATE\n"));
792
snprintf (mmbox, sizeof (mmbox), _("Create %s?"), mbox);
793
if (option (OPTCONFIRMCREATE) && mutt_yesorno (mmbox, 1) < 1)
798
if (imap_create_mailbox (idata, mbox) < 0)
802
rc = imap_exec (idata, cmd.data, 0);
757
memset (&sync_cmd, 0, sizeof (sync_cmd));
758
memset (&cmd, 0, sizeof (cmd));
760
/* Null HEADER* means copy tagged messages */
763
/* if any messages have attachments to delete, fall through to FETCH
764
* and APPEND. TODO: Copy what we can with COPY, fall through for the
766
for (n = 0; n < ctx->msgcount; n++)
768
if (ctx->hdrs[n]->tagged && ctx->hdrs[n]->attach_del)
770
dprint (3, (debugfile, "imap_copy_messages: Message contains attachments to be deleted\n"));
774
if (ctx->hdrs[n]->tagged && ctx->hdrs[n]->active &&
775
ctx->hdrs[n]->changed)
777
rc = imap_sync_message (idata, ctx->hdrs[n], &sync_cmd, &err_continue);
780
dprint (1, (debugfile, "imap_copy_messages: could not sync\n"));
786
rc = imap_exec_msgset (idata, "UID COPY", mmbox, M_TAG, 0, 0);
789
dprint (1, (debugfile, "imap_copy_messages: No messages tagged\n"));
794
dprint (1, (debugfile, "could not queue copy\n"));
798
mutt_message (_("Copying %d messages to %s..."), rc, mbox);
802
mutt_message (_("Copying message %d to %s..."), h->index+1, mbox);
803
mutt_buffer_printf (&cmd, "UID COPY %u %s", HEADER_DATA (h)->uid, mmbox);
805
if (h->active && h->changed)
807
rc = imap_sync_message (idata, h, &sync_cmd, &err_continue);
810
dprint (1, (debugfile, "imap_copy_messages: could not sync\n"));
814
if ((rc = imap_exec (idata, cmd.data, IMAP_CMD_QUEUE)) < 0)
816
dprint (1, (debugfile, "could not queue copy\n"));
821
/* let's get it on */
822
rc = imap_exec (idata, NULL, IMAP_CMD_FAIL_OK);
827
dprint (1, (debugfile, "Already tried to create mailbox %s\n", mbox));
830
/* bail out if command failed for reasons other than nonexistent target */
831
if (ascii_strncasecmp (imap_get_qualifier (idata->buf), "[TRYCREATE]", 11))
833
dprint (3, (debugfile, "imap_copy_messages: server suggests TRYCREATE\n"));
834
snprintf (prompt, sizeof (prompt), _("Create %s?"), mbox);
835
if (option (OPTCONFIRMCREATE) && mutt_yesorno (prompt, 1) < 1)
840
if (imap_create_mailbox (idata, mbox) < 0)
806
849
imap_error ("imap_copy_messages", idata->buf);