Tcl
Tcl
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 Tcl Downloads
load ./chilkat.dll
set success 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.
set imap [new_CkImap]
CkImap_put_Ssl $imap 1
CkImap_put_Port $imap 993
set success [CkImap_Connect $imap "imap.example.com"]
if {$success == 0} then {
puts [CkImap_lastErrorText $imap]
delete_CkImap $imap
exit
}
set success [CkImap_Login $imap "user@example.com" "myPassword"]
if {$success == 0} then {
puts [CkImap_lastErrorText $imap]
delete_CkImap $imap
exit
}
set success [CkImap_SelectMailbox $imap "Inbox"]
if {$success == 0} then {
puts [CkImap_lastErrorText $imap]
delete_CkImap $imap
exit
}
# 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.
set headersOnly 1
set useUid 0
set seqNum 1
set email [new_CkEmail]
set success [CkImap_FetchEmail $imap $headersOnly $seqNum $useUid $email]
if {$success == 0} then {
puts [CkImap_lastErrorText $imap]
delete_CkImap $imap
delete_CkEmail $email
exit
}
set sizeBytes [CkImap_GetMailSize $imap $email]
puts "Total message size: $sizeBytes bytes"
set success [CkImap_Disconnect $imap]
if {$success == 0} then {
puts [CkImap_lastErrorText $imap]
delete_CkImap $imap
delete_CkEmail $email
exit
}
delete_CkImap $imap
delete_CkEmail $email