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
(DataFlex) Fetch Full Email Given Email HeaderWhen email headers are fetched using UIDs (not sequence numbers), then the resultant email object (containing only the header) will include auto-generated ckx-imap-* header fields to record information about the uid, attachments, etc. The IMAP UID of the email will be available in the "ckx-imap-uid" header. There will also be a "ckx-imap-isUid" header field having the value "YES" or "NO". If the email header was downloaded by UID, then "ckx-imap-isUID" will contain the value "YES" and the value of the "ckx-imap-uid" header field is the IMAP UID. If the "ckx-imap-isUID" header has a value of "NO", then the "ckx-imap-uid" header field represents the sequence number. (Sequence numbers of emails on the server can change over time, depending on whether emails are deleted. UIDs must be used to ensure that the correct full email is downloaded.) The Chilkat Email object provides a GetImapUid method to return the UID from the ckx-imap-uid header. This can then be used to download the full email using the FetchSingle method. Assuming the UID is known, download a single email by UID from an IMAP mail server.
Use ChilkatAx-win32.pkg Procedure Test Handle hoImap Boolean iSuccess Variant vEmailHeader Handle hoEmailHeader Variant vEmailFull Handle hoEmailFull Integer iUid Boolean iIsUid Integer iUidFromCkxHeader String sTemp1 Boolean bTemp1 // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. Get Create (RefClass(cComChilkatImap)) To hoImap If (Not(IsComObjectCreated(hoImap))) Begin Send CreateComObject of hoImap End // Connect to an IMAP server. // Use TLS Set ComSsl Of hoImap To True Set ComPort Of hoImap To 993 Get ComConnect Of hoImap "imap.someMailServer.com" To iSuccess If (iSuccess <> True) Begin Get ComLastErrorText Of hoImap To sTemp1 Showln sTemp1 Procedure_Return End // Login Get ComLogin Of hoImap "***" "***" To iSuccess If (iSuccess <> True) Begin Get ComLastErrorText Of hoImap To sTemp1 Showln sTemp1 Procedure_Return End // Select an IMAP mailbox Get ComSelectMailbox Of hoImap "Inbox" To iSuccess If (iSuccess <> True) Begin Get ComLastErrorText Of hoImap To sTemp1 Showln sTemp1 Procedure_Return End Move 2014 To iUid Move True To iIsUid // Fetch only the email header Get ComFetchSingleHeader Of hoImap iUid iIsUid To vEmailHeader If (IsComObject(vEmailHeader)) Begin Get Create (RefClass(cComChilkatEmail)) To hoEmailHeader Set pvComObject Of hoEmailHeader To vEmailHeader End Get ComLastMethodSuccess Of hoImap To bTemp1 If (bTemp1 = True) Begin // Now fetch the full email Get ComGetImapUid Of hoEmailHeader To iUidFromCkxHeader If (iUidFromCkxHeader < 0) Begin // Failed. Send Destroy of hoEmailHeader Showln "No ckx-imap-uid header was found." Procedure_Return End Get ComFetchSingle Of hoImap iUidFromCkxHeader True To vEmailFull If (IsComObject(vEmailFull)) Begin Get Create (RefClass(cComChilkatEmail)) To hoEmailFull Set pvComObject Of hoEmailFull To vEmailFull End Get ComLastMethodSuccess Of hoImap To bTemp1 If (bTemp1 = True) Begin // OK, we have the full email, do whatever we want... Send Destroy of hoEmailFull End Send Destroy of hoEmailHeader End // Disconnect from the IMAP server. Get ComDisconnect Of hoImap To iSuccess End_Procedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.