Unicode C++
Unicode C++
Get IMAP UID from Email Header
See more IMAP Examples
Demonstrates how to get the IMAP UID from an email header. After fetching an email or header using IMAP, the UID is contained in the ckx-imap-uid header field.Chilkat Unicode C++ Downloads
#include <CkImapW.h>
#include <CkMessageSetW.h>
#include <CkEmailBundleW.h>
#include <CkEmailW.h>
void ChilkatSample(void)
{
bool success = false;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkImapW imap;
// Connect to an IMAP server.
// Use TLS
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;
}
// Login
success = imap.Login(L"login",L"password");
if (success == false) {
wprintf(L"%s\n",imap.lastErrorText());
return;
}
// Select an IMAP mailbox
success = imap.SelectMailbox(L"Inbox");
if (success == false) {
wprintf(L"%s\n",imap.lastErrorText());
return;
}
bool fetchUids = true;
// Get the message UIDs of all the emails in the mailbox
CkMessageSetW messageSet;
success = imap.QueryMbx(L"ALL",fetchUids,messageSet);
if (success == false) {
wprintf(L"%s\n",imap.lastErrorText());
return;
}
CkEmailBundleW bundle;
bool headersOnly = true;
success = imap.FetchMsgSet(headersOnly,messageSet,bundle);
if (success == false) {
wprintf(L"%s\n",imap.lastErrorText());
return;
}
// The UID of each fetched email header is available
// in the ckx-imap-uid header field.
CkEmailW email;
CkMessageSetW msgSet1;
int i = 0;
int szBundle = bundle.get_MessageCount();
while (i < szBundle) {
bundle.EmailAt(i,email);
// Build a message set containing one UID
const wchar_t *uidStr = email.getHeaderField(L"ckx-imap-uid");
msgSet1.FromCompactString(uidStr);
// Move this message to some other folder.
success = imap.MoveMessages(msgSet1,L"someOtherFolder");
if (success != true) {
wprintf(L"%s\n",imap.lastErrorText());
// Exit the loop...
i = szBundle;
}
i = i + 1;
}
// Disconnect from the IMAP server.
success = imap.Disconnect();
}