Sample code for 30+ languages & platforms
PowerBuilder

Get the Decoded MIME Body Bytes (BinData)

See more MIME Examples

Demonstrates the Chilkat Mime.GetBodyBd method, which replaces the contents of a BinData with the decoded body bytes of the current part. The only argument is the BinData. Base64 and quoted-printable are decoded; headers and boundaries are not included.

Note: The file paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths appropriate to your own environment.

Background: This is how you extract a part's actual content as bytes — the decoded payload of an attachment or an image, ready to hash, re-save, or hand to another API. Because it works in raw bytes it is the correct choice for binary parts, where a text decode would be wrong. Note it replaces the BinData contents rather than appending.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Mime
oleobject loo_Bd

li_Success = 0

loo_Mime = create oleobject
li_rc = loo_Mime.ConnectToNewObject("Chilkat.Mime")
if li_rc < 0 then
    destroy loo_Mime
    MessageBox("Error","Connecting to COM object failed")
    return
end if
li_Success = loo_Mime.LoadMimeFile("qa_data/message.eml")
if li_Success = 0 then
    Write-Debug loo_Mime.LastErrorText
    destroy loo_Mime
    return
end if

//  Replace the contents of a BinData with the decoded body bytes of the current part.  Base64 and
//  quoted-printable are decoded; MIME headers and multipart boundaries are not included.
loo_Bd = create oleobject
li_rc = loo_Bd.ConnectToNewObject("Chilkat.BinData")

li_Success = loo_Mime.GetBodyBd(loo_Bd)
if li_Success = 0 then
    Write-Debug loo_Mime.LastErrorText
    destroy loo_Mime
    destroy loo_Bd
    return
end if

Write-Debug "Decoded body: " + string(loo_Bd.NumBytes) + " bytes."


destroy loo_Mime
destroy loo_Bd