PowerBuilder
PowerBuilder
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 PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Imap
integer li_HeadersOnly
integer li_UseUid
integer li_SeqNum
oleobject loo_Email
integer li_NumAttach
integer i
string ls_Fname
integer li_Sz
li_Success = 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.
loo_Imap = create oleobject
li_rc = loo_Imap.ConnectToNewObject("Chilkat.Imap")
if li_rc < 0 then
destroy loo_Imap
MessageBox("Error","Connecting to COM object failed")
return
end if
loo_Imap.Ssl = 1
loo_Imap.Port = 993
li_Success = loo_Imap.Connect("imap.example.com")
if li_Success = 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
return
end if
li_Success = loo_Imap.Login("user@example.com","myPassword")
if li_Success = 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
return
end if
li_Success = loo_Imap.SelectMailbox("Inbox")
if li_Success = 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
return
end if
// 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.
li_HeadersOnly = 1
li_UseUid = 0
li_SeqNum = 1
loo_Email = create oleobject
li_rc = loo_Email.ConnectToNewObject("Chilkat.Email")
li_Success = loo_Imap.FetchEmail(li_HeadersOnly,li_SeqNum,li_UseUid,loo_Email)
if li_Success = 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
destroy loo_Email
return
end if
li_NumAttach = loo_Imap.GetMailNumAttach(loo_Email)
for i = 0 to li_NumAttach - 1
ls_Fname = loo_Imap.GetMailAttachFilename(loo_Email,i)
if loo_Imap.LastMethodSuccess = 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
destroy loo_Email
return
end if
li_Sz = loo_Imap.GetMailAttachSize(loo_Email,i)
Write-Debug ls_Fname + ": " + string(li_Sz) + " bytes"
next
li_Success = loo_Imap.Disconnect()
if li_Success = 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
destroy loo_Email
return
end if
destroy loo_Imap
destroy loo_Email