PowerBuilder
PowerBuilder
Fetch an IMAP Message's MIME into a BinData
See more IMAP Examples
Demonstrates the Chilkat Imap.FetchSingleBd method, which downloads one message's MIME bytes into a BinData object. If the second argument (bUid) is true, the first argument is a UID; otherwise it is a sequence number. This example downloads message 1's MIME into a BinData and prints the byte count.
Background: This is the binary counterpart to
FetchSingleAsMime (which returns a string). A BinData holds raw bytes, so it preserves the message exactly — the right choice when you plan to write the MIME straight to a file, hash it, or hand it to an API expecting a byte buffer, with no charset conversion that could alter binary content.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Imap
oleobject loo_BdMime
li_Success = 0
// Demonstrates the Imap.FetchSingleBd method, which downloads one message's MIME bytes into a
// BinData object. If the 2nd argument (bUid) is 1, the 1st argument is a UID; otherwise
// it is a sequence number.
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
// Download message sequence number 1's MIME bytes into a BinData. bUid = 0.
loo_BdMime = create oleobject
li_rc = loo_BdMime.ConnectToNewObject("Chilkat.BinData")
li_Success = loo_Imap.FetchSingleBd(1,0,loo_BdMime)
if li_Success = 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
destroy loo_BdMime
return
end if
Write-Debug "MIME size (bytes) = " + string(loo_BdMime.NumBytes)
li_Success = loo_Imap.Disconnect()
if li_Success = 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
destroy loo_BdMime
return
end if
destroy loo_Imap
destroy loo_BdMime