Unicode C
Unicode C
Store One or More Flags on a Single Message
See more IMAP Examples
Demonstrates the Chilkat Imap.StoreFlags method, which sets or clears one or more flags on a single message identified by ID. The first argument is the message ID, the second (bUid) selects UID vs sequence number, the third is a space-separated list of flag names, and the fourth is the value (1 to set, 0 to clear). This example applies the Seen and Flagged flags to one message by UID.
Background:
StoreFlags is the single-message counterpart to SetFlags and lets you change several flags at once by listing them space-separated (without leading backslashes). Because the ID can be either a UID or a sequence number, the bUid argument must match how you obtained it — a UID from a UID search, or a sequence number from a sequence-based operation. UIDs are the safer choice since they remain valid as the mailbox changes.Chilkat Unicode C Downloads
#include <C_CkImapW.h>
#include <C_CkMessageSetW.h>
void ChilkatSample(void)
{
BOOL success;
HCkImapW imap;
HCkMessageSetW msgSet;
unsigned long uid;
success = FALSE;
// Demonstrates the Imap.StoreFlags method, which sets or clears one or more flags on a single
// message identified by ID. The 1st argument is the message ID, the 2nd (bUid) selects UID
// vs sequence number, the 3rd is a space-separated list of flag names, and the 4th is the
// value (1 to set, 0 to clear).
imap = CkImapW_Create();
CkImapW_putSsl(imap,TRUE);
CkImapW_putPort(imap,993);
success = CkImapW_Connect(imap,L"imap.example.com");
if (success == FALSE) {
wprintf(L"%s\n",CkImapW_lastErrorText(imap));
CkImapW_Dispose(imap);
return;
}
success = CkImapW_Login(imap,L"user@example.com",L"myPassword");
if (success == FALSE) {
wprintf(L"%s\n",CkImapW_lastErrorText(imap));
CkImapW_Dispose(imap);
return;
}
success = CkImapW_SelectMailbox(imap,L"Inbox");
if (success == FALSE) {
wprintf(L"%s\n",CkImapW_lastErrorText(imap));
CkImapW_Dispose(imap);
return;
}
// Get the UIDs of all messages.
msgSet = CkMessageSetW_Create();
success = CkImapW_QueryMbx(imap,L"ALL",TRUE,msgSet);
if (success == FALSE) {
wprintf(L"%s\n",CkImapW_lastErrorText(imap));
CkImapW_Dispose(imap);
CkMessageSetW_Dispose(msgSet);
return;
}
if (CkMessageSetW_getCount(msgSet) > 0) {
// Apply the Seen and Flagged flags to the first message. bUid is TRUE because the ID
// came from a UID search.
uid = CkMessageSetW_GetId(msgSet,0);
success = CkImapW_StoreFlags(imap,uid,TRUE,L"Seen Flagged",1);
if (success == FALSE) {
wprintf(L"%s\n",CkImapW_lastErrorText(imap));
CkImapW_Dispose(imap);
CkMessageSetW_Dispose(msgSet);
return;
}
wprintf(L"Updated flags on UID %u\n",uid);
}
success = CkImapW_Disconnect(imap);
if (success == FALSE) {
wprintf(L"%s\n",CkImapW_lastErrorText(imap));
CkImapW_Dispose(imap);
CkMessageSetW_Dispose(msgSet);
return;
}
CkImapW_Dispose(imap);
CkMessageSetW_Dispose(msgSet);
}