DataFlex
DataFlex
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoImap
Variant vMsgSet
Handle hoMsgSet
Variant vBundle
Handle hoBundle
Variant vEmail
Handle hoEmail
Integer i
Integer iSeen
String sTemp1
Integer iTemp1
Move False To iSuccess
// 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.
Get Create (RefClass(cComChilkatImap)) To hoImap
If (Not(IsComObjectCreated(hoImap))) Begin
Send CreateComObject of hoImap
End
Set ComSsl Of hoImap To True
Set ComPort Of hoImap To 993
Get ComConnect Of hoImap "imap.example.com" To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoImap To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComLogin Of hoImap "user@example.com" "myPassword" To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoImap To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComSelectMailbox Of hoImap "Inbox" To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoImap To sTemp1
Showln sTemp1
Procedure_Return
End
Get Create (RefClass(cComChilkatMessageSet)) To hoMsgSet
If (Not(IsComObjectCreated(hoMsgSet))) Begin
Send CreateComObject of hoMsgSet
End
Get pvComObject of hoMsgSet to vMsgSet
Get ComQueryMbx Of hoImap "ALL" True vMsgSet To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoImap To sTemp1
Showln sTemp1
Procedure_Return
End
Get Create (RefClass(cComChilkatEmailBundle)) To hoBundle
If (Not(IsComObjectCreated(hoBundle))) Begin
Send CreateComObject of hoBundle
End
Get pvComObject of hoMsgSet to vMsgSet
Get pvComObject of hoBundle to vBundle
Get ComFetchMsgSet Of hoImap True vMsgSet vBundle To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoImap To sTemp1
Showln sTemp1
Procedure_Return
End
Get Create (RefClass(cComChilkatEmail)) To hoEmail
If (Not(IsComObjectCreated(hoEmail))) Begin
Send CreateComObject of hoEmail
End
Get ComMessageCount Of hoBundle To iTemp1
For i From 0 To (iTemp1 - 1)
Get pvComObject of hoEmail to vEmail
Get ComEmailAt Of hoBundle i vEmail To iSuccess
// Check whether each message has been read (the "Seen" flag).
Get pvComObject of hoEmail to vEmail
Get ComGetMailFlag Of hoImap vEmail "Seen" To iSeen
If (iSeen = 1) Begin
Get ComSubject Of hoEmail To sTemp1
Showln sTemp1 " -- already read"
End
ERROR: "}" expected
Loop
End_Procedure