PowerBuilder
PowerBuilder
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 PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Imap
oleobject loo_EmailHeader
oleobject loo_EmailFull
integer li_Uid
integer li_IsUid
integer li_UidFromCkxHeader
li_Success = 0
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loo_Imap = create oleobject
li_rc = loo_Imap.ConnectToNewObject("Chilkat.Imap")
if li_rc < 0 then
destroy loo_Imap
MessageBox("Error","Connecting to COM object failed")
return
end if
// Connect to an IMAP server.
// Use TLS
loo_Imap.Ssl = 1
loo_Imap.Port = 993
li_Success = loo_Imap.Connect("imap.example.com")
if li_Success = 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
return
end if
// Login
li_Success = loo_Imap.Login("***","***")
if li_Success = 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
return
end if
// Select an IMAP mailbox
li_Success = loo_Imap.SelectMailbox("Inbox")
if li_Success = 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
return
end if
loo_EmailHeader = create oleobject
li_rc = loo_EmailHeader.ConnectToNewObject("Chilkat.Email")
loo_EmailFull = create oleobject
li_rc = loo_EmailFull.ConnectToNewObject("Chilkat.Email")
li_Uid = 2014
li_IsUid = 1
// Fetch only the email header
li_Success = loo_Imap.FetchEmail(1,li_Uid,li_IsUid,loo_EmailHeader)
if li_Success = 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
destroy loo_EmailHeader
destroy loo_EmailFull
return
end if
// Now fetch the full email
li_UidFromCkxHeader = loo_EmailHeader.GetImapUid()
if li_UidFromCkxHeader < 0 then
// Failed.
Write-Debug "No ckx-imap-uid header was found."
destroy loo_Imap
destroy loo_EmailHeader
destroy loo_EmailFull
return
end if
li_Success = loo_Imap.FetchEmail(0,li_Uid,li_IsUid,loo_EmailFull)
if li_Success = 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
destroy loo_EmailHeader
destroy loo_EmailFull
return
end if
// OK, we have the full email, do whatever we want...
// Disconnect from the IMAP server.
li_Success = loo_Imap.Disconnect()
destroy loo_Imap
destroy loo_EmailHeader
destroy loo_EmailFull