Sample code for 30+ languages & platforms
Xojo Plugin

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 Xojo Plugin Downloads

Xojo Plugin
Dim success As Boolean
success = False

//  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.

Dim imap As New Chilkat.Imap

imap.Ssl = True
imap.Port = 993

success = imap.Connect("imap.example.com")
If (success = False) Then
    System.DebugLog(imap.LastErrorText)
    Return
End If

success = imap.Login("user@example.com","myPassword")
If (success = False) Then
    System.DebugLog(imap.LastErrorText)
    Return
End If

success = imap.SelectMailbox("Inbox")
If (success = False) Then
    System.DebugLog(imap.LastErrorText)
    Return
End If

Dim msgSet As New Chilkat.MessageSet
success = imap.QueryMbx("ALL",True,msgSet)
If (success = False) Then
    System.DebugLog(imap.LastErrorText)
    Return
End If

If (msgSet.Count > 0) Then
    Dim uid As UInt32
    uid = msgSet.GetId(0)
    //  FetchFlags returns a string, so assign it to a string variable and check for success.
    Dim flags As String
    flags = imap.FetchFlags(uid,True)
    If (imap.LastMethodSuccess = False) Then
        System.DebugLog(imap.LastErrorText)
        Return
    End If

    System.DebugLog("UID " + Str(uid) + " flags: " + flags)
End If

success = imap.Disconnect()
If (success = False) Then
    System.DebugLog(imap.LastErrorText)
    Return
End If