Xbase++ Requires Chilkat v11.0.0+
Xbase++
Fetch Full Email Given Email Header
When you fetch email headers using UIDs instead of sequence numbers, the email object (which includes only the header) will have auto-generatedckx-imap-* headers. These headers provide details like the UID and attachments. The IMAP UID is found in the ckx-imap-uid header. Additionally, the ckx-imap-isUid header indicates whether the email header was downloaded by UID, showing YES or NO. Since sequence numbers can change if emails are deleted, UIDs are essential for downloading the correct full email.
The Chilkat Email object offers a GetImapUid method to retrieve the UID from the ckx-imap-uid header. This UID can be used to fetch the full email.
Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oImap
LOCAL oEmailHeader
LOCAL oEmailFull
LOCAL nUid
LOCAL nIsUid
LOCAL nUidFromCkxHeader
nSuccess := 0
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oImap := CreateObject("Chilkat.Imap")
// Connect to an IMAP server.
// Use TLS
oImap:Ssl := 1
oImap:Port := 993
nSuccess := oImap:Connect("imap.example.com")
IF (nSuccess == 0)
? oImap:LastErrorText
oImap:destroy()
RETURN
ENDIF
// Login
nSuccess := oImap:Login("***", "***")
IF (nSuccess == 0)
? oImap:LastErrorText
oImap:destroy()
RETURN
ENDIF
// Select an IMAP mailbox
nSuccess := oImap:SelectMailbox("Inbox")
IF (nSuccess == 0)
? oImap:LastErrorText
oImap:destroy()
RETURN
ENDIF
oEmailHeader := CreateObject("Chilkat.Email")
oEmailFull := CreateObject("Chilkat.Email")
nUid := 2014
nIsUid := 1
// Fetch only the email header
nSuccess := oImap:FetchEmail(1, nUid, nIsUid, oEmailHeader)
IF (nSuccess == 0)
? oImap:LastErrorText
oImap:destroy()
oEmailHeader:destroy()
oEmailFull:destroy()
RETURN
ENDIF
// Now fetch the full email
nUidFromCkxHeader := oEmailHeader:GetImapUid()
IF (nUidFromCkxHeader < 0)
// Failed.
? "No ckx-imap-uid header was found."
oImap:destroy()
oEmailHeader:destroy()
oEmailFull:destroy()
RETURN
ENDIF
nSuccess := oImap:FetchEmail(0, nUid, nIsUid, oEmailFull)
IF (nSuccess == 0)
? oImap:LastErrorText
oImap:destroy()
oEmailHeader:destroy()
oEmailFull:destroy()
RETURN
ENDIF
// OK, we have the full email, do whatever we want...
// Disconnect from the IMAP server.
nSuccess := oImap:Disconnect()
oImap:destroy()
oEmailHeader:destroy()
oEmailFull:destroy()