Sample code for 30+ languages & platforms
PowerBuilder

Fetch a Set of POP3 Messages by UIDL

See more POP3 Examples

Demonstrates the Chilkat MailMan.FetchUidlSet method, which retrieves the messages whose UIDLs are listed in a StringTable and appends them to an EmailBundle. The arguments are the UIDL StringTable, headersOnly, numBodyLines, and the EmailBundle. This example fetches two specific messages by UIDL.

Background: This is the efficient way to download a selected subset of a mailbox in one call — exactly the pattern for an incremental client: list the mailbox UIDLs, compare against the ones you've already stored, and fetch only the new UIDLs as a set. It avoids re-downloading messages you already have while still pulling everything new in a single operation.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Mailman
oleobject loo_Uidls
oleobject loo_Bundle
integer n
oleobject loo_Email
integer i

li_Success = 0

//  Demonstrates the MailMan.FetchUidlSet method, which retrieves the messages whose UIDLs are
//  listed in a StringTable and appends them to an EmailBundle.  The arguments are the UIDL
//  StringTable, headersOnly, numBodyLines, and the EmailBundle.  The messages remain on the
//  server.

loo_Mailman = create oleobject
li_rc = loo_Mailman.ConnectToNewObject("Chilkat.MailMan")
if li_rc < 0 then
    destroy loo_Mailman
    MessageBox("Error","Connecting to COM object failed")
    return
end if

//  Configure the POP3 server connection.
loo_Mailman.MailHost = "pop.example.com"
loo_Mailman.MailPort = 995
loo_Mailman.PopSsl = 1
loo_Mailman.PopUsername = "user@example.com"
loo_Mailman.PopPassword = "myPassword"

//  Build the set of UIDLs to fetch.
loo_Uidls = create oleobject
li_rc = loo_Uidls.ConnectToNewObject("Chilkat.StringTable")

loo_Uidls.Append("0000000123abcdef")
loo_Uidls.Append("0000000124abcdef")

//  Fetch the listed messages (full bodies) into a bundle.
//  headersOnly=0 (fetch the entire message).
//  Note: numBodyLines only applies when headersOnly is 1 (it sets how many lines of the
//  body to include along with the headers).  When headersOnly is 0, the entire message
//  is fetched and numBodyLines is ignored.
loo_Bundle = create oleobject
li_rc = loo_Bundle.ConnectToNewObject("Chilkat.EmailBundle")

li_Success = loo_Mailman.FetchUidlSet(loo_Uidls,0,0,loo_Bundle)
if li_Success = 0 then
    Write-Debug loo_Mailman.LastErrorText
    destroy loo_Mailman
    destroy loo_Uidls
    destroy loo_Bundle
    return
end if

n = loo_Bundle.MessageCount
Write-Debug "Fetched " + string(n) + " messages."

loo_Email = create oleobject
li_rc = loo_Email.ConnectToNewObject("Chilkat.Email")

for i = 0 to n - 1
    li_Success = loo_Bundle.EmailAt(i,loo_Email)
    Write-Debug loo_Email.Subject
next

//  Note: Explicitly connecting/authenticating is optional.  Chilkat MailMan automatically
//  connects and authenticates -- using the property settings above -- whenever a server
//  operation requires it.  Calling the explicit connect/authenticate methods can still be
//  helpful to determine whether a failure occurs while connecting or while authenticating.


destroy loo_Mailman
destroy loo_Uidls
destroy loo_Bundle
destroy loo_Email