Sample code for 30+ languages & platforms
Visual FoxPro

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-generated ckx-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 Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loImap
LOCAL loEmailHeader
LOCAL loEmailFull
LOCAL lnUid
LOCAL lnIsUid
LOCAL lnUidFromCkxHeader

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.example.com")
IF (lnSuccess = 0) THEN
    ? loImap.LastErrorText
    RELEASE loImap
    CANCEL
ENDIF

* Login
lnSuccess = loImap.Login("***","***")
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

loEmailHeader = CreateObject('Chilkat.Email')
loEmailFull = CreateObject('Chilkat.Email')

lnUid = 2014
lnIsUid = 1

* Fetch only the email header
lnSuccess = loImap.FetchEmail(1,lnUid,lnIsUid,loEmailHeader)
IF (lnSuccess = 0) THEN
    ? loImap.LastErrorText
    RELEASE loImap
    RELEASE loEmailHeader
    RELEASE loEmailFull
    CANCEL
ENDIF

* Now fetch the full email
lnUidFromCkxHeader = loEmailHeader.GetImapUid()
IF (lnUidFromCkxHeader < 0) THEN
    * Failed. 
    ? "No ckx-imap-uid header was found."
    RELEASE loImap
    RELEASE loEmailHeader
    RELEASE loEmailFull
    CANCEL
ENDIF

lnSuccess = loImap.FetchEmail(0,lnUid,lnIsUid,loEmailFull)
IF (lnSuccess = 0) THEN
    ? loImap.LastErrorText
    RELEASE loImap
    RELEASE loEmailHeader
    RELEASE loEmailFull
    CANCEL
ENDIF

* OK, we have the full email, do whatever we want...

* Disconnect from the IMAP server.
lnSuccess = loImap.Disconnect()

RELEASE loImap
RELEASE loEmailHeader
RELEASE loEmailFull