Visual FoxPro Requires Chilkat v11.0.0+
Visual FoxPro
Imap.GetMailSize vs Email.Size
Shows how to get the total size of an email, as well as the sizes of the attachments. This can be done when either full-emails or headers-only are downloaded.Chilkat Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loImap
LOCAL lnFetchUids
LOCAL loMessageSet
LOCAL loBundle
LOCAL lnHeadersOnly
LOCAL loEmail
LOCAL i
LOCAL j
LOCAL lnNumEmails
LOCAL lnNumAttach
LOCAL lnAttachSize
lnSuccess = 0
* This example assumes the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.
loImap = CreateObject('Chilkat.Imap')
* Connect to an IMAP server.
* Use TLS
loImap.Ssl = 1
loImap.Port = 993
lnSuccess = loImap.Connect("imap.example.com")
IF (lnSuccess = 0) THEN
? loImap.LastErrorText
RELEASE loImap
CANCEL
ENDIF
* Login
lnSuccess = loImap.Login("****","****")
IF (lnSuccess = 0) THEN
? loImap.LastErrorText
RELEASE loImap
CANCEL
ENDIF
* Select an IMAP mailbox
lnSuccess = loImap.SelectMailbox("Inbox")
IF (lnSuccess = 0) THEN
? loImap.LastErrorText
RELEASE loImap
CANCEL
ENDIF
* Get the message IDs of all the emails in the mailbox
* We can choose to fetch UIDs or sequence numbers.
lnFetchUids = 1
loMessageSet = CreateObject('Chilkat.MessageSet')
lnSuccess = loImap.QueryMbx("ALL",lnFetchUids,loMessageSet)
IF (lnSuccess = 0) THEN
? loImap.LastErrorText
RELEASE loImap
RELEASE loMessageSet
CANCEL
ENDIF
* When downloading headers, each email object contains
* (obviously) the headers, but the body will be missing.
* Attachments will not be included. However, it is
* possible to get information about the attachments
* as well as the complete size of the email.
loBundle = CreateObject('Chilkat.EmailBundle')
lnHeadersOnly = 1
lnSuccess = loImap.FetchMsgSet(lnHeadersOnly,loMessageSet,loBundle)
IF (lnSuccess = 0) THEN
? loImap.LastErrorText
RELEASE loImap
RELEASE loMessageSet
RELEASE loBundle
CANCEL
ENDIF
* Loop over the email objects and display information about each:
loEmail = CreateObject('Chilkat.Email')
i = 0
j = 0
lnNumEmails = loBundle.MessageCount
DO WHILE i < lnNumEmails
loBundle.EmailAt(i,loEmail)
* Display the From and Subject
? loEmail.From
? loEmail.Subject
* Display the recipients:
j = 0
DO WHILE j < loEmail.NumTo
? "TO: " + loEmail.GetToName(j) + ", " + loEmail.GetToAddr(j)
j = j + 1
ENDDO
j = 0
DO WHILE j < loEmail.NumCC
? "CC: " + loEmail.GetCcName(j) + ", " + loEmail.GetCcAddr(j)
j = j + 1
ENDDO
* Show the total size of the email, including body and attachments:
? STR(loEmail.Size)
* When a full email is downloaded, we would use the
* email.NumAttachments property in conjunction with the
* email.GetMailAttach* methods.
* However, when an email object contains only the header,
* we need to access the attachment info differently:
lnNumAttach = loImap.GetMailNumAttach(loEmail)
j = 0
DO WHILE j < lnNumAttach
? loImap.GetMailAttachFilename(loEmail,j)
lnAttachSize = loImap.GetMailAttachSize(loEmail,j)
? " size = " + STR(lnAttachSize) + " bytes"
j = j + 1
ENDDO
? "--"
i = i + 1
ENDDO
* Disconnect from the IMAP server.
lnSuccess = loImap.Disconnect()
RELEASE loImap
RELEASE loMessageSet
RELEASE loBundle
RELEASE loEmail