Visual FoxPro
Visual FoxPro
Get IMAP Attachment Sizes
See more IMAP Examples
Demonstrates the Chilkat Imap.GetMailAttachSize method, which returns the size in bytes of an attachment. The first argument is the Email and the second is the zero-based attachment index. This example fetches headers only and prints each attachment's name and size.
Background: Like the attachment filename, the size comes from
ckx-imap-* metadata and is available from a header-only fetch without downloading the body. A client can therefore show attachment sizes in a message preview, and decide whether to auto-download or prompt before pulling a large file.Chilkat Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loImap
LOCAL lnHeadersOnly
LOCAL lnUseUid
LOCAL lnSeqNum
LOCAL loEmail
LOCAL lnNumAttach
LOCAL i
LOCAL lcFname
LOCAL lnSz
lnSuccess = 0
* Demonstrates the Imap.GetMailAttachSize method, which returns the size in bytes of an
* attachment. The 1st argument is the Email and the 2nd is the zero-based attachment index.
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)
FOR i = 0 TO lnNumAttach - 1
lcFname = loImap.GetMailAttachFilename(loEmail,i)
IF (loImap.LastMethodSuccess = 0) THEN
? loImap.LastErrorText
RELEASE loImap
RELEASE loEmail
CANCEL
ENDIF
lnSz = loImap.GetMailAttachSize(loEmail,i)
? lcFname + ": " + STR(lnSz) + " bytes"
NEXT
lnSuccess = loImap.Disconnect()
IF (lnSuccess = 0) THEN
? loImap.LastErrorText
RELEASE loImap
RELEASE loEmail
CANCEL
ENDIF
RELEASE loImap
RELEASE loEmail