Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Tcl) Imap.GetMailSize vs Email.SizeShows how to get the total size of an email, as well as the sizes of the attachments. This can be done when either full-emails or headers-only are downloaded.
load ./chilkat.dll # This example assumes the Chilkat API to have been previously unlocked. # See Global Unlock Sample for sample code. set imap [new_CkImap] # Connect to an IMAP server. # Use TLS CkImap_put_Ssl $imap 1 CkImap_put_Port $imap 993 set success [CkImap_Connect $imap "imap.someMailServer.com"] if {$success != 1} then { puts [CkImap_lastErrorText $imap] delete_CkImap $imap exit } # Login set success [CkImap_Login $imap "****" "****"] if {$success != 1} then { puts [CkImap_lastErrorText $imap] delete_CkImap $imap exit } # Select an IMAP mailbox set success [CkImap_SelectMailbox $imap "Inbox"] if {$success != 1} then { puts [CkImap_lastErrorText $imap] delete_CkImap $imap exit } # messageSet is a CkMessageSet # We can choose to fetch UIDs or sequence numbers. set fetchUids 1 # Get the message IDs of all the emails in the mailbox set messageSet [CkImap_Search $imap "ALL" $fetchUids] if {[CkImap_get_LastMethodSuccess $imap] == 0} then { puts [CkImap_lastErrorText $imap] delete_CkImap $imap exit } # When downloading headers, each email object contains # (obviously) the headers, but the body will be missing. # Also, attachments will not be included. However, it is # possible to get information about the attachments # as well as the complete size of the email. # bundle is a CkEmailBundle set bundle [CkImap_FetchHeaders $imap $messageSet] if {[CkImap_get_LastMethodSuccess $imap] == 0} then { delete_CkMessageSet $messageSet puts [CkImap_lastErrorText $imap] delete_CkImap $imap exit } # Loop over the email objects and display information # about each: set i 0 set numEmails [CkEmailBundle_get_MessageCount $bundle] while {$i < $numEmails} { # email is a CkEmail set email [CkEmailBundle_GetEmail $bundle $i] # Display the From and Subject puts [CkEmail_from $email] puts [CkEmail_subject $email] # Display the recipients: for {set j 0} {$j <= [expr [CkEmail_get_NumTo $email] - 1]} {incr j} { puts [CkEmail_getToName $email $j], [CkEmail_getToAddr $email $j] } for {set j 0} {$j <= [expr [CkEmail_get_NumCC $email] - 1]} {incr j} { puts [CkEmail_getCcName $email $j], [CkEmail_getCcAddr $email $j] } # Show the total size of the email, including body and attachments: puts [CkEmail_get_Size $email] # When a full email is downloaded, we would use the # email.NumAttachments property in conjunction with the # email.GetMailAttach* methods. # However, when an email object contains only the header, # we need to access the attachment info differently: set numAttach [CkImap_GetMailNumAttach $imap $email] for {set j 0} {$j <= [expr $numAttach - 1]} {incr j} { puts [CkImap_getMailAttachFilename $imap $email $j] set attachSize [CkImap_GetMailAttachSize $imap $email $j] puts " size = $attachSize bytes" } puts "--" delete_CkEmail $email set i [expr $i + 1] } # Disconnect from the IMAP server. set success [CkImap_Disconnect $imap] delete_CkMessageSet $messageSet delete_CkEmailBundle $bundle delete_CkImap $imap |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.