Unicode C
Unicode C
Download MIME Source of Emails in IMAP Mailbox
Demonstrates how to download the MIME source for emails on an IMAP server.Chilkat Unicode C Downloads
#include <C_CkImapW.h>
#include <C_CkStringBuilderW.h>
void ChilkatSample(void)
{
BOOL success;
HCkImapW imap;
int numMessages;
HCkStringBuilderW sbMime;
int seqNum;
success = FALSE;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
imap = CkImapW_Create();
// Connect to an IMAP server.
// Use TLS
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;
}
// Login
success = CkImapW_Login(imap,L"myLogin",L"myPassword");
if (success == FALSE) {
wprintf(L"%s\n",CkImapW_lastErrorText(imap));
CkImapW_Dispose(imap);
return;
}
// Select an IMAP mailbox
success = CkImapW_SelectMailbox(imap,L"Inbox");
if (success == FALSE) {
wprintf(L"%s\n",CkImapW_lastErrorText(imap));
CkImapW_Dispose(imap);
return;
}
// The NumMessages property contains the number of messages in the selected mailbox.
numMessages = CkImapW_getNumMessages(imap);
if (numMessages == 0) {
wprintf(L"No messages exist in the Inbox.\n");
CkImapW_Dispose(imap);
return;
}
sbMime = CkStringBuilderW_Create();
for (seqNum = 1; seqNum <= numMessages; seqNum++) {
CkStringBuilderW_Clear(sbMime);
success = CkImapW_FetchSingleAsMimeSb(imap,seqNum,FALSE,sbMime);
if (success == FALSE) {
wprintf(L"%s\n",CkImapW_lastErrorText(imap));
CkImapW_Dispose(imap);
CkStringBuilderW_Dispose(sbMime);
return;
}
// The MIME source of the downloaded email is contained in sbMime.
}
// Disconnect from the IMAP server.
success = CkImapW_Disconnect(imap);
CkImapW_Dispose(imap);
CkStringBuilderW_Dispose(sbMime);
}