C
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 C Downloads
#include <C_CkImap.h>
#include <C_CkEmail.h>
void ChilkatSample(void)
{
BOOL success;
HCkImap imap;
BOOL headersOnly;
BOOL useUid;
int seqNum;
HCkEmail 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 = CkImap_Create();
CkImap_putSsl(imap,TRUE);
CkImap_putPort(imap,993);
success = CkImap_Connect(imap,"imap.example.com");
if (success == FALSE) {
printf("%s\n",CkImap_lastErrorText(imap));
CkImap_Dispose(imap);
return;
}
success = CkImap_Login(imap,"user@example.com","myPassword");
if (success == FALSE) {
printf("%s\n",CkImap_lastErrorText(imap));
CkImap_Dispose(imap);
return;
}
success = CkImap_SelectMailbox(imap,"Inbox");
if (success == FALSE) {
printf("%s\n",CkImap_lastErrorText(imap));
CkImap_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 = CkEmail_Create();
success = CkImap_FetchEmail(imap,headersOnly,seqNum,useUid,email);
if (success == FALSE) {
printf("%s\n",CkImap_lastErrorText(imap));
CkImap_Dispose(imap);
CkEmail_Dispose(email);
return;
}
sizeBytes = CkImap_GetMailSize(imap,email);
printf("Total message size: %d bytes\n",sizeBytes);
success = CkImap_Disconnect(imap);
if (success == FALSE) {
printf("%s\n",CkImap_lastErrorText(imap));
CkImap_Dispose(imap);
CkEmail_Dispose(email);
return;
}
CkImap_Dispose(imap);
CkEmail_Dispose(email);
}