PowerBuilder
PowerBuilder
Fetch the Flags Set on an IMAP Message
See more IMAP Examples
Demonstrates the Chilkat Imap.FetchFlags method, which returns the flags currently set on a single message as a space-separated string. The first argument is the message ID and the second (bUid) selects UID vs sequence number. This example fetches and prints the flags for one message identified by UID.
Background: The returned string is the server's current flag list for the message, such as
\Seen \Flagged. This is a quick way to check a single message's state — for example, to decide whether it still needs processing — without downloading the message itself. To read the same information from a message you already have as an Email object, use GetMailFlag instead.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Imap
oleobject loo_MsgSet
integer li_Uid
string ls_Flags
li_Success = 0
// Demonstrates the Imap.FetchFlags method, which returns the flags currently set on a single
// message as a space-separated string. The 1st argument is the message ID and the 2nd (bUid)
// selects UID vs 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
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
li_Uid = loo_MsgSet.GetId(0)
// FetchFlags returns a string, so assign it to a string variable and check for success.
ls_Flags = loo_Imap.FetchFlags(li_Uid,1)
if loo_Imap.LastMethodSuccess = 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
destroy loo_MsgSet
return
end if
Write-Debug "UID " + string(li_Uid) + " flags: " + ls_Flags
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