Unicode C++
Unicode C++
Fetch Only an IMAP Message's Headers
See more IMAP Examples
Demonstrates the Chilkat Imap.FetchSingleHeaderAsMime method, which downloads and returns the MIME header block for one message, without downloading the body. If the second argument (bUID) is true, the first argument is a UID; otherwise it is a sequence number. This example fetches message 1's headers.
Background: Headers are tiny compared to a full message with attachments, so fetching just the header block is the fast, bandwidth-friendly way to build a message list — sender, subject, date — without pulling every body. It is also gentler on read state: retrieving only headers does not mark a message as seen. Download the full message later, on demand, when the user opens it.
Chilkat Unicode C++ Downloads
#include <CkImapW.h>
void ChilkatSample(void)
{
bool success = false;
// Demonstrates the Imap.FetchSingleHeaderAsMime method, which downloads and returns the MIME
// header block for one message, without downloading the body. If the 2nd argument (bUID)
// is true, the 1st argument is a UID; otherwise it is a sequence number.
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;
}
// Download only the MIME header block of message sequence number 1. bUID = false.
const wchar_t *headers = imap.fetchSingleHeaderAsMime(1,false);
if (imap.get_LastMethodSuccess() == false) {
wprintf(L"%s\n",imap.lastErrorText());
return;
}
wprintf(L"%s\n",headers);
success = imap.Disconnect();
if (success == false) {
wprintf(L"%s\n",imap.lastErrorText());
return;
}
}