PowerBuilder
PowerBuilder
Get an IMAP Flag from a Downloaded Email
See more IMAP Examples
Demonstrates the Chilkat Imap.GetMailFlag method, which returns the state of a named flag for an Email object that was downloaded from the server. The first argument is the Email and the second is the flag name. The return value is 1 if the flag is set, 0 if not, and -1 if the flag is not present. This example iterates a bundle and reports which messages are read vs unread.
Background: When Chilkat downloads a message it records the flags the server reported at fetch time, so you can inspect them locally with
GetMailFlag without another round trip. This is the client-side view: it reflects the state as of the download, not necessarily the live state on the server, which other clients could have changed. Use RefetchMailFlags to update an Email object's flags to the current server values.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Imap
oleobject loo_MsgSet
oleobject loo_Bundle
oleobject loo_Email
integer i
integer li_Seen
li_Success = 0
// Demonstrates the Imap.GetMailFlag method, which returns the state of a named flag for an
// Email object that was downloaded from the server. The 1st argument is the Email and the
// 2nd is the flag name. The return value is 1 if the flag is set, 0 if not, and -1 if the
// flag is not present.
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
loo_Bundle = create oleobject
li_rc = loo_Bundle.ConnectToNewObject("Chilkat.EmailBundle")
li_Success = loo_Imap.FetchMsgSet(1,loo_MsgSet,loo_Bundle)
if li_Success = 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
destroy loo_MsgSet
destroy loo_Bundle
return
end if
loo_Email = create oleobject
li_rc = loo_Email.ConnectToNewObject("Chilkat.Email")
for i = 0 to loo_Bundle.MessageCount - 1
li_Success = loo_Bundle.EmailAt(i,loo_Email)
// Check whether each message has been read (the "Seen" flag).
li_Seen = loo_Imap.GetMailFlag(loo_Email,"Seen")
if li_Seen = 1 then
Write-Debug loo_Email.Subject + " -- already read"
end if
ERROR: "}" expected
next
destroy loo_Imap
destroy loo_MsgSet
destroy loo_Bundle
destroy loo_Email