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) Get IMAP UID from Email HeaderDemonstrates how to get the IMAP UID from an email header. After fetching an email or header using IMAP, the UID is contained in the ckx-imap-uid header field.
load ./chilkat.dll # This example requires 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 "login" "password"] 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 } set fetchUids 1 # Get the message UIDs of all the emails in the mailbox # messageSet is a CkMessageSet set messageSet [CkImap_Search $imap "ALL" $fetchUids] if {[CkImap_get_LastMethodSuccess $imap] != 1} then { puts [CkImap_lastErrorText $imap] delete_CkImap $imap exit } # bundle is a CkEmailBundle set bundle [CkImap_FetchHeaders $imap $messageSet] if {[CkImap_get_LastMethodSuccess $imap] != 1} then { delete_CkMessageSet $messageSet puts [CkImap_lastErrorText $imap] delete_CkImap $imap exit } # The UID of each fetched email header is available # in the ckx-imap-uid header field. set i 0 set szBundle [CkEmailBundle_get_MessageCount $bundle] set msOneMsg [new_CkMessageSet] while {$i < $szBundle} { # email is a CkEmail set email [CkEmailBundle_GetEmail $bundle $i] # Build a message set containing one UID set uidStr [CkEmail_getHeaderField $email "ckx-imap-uid"] CkMessageSet_FromCompactString $msOneMsg $uidStr # Move this message to some other folder. set success [CkImap_MoveMessages $imap $msOneMsg "someOtherFolder"] if {$success != 1} then { puts [CkImap_lastErrorText $imap] # Exit the loop... set i $szBundle } 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 delete_CkMessageSet $msOneMsg |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.