PowerBuilder
PowerBuilder
Remove a Part from a Multipart MIME Entity
See more MIME Examples
Demonstrates the Chilkat Mime.RemovePart method, which removes the direct child at a zero-based index. The only argument is the index; valid values are 0 through NumParts - 1. An out-of-range index returns false and changes nothing.
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: Removing a part is how you strip an attachment or drop an unwanted alternative when reprocessing a message. Because parts are addressed by position, be mindful that removing one shifts the indexes of those after it — when deleting several, iterate from the last index downward so earlier removals do not renumber the parts you still intend to remove.
Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Mime
integer li_LastIndex
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/multipart_message.eml")
if li_Success = 0 then
Write-Debug loo_Mime.LastErrorText
destroy loo_Mime
return
end if
// Remove the direct child part at a zero-based index. Valid indexes are 0 through NumParts - 1.
// Here the last part is removed.
li_LastIndex = loo_Mime.NumParts - 1
li_Success = loo_Mime.RemovePart(li_LastIndex)
if li_Success = 0 then
Write-Debug loo_Mime.LastErrorText
destroy loo_Mime
return
end if
Write-Debug "Parts remaining: " + string(loo_Mime.NumParts)
destroy loo_Mime