B4X
B4X
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 B4X Downloads
Dim success As Boolean = False
' 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.
Dim imap As ChilkatImap
imap.Initialize("imap")
imap.Ssl = True
imap.Port = 993
success = imap.Connect("imap.example.com")
If success = False Then
Log(imap.LastErrorText)
Return
End If
success = imap.Login("user@example.com", "myPassword")
If success = False Then
Log(imap.LastErrorText)
Return
End If
success = imap.SelectMailbox("Inbox")
If success = False Then
Log(imap.LastErrorText)
Return
End If
Dim msgSet As ChilkatMessageSet
msgSet.Initialize
success = imap.QueryMbx("ALL", True, msgSet)
If success = False Then
Log(imap.LastErrorText)
Return
End If
Dim bundle As ChilkatEmailBundle
bundle.Initialize
success = imap.FetchMsgSet(True, msgSet, bundle)
If success = False Then
Log(imap.LastErrorText)
Return
End If
Dim email As ChilkatEmail
email.Initialize
Dim i As Int
For i = 0 To bundle.MessageCount - 1
success = bundle.EmailAt(i, email)
' Check whether each message has been read (the "Seen" flag).
Dim seen As Int = imap.GetMailFlag(email, "Seen")
If seen = 1 Then
Log(email.Subject & " -- already read")
End If
ERROR: "}" expected
Next