Sample code for 30+ languages & platforms
Visual FoxPro

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 Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loImap
LOCAL loMsgSet
LOCAL loBundle
LOCAL loEmail
LOCAL i
LOCAL lnSeen

lnSuccess = 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.

loImap = CreateObject('Chilkat.Imap')

loImap.Ssl = 1
loImap.Port = 993

lnSuccess = loImap.Connect("imap.example.com")
IF (lnSuccess = 0) THEN
    ? loImap.LastErrorText
    RELEASE loImap
    CANCEL
ENDIF

lnSuccess = loImap.Login("user@example.com","myPassword")
IF (lnSuccess = 0) THEN
    ? loImap.LastErrorText
    RELEASE loImap
    CANCEL
ENDIF

lnSuccess = loImap.SelectMailbox("Inbox")
IF (lnSuccess = 0) THEN
    ? loImap.LastErrorText
    RELEASE loImap
    CANCEL
ENDIF

loMsgSet = CreateObject('Chilkat.MessageSet')
lnSuccess = loImap.QueryMbx("ALL",1,loMsgSet)
IF (lnSuccess = 0) THEN
    ? loImap.LastErrorText
    RELEASE loImap
    RELEASE loMsgSet
    CANCEL
ENDIF

loBundle = CreateObject('Chilkat.EmailBundle')
lnSuccess = loImap.FetchMsgSet(1,loMsgSet,loBundle)
IF (lnSuccess = 0) THEN
    ? loImap.LastErrorText
    RELEASE loImap
    RELEASE loMsgSet
    RELEASE loBundle
    CANCEL
ENDIF

loEmail = CreateObject('Chilkat.Email')

FOR i = 0 TO loBundle.MessageCount - 1
    lnSuccess = loBundle.EmailAt(i,loEmail)
    *  Check whether each message has been read (the "Seen" flag).
    lnSeen = loImap.GetMailFlag(loEmail,"Seen")
    IF (lnSeen = 1) THEN
        ? loEmail.Subject + " -- already read"
    ENDIF

ERROR: "}" expected
NEXT

RELEASE loImap
RELEASE loMsgSet
RELEASE loBundle
RELEASE loEmail