Visual FoxPro
Visual FoxPro
Get the Number of IMAP Attachments
See more IMAP Examples
Demonstrates the Chilkat Imap.GetMailNumAttach method, which returns the number of ordinary attachments on a message. The only argument is the Email. This example fetches only the headers and reports the attachment count.
Background: A header-only fetch downloads no attachment bodies, so the
Email object's own downloaded-attachment count can be 0. GetMailNumAttach instead reads the ckx-imap-numAttach metadata, giving the true count — which is what you want when building a message list that shows whether each message has attachments.Chilkat Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loImap
LOCAL lnHeadersOnly
LOCAL lnUseUid
LOCAL lnSeqNum
LOCAL loEmail
LOCAL lnNumAttach
lnSuccess = 0
* Demonstrates the Imap.GetMailNumAttach method, which returns the number of ordinary
* attachments on a message. The only argument is the Email.
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
* Fetch only the message headers. Attachment bodies are NOT downloaded, but the ckx-imap-*
* metadata describing the attachments is present, so the attachment info methods still work.
lnHeadersOnly = 1
lnUseUid = 0
lnSeqNum = 1
loEmail = CreateObject('Chilkat.Email')
lnSuccess = loImap.FetchEmail(lnHeadersOnly,lnSeqNum,lnUseUid,loEmail)
IF (lnSuccess = 0) THEN
? loImap.LastErrorText
RELEASE loImap
RELEASE loEmail
CANCEL
ENDIF
lnNumAttach = loImap.GetMailNumAttach(loEmail)
? "This message has " + STR(lnNumAttach) + " attachment(s)."
lnSuccess = loImap.Disconnect()
IF (lnSuccess = 0) THEN
? loImap.LastErrorText
RELEASE loImap
RELEASE loEmail
CANCEL
ENDIF
RELEASE loImap
RELEASE loEmail