PureBasic
PureBasic
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 PureBasic Downloads
IncludeFile "CkEmail.pb"
IncludeFile "CkImap.pb"
Procedure ChilkatExample()
success.i = 0
; 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.i = CkImap::ckCreate()
If imap.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkImap::setCkSsl(imap, 1)
CkImap::setCkPort(imap, 993)
success = CkImap::ckConnect(imap,"imap.example.com")
If success = 0
Debug CkImap::ckLastErrorText(imap)
CkImap::ckDispose(imap)
ProcedureReturn
EndIf
success = CkImap::ckLogin(imap,"user@example.com","myPassword")
If success = 0
Debug CkImap::ckLastErrorText(imap)
CkImap::ckDispose(imap)
ProcedureReturn
EndIf
success = CkImap::ckSelectMailbox(imap,"Inbox")
If success = 0
Debug CkImap::ckLastErrorText(imap)
CkImap::ckDispose(imap)
ProcedureReturn
EndIf
; 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.i = 1
useUid.i = 0
seqNum.i = 1
email.i = CkEmail::ckCreate()
If email.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success = CkImap::ckFetchEmail(imap,headersOnly,seqNum,useUid,email)
If success = 0
Debug CkImap::ckLastErrorText(imap)
CkImap::ckDispose(imap)
CkEmail::ckDispose(email)
ProcedureReturn
EndIf
sizeBytes.i = CkImap::ckGetMailSize(imap,email)
Debug "Total message size: " + Str(sizeBytes) + " bytes"
success = CkImap::ckDisconnect(imap)
If success = 0
Debug CkImap::ckLastErrorText(imap)
CkImap::ckDispose(imap)
CkEmail::ckDispose(email)
ProcedureReturn
EndIf
CkImap::ckDispose(imap)
CkEmail::ckDispose(email)
ProcedureReturn
EndProcedure