Unicode C
Unicode C
Get the Total Size of an IMAP Message
See more IMAP Examples
Demonstrates the Chilkat Imap.GetMailSize method, which returns the complete server-reported size of a message in bytes, including attachment data. The only argument is the Email. This example fetches only the headers and prints the full message size.
Background: The server reports each message's total size, so this value is available even when only the headers were downloaded. That lets a client show a size column in a message list, sort by size, or warn the user before downloading an unusually large message — all without fetching the full body first.
Chilkat Unicode C Downloads
#include <C_CkImapW.h>
#include <C_CkEmailW.h>
void ChilkatSample(void)
{
BOOL success;
HCkImapW imap;
BOOL headersOnly;
BOOL useUid;
int seqNum;
HCkEmailW email;
int sizeBytes;
success = FALSE;
// Demonstrates the Imap.GetMailSize method, which returns the complete server-reported size
// of a message in bytes, including attachments. The only argument is the Email.
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;
}
// Fetch only the message headers. Attachment bodies are NOT downloaded, but the ckx-imap-*
// metadata describing the attachments is present, so the attachment info methods still work.
headersOnly = TRUE;
useUid = FALSE;
seqNum = 1;
email = CkEmailW_Create();
success = CkImapW_FetchEmail(imap,headersOnly,seqNum,useUid,email);
if (success == FALSE) {
wprintf(L"%s\n",CkImapW_lastErrorText(imap));
CkImapW_Dispose(imap);
CkEmailW_Dispose(email);
return;
}
sizeBytes = CkImapW_GetMailSize(imap,email);
wprintf(L"Total message size: %d bytes\n",sizeBytes);
success = CkImapW_Disconnect(imap);
if (success == FALSE) {
wprintf(L"%s\n",CkImapW_lastErrorText(imap));
CkImapW_Dispose(imap);
CkEmailW_Dispose(email);
return;
}
CkImapW_Dispose(imap);
CkEmailW_Dispose(email);
}