C
C
Copy an IMAP Message to Another Mailbox
See more IMAP Examples
Demonstrates the Chilkat Imap.Copy method, which copies one message from the currently selected mailbox to a destination mailbox. The first argument identifies the source message; the second (bUid) indicates whether the id is a UID (true) or a sequence number (false). This example copies a message from the Inbox to another mailbox.
Background: Messages can be identified two ways in IMAP: a sequence number (the message's current 1-based position, which shifts as messages are added or expunged) or a UID (a stable identifier that doesn't change). The
bUid flag tells Copy which you're passing. Copying leaves the original in place and places a duplicate in the destination — use MoveMessages to relocate instead of duplicate.Chilkat C Downloads
#include <C_CkImap.h>
void ChilkatSample(void)
{
BOOL success;
HCkImap imap;
success = FALSE;
// Demonstrates the Imap.Copy method, which copies one message from the currently selected
// mailbox to a destination mailbox. The 1st argument identifies the source message; the 2nd
// (bUid) indicates whether the id is a UID (TRUE) or a sequence number (FALSE).
imap = CkImap_Create();
CkImap_putSsl(imap,TRUE);
CkImap_putPort(imap,993);
success = CkImap_Connect(imap,"imap.example.com");
if (success == FALSE) {
printf("%s\n",CkImap_lastErrorText(imap));
CkImap_Dispose(imap);
return;
}
success = CkImap_Login(imap,"user@example.com","myPassword");
if (success == FALSE) {
printf("%s\n",CkImap_lastErrorText(imap));
CkImap_Dispose(imap);
return;
}
// Select the source mailbox.
success = CkImap_SelectMailbox(imap,"Inbox");
if (success == FALSE) {
printf("%s\n",CkImap_lastErrorText(imap));
CkImap_Dispose(imap);
return;
}
// Copy message sequence number 1 to the "Archive2026" mailbox. bUid = FALSE means the id
// is a sequence number, not a UID.
success = CkImap_Copy(imap,1,FALSE,"Archive2026");
if (success == FALSE) {
printf("%s\n",CkImap_lastErrorText(imap));
CkImap_Dispose(imap);
return;
}
printf("Message copied.\n");
success = CkImap_Disconnect(imap);
if (success == FALSE) {
printf("%s\n",CkImap_lastErrorText(imap));
CkImap_Dispose(imap);
return;
}
CkImap_Dispose(imap);
}