Delphi DLL
Delphi DLL
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 Delphi DLL Downloads
var
success: Boolean;
imap: HCkImap;
headersOnly: Boolean;
useUid: Boolean;
seqNum: Integer;
email: HCkEmail;
sizeBytes: Integer;
begin
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) then
begin
Memo1.Lines.Add(CkImap__lastErrorText(imap));
Exit;
end;
success := CkImap_Login(imap,'user@example.com','myPassword');
if (success = False) then
begin
Memo1.Lines.Add(CkImap__lastErrorText(imap));
Exit;
end;
success := CkImap_SelectMailbox(imap,'Inbox');
if (success = False) then
begin
Memo1.Lines.Add(CkImap__lastErrorText(imap));
Exit;
end;
// 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) then
begin
Memo1.Lines.Add(CkImap__lastErrorText(imap));
Exit;
end;
sizeBytes := CkImap_GetMailSize(imap,email);
Memo1.Lines.Add('Total message size: ' + IntToStr(sizeBytes) + ' bytes');
success := CkImap_Disconnect(imap);
if (success = False) then
begin
Memo1.Lines.Add(CkImap__lastErrorText(imap));
Exit;
end;
CkImap_Dispose(imap);
CkEmail_Dispose(email);