Sample code for 30+ languages & platforms
PowerBuilder

Store One or More Flags on a Single Message

See more IMAP Examples

Demonstrates the Chilkat Imap.StoreFlags method, which sets or clears one or more flags on a single message identified by ID. The first argument is the message ID, the second (bUid) selects UID vs sequence number, the third is a space-separated list of flag names, and the fourth is the value (1 to set, 0 to clear). This example applies the Seen and Flagged flags to one message by UID.

Background: StoreFlags is the single-message counterpart to SetFlags and lets you change several flags at once by listing them space-separated (without leading backslashes). Because the ID can be either a UID or a sequence number, the bUid argument must match how you obtained it — a UID from a UID search, or a sequence number from a sequence-based operation. UIDs are the safer choice since they remain valid as the mailbox changes.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Imap
oleobject loo_MsgSet
integer li_Uid

li_Success = 0

//  Demonstrates the Imap.StoreFlags method, which sets or clears one or more flags on a single
//  message identified by ID.  The 1st argument is the message ID, the 2nd (bUid) selects UID
//  vs sequence number, the 3rd is a space-separated list of flag names, and the 4th is the
//  value (1 to set, 0 to clear).

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

//  Get the UIDs of all messages.
loo_MsgSet = create oleobject
li_rc = loo_MsgSet.ConnectToNewObject("Chilkat.MessageSet")

li_Success = loo_Imap.QueryMbx("ALL",1,loo_MsgSet)
if li_Success = 0 then
    Write-Debug loo_Imap.LastErrorText
    destroy loo_Imap
    destroy loo_MsgSet
    return
end if

if loo_MsgSet.Count > 0 then
    //  Apply the Seen and Flagged flags to the first message.  bUid is 1 because the ID
    //  came from a UID search.
    li_Uid = loo_MsgSet.GetId(0)
    li_Success = loo_Imap.StoreFlags(li_Uid,1,"Seen Flagged",1)
    if li_Success = 0 then
        Write-Debug loo_Imap.LastErrorText
        destroy loo_Imap
        destroy loo_MsgSet
        return
    end if

    Write-Debug "Updated flags on UID " + string(li_Uid)
end if

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



destroy loo_Imap
destroy loo_MsgSet