Unicode C++
Unicode C++
Copy Multiple IMAP Messages to Another Mailbox
See more IMAP Examples
Demonstrates the Chilkat Imap.CopyMultiple method, which copies the messages in a MessageSet to another mailbox, leaving the originals in place. The first argument is the MessageSet and the second is the destination mailbox name. This example searches for recent messages and copies them to a Backup mailbox.
Background: This maps to the IMAP
COPY command, which duplicates messages entirely on the server — nothing is downloaded. The copy in the destination mailbox is an independent message with its own UID; changing flags on one copy does not affect the other. Combine CopyMultiple with a search from QueryMbx to snapshot or archive matching messages without removing them from their current folder.Chilkat Unicode C++ Downloads
#include <CkImapW.h>
#include <CkMessageSetW.h>
void ChilkatSample(void)
{
bool success = false;
// Demonstrates the Imap.CopyMultiple method, which copies the messages in a MessageSet to
// another mailbox, leaving the originals in place. The 1st argument is the MessageSet and
// the 2nd is the destination mailbox name.
CkImapW imap;
imap.put_Ssl(true);
imap.put_Port(993);
success = imap.Connect(L"imap.example.com");
if (success == false) {
wprintf(L"%s\n",imap.lastErrorText());
return;
}
success = imap.Login(L"user@example.com",L"myPassword");
if (success == false) {
wprintf(L"%s\n",imap.lastErrorText());
return;
}
success = imap.SelectMailbox(L"Inbox");
if (success == false) {
wprintf(L"%s\n",imap.lastErrorText());
return;
}
// Find the messages to copy (here, messages seen today, by UID).
CkMessageSetW msgSet;
success = imap.QueryMbx(L"SINCE 15-Jul-2026",true,msgSet);
if (success == false) {
wprintf(L"%s\n",imap.lastErrorText());
return;
}
// Copy them to the "Backup" mailbox. The originals remain in the Inbox.
success = imap.CopyMultiple(msgSet,L"Backup");
if (success == false) {
wprintf(L"%s\n",imap.lastErrorText());
return;
}
wprintf(L"Copied %d messages to Backup.\n",msgSet.get_Count());
success = imap.Disconnect();
if (success == false) {
wprintf(L"%s\n",imap.lastErrorText());
return;
}
}