Sample code for 30+ languages & platforms
Tcl

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 Tcl Downloads

Tcl

load ./chilkat.dll

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

set imap [new_CkImap]

CkImap_put_Ssl $imap 1
CkImap_put_Port $imap 993

set success [CkImap_Connect $imap "imap.example.com"]
if {$success == 0} then {
    puts [CkImap_lastErrorText $imap]
    delete_CkImap $imap
    exit
}

set success [CkImap_Login $imap "user@example.com" "myPassword"]
if {$success == 0} then {
    puts [CkImap_lastErrorText $imap]
    delete_CkImap $imap
    exit
}

set success [CkImap_SelectMailbox $imap "Inbox"]
if {$success == 0} then {
    puts [CkImap_lastErrorText $imap]
    delete_CkImap $imap
    exit
}

set msgSet [new_CkMessageSet]

set success [CkImap_QueryMbx $imap "ALL" 1 $msgSet]
if {$success == 0} then {
    puts [CkImap_lastErrorText $imap]
    delete_CkImap $imap
    delete_CkMessageSet $msgSet
    exit
}

if {[CkMessageSet_get_Count $msgSet] > 0} then {
    set uid [CkMessageSet_GetId $msgSet 0]
    #  FetchFlags returns a string, so assign it to a string variable and check for success.
    set flags [CkImap_fetchFlags $imap $uid 1]
    if {[CkImap_get_LastMethodSuccess $imap] == 0} then {
        puts [CkImap_lastErrorText $imap]
        delete_CkImap $imap
        delete_CkMessageSet $msgSet
        exit
    }

    puts "UID $uid flags: $flags"
}

set success [CkImap_Disconnect $imap]
if {$success == 0} then {
    puts [CkImap_lastErrorText $imap]
    delete_CkImap $imap
    delete_CkMessageSet $msgSet
    exit
}


delete_CkImap $imap
delete_CkMessageSet $msgSet