Sample code for 30+ languages & platforms
PowerBuilder

Access a Part in a Multipart MIME Entity

See more MIME Examples

Demonstrates the Chilkat Mime.PartAt method, which provides live access to the direct child at a zero-based index. The first argument is the index and the second is a Mime object that will reference the child. Modifying it modifies the child stored in the parent tree.

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 reach into a multipart message to inspect or edit an individual part — read a part's Content-Type, extract an attachment's body, or change a part in place. The key point is that the returned Mime is a live reference, not a copy, so edits to it flow back into the parent tree. Loop from 0 to NumParts - 1 to visit every direct child.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Mime
integer n
oleobject loo_Part
integer i

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

//  PartAt provides LIVE access to a direct child part.  The 1st argument is the zero-based index
//  and the 2nd is a Mime object that will reference the child.  Modifying it modifies the child in
//  the parent tree.
n = loo_Mime.NumParts
Write-Debug "Number of parts: " + string(n)

loo_Part = create oleobject
li_rc = loo_Part.ConnectToNewObject("Chilkat.Mime")

for i = 0 to n - 1
    li_Success = loo_Mime.PartAt(i,loo_Part)
    if li_Success = 0 then
        Write-Debug loo_Mime.LastErrorText
        destroy loo_Mime
        destroy loo_Part
        return
    end if

    Write-Debug "Part " + string(i) + " Content-Type: " + loo_Part.ContentType
next


destroy loo_Mime
destroy loo_Part