Sample code for 30+ languages & platforms
PowerBuilder

Fetch Only an IMAP Message's Headers

See more IMAP Examples

Demonstrates the Chilkat Imap.FetchSingleHeaderAsMime method, which downloads and returns the MIME header block for one message, without downloading the body. If the second argument (bUID) is true, the first argument is a UID; otherwise it is a sequence number. This example fetches message 1's headers.

Background: Headers are tiny compared to a full message with attachments, so fetching just the header block is the fast, bandwidth-friendly way to build a message list — sender, subject, date — without pulling every body. It is also gentler on read state: retrieving only headers does not mark a message as seen. Download the full message later, on demand, when the user opens it.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Imap
string ls_Headers

li_Success = 0

//  Demonstrates the Imap.FetchSingleHeaderAsMime method, which downloads and returns the MIME
//  header block for one message, without downloading the body.  If the 2nd argument (bUID)
//  is 1, the 1st argument is a UID; otherwise it is a sequence number.

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

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

li_Success = loo_Imap.Login("user@example.com","myPassword")
if li_Success = 0 then
    Write-Debug loo_Imap.LastErrorText
    destroy loo_Imap
    return
end if

li_Success = loo_Imap.SelectMailbox("Inbox")
if li_Success = 0 then
    Write-Debug loo_Imap.LastErrorText
    destroy loo_Imap
    return
end if

//  Download only the MIME header block of message sequence number 1.  bUID = 0.
ls_Headers = loo_Imap.FetchSingleHeaderAsMime(1,0)
if loo_Imap.LastMethodSuccess = 0 then
    Write-Debug loo_Imap.LastErrorText
    destroy loo_Imap
    return
end if

Write-Debug ls_Headers

li_Success = loo_Imap.Disconnect()
if li_Success = 0 then
    Write-Debug loo_Imap.LastErrorText
    destroy loo_Imap
    return
end if



destroy loo_Imap