PowerBuilder
PowerBuilder
Set a MIME Body from Transfer-Encoded Text
See more MIME Examples
Demonstrates the Chilkat Mime.SetBodyFromEncoded method, which sets the body from already transfer-encoded text. The first argument is the encoding (base64 or quoted-printable) and the second is the encoded text.
Background: Sometimes you already hold content in its encoded form — a Base64 string from a database or another API — and re-decoding just to have Chilkat re-encode it is wasteful. This method stores the encoded text as-is and records the matching transfer encoding, so the body is correct without a needless round trip. Only the standard reversible encodings, Base64 and quoted-printable, are accepted.
Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Mime
string ls_Base64Body
string ls_Decoded
li_Success = 0
// Demonstrates the Mime.SetBodyFromEncoded method, which sets the body from already transfer-
// encoded text. The 1st argument is the encoding ("base64" or "quoted-printable") and the 2nd is
// the encoded text.
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
loo_Mime.ContentType = "text/plain"
// The body is provided already Base64-encoded; Chilkat stores it without re-encoding.
ls_Base64Body = "SGVsbG8sIHRoaXMgaXMgdGhlIGJvZHku"
li_Success = loo_Mime.SetBodyFromEncoded("base64",ls_Base64Body)
if li_Success = 0 then
Write-Debug loo_Mime.LastErrorText
destroy loo_Mime
return
end if
// The decoded body is the original text.
ls_Decoded = loo_Mime.GetBodyDecoded()
if loo_Mime.LastMethodSuccess = 0 then
Write-Debug loo_Mime.LastErrorText
destroy loo_Mime
return
end if
Write-Debug ls_Decoded
destroy loo_Mime