PowerBuilder
PowerBuilder
Set a MIME Body, Preserving Content Headers
See more MIME Examples
Demonstrates the Chilkat Mime.SetBody method, which sets the current part's body while preserving the existing content headers (Content-Type, charset, Content-Transfer-Encoding). The only argument is the body text; it is a void method.
Background: Unlike the
SetBodyFrom... methods, which set both the content and the headers that describe it, SetBody replaces only the body text and leaves the existing Content-Type and encoding in place. That is what you want when the media type is already correct and you simply need to swap in new content — updating a templated part, for instance — without re-declaring its type.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Mime
string ls_MimeText
li_Success = 0
// Demonstrates the Mime.SetBody method, which sets the current part's body while preserving the
// existing content headers (Content-Type, charset, Content-Transfer-Encoding). The only argument
// is the body text. It is a void method.
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
// Establish the content headers first.
li_Success = loo_Mime.SetBodyFromPlainText("initial")
if li_Success = 0 then
Write-Debug loo_Mime.LastErrorText
destroy loo_Mime
return
end if
// Replace just the body text, keeping the existing Content-Type and encoding.
loo_Mime.SetBody("This is the replacement body text.")
ls_MimeText = loo_Mime.GetMime()
if loo_Mime.LastMethodSuccess = 0 then
Write-Debug loo_Mime.LastErrorText
destroy loo_Mime
return
end if
Write-Debug ls_MimeText
destroy loo_Mime