![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Visual FoxPro) 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. Note: This example requires Chilkat v11.0.0 or greater.
LOCAL lnSuccess LOCAL loImap LOCAL lnFetchUids LOCAL loMessageSet LOCAL loBundle LOCAL lnHeadersOnly LOCAL loEmail LOCAL loMsgSet1 LOCAL i LOCAL lnSzBundle LOCAL lcUidStr lnSuccess = 0 * This example requires the Chilkat API to have been previously unlocked. * See Global Unlock Sample for sample code. loImap = CreateObject('Chilkat.Imap') * Connect to an IMAP server. * Use TLS loImap.Ssl = 1 loImap.Port = 993 lnSuccess = loImap.Connect("imap.someMailServer.com") IF (lnSuccess = 0) THEN ? loImap.LastErrorText RELEASE loImap CANCEL ENDIF * Login lnSuccess = loImap.Login("login","password") IF (lnSuccess = 0) THEN ? loImap.LastErrorText RELEASE loImap CANCEL ENDIF * Select an IMAP mailbox lnSuccess = loImap.SelectMailbox("Inbox") IF (lnSuccess = 0) THEN ? loImap.LastErrorText RELEASE loImap CANCEL ENDIF lnFetchUids = 1 * Get the message UIDs of all the emails in the mailbox loMessageSet = CreateObject('Chilkat.MessageSet') lnSuccess = loImap.QueryMbx("ALL",lnFetchUids,loMessageSet) IF (lnSuccess = 0) THEN ? loImap.LastErrorText RELEASE loImap RELEASE loMessageSet CANCEL ENDIF loBundle = CreateObject('Chilkat.EmailBundle') lnHeadersOnly = 1 lnSuccess = loImap.FetchMsgSet(lnHeadersOnly,loMessageSet,loBundle) IF (lnSuccess = 0) THEN ? loImap.LastErrorText RELEASE loImap RELEASE loMessageSet RELEASE loBundle CANCEL ENDIF * The UID of each fetched email header is available * in the ckx-imap-uid header field. loEmail = CreateObject('Chilkat.Email') loMsgSet1 = CreateObject('Chilkat.MessageSet') i = 0 lnSzBundle = loBundle.MessageCount DO WHILE i < lnSzBundle loBundle.EmailAt(i,loEmail) * Build a message set containing one UID lcUidStr = loEmail.GetHeaderField("ckx-imap-uid") loMsgSet1.FromCompactString(lcUidStr) * Move this message to some other folder. lnSuccess = loImap.MoveMessages(loMsgSet1,"someOtherFolder") IF (lnSuccess <> 1) THEN ? loImap.LastErrorText * Exit the loop... i = lnSzBundle ENDIF i = i + 1 ENDDO * Disconnect from the IMAP server. lnSuccess = loImap.Disconnect() RELEASE loImap RELEASE loMessageSet RELEASE loBundle RELEASE loEmail RELEASE loMsgSet1 |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.