This VB.NET sample recursively traverses a MIME document and saves the embedded files to the filesystem.
Private Sub TraverseMime(ByVal mime As Chilkat.Mime)
If (mime.NumParts > 0) Then
Dim i As Integer
For i = 0 To mime.NumParts - 1
Dim child As Chilkat.Mime
child = mime.GetPart(i)
TraverseMime(child)
Next
Else
If (mime.Filename.Length > 0) Then
Dim success As Boolean
If (mime.ContentType.Equals("application/pdf")) Then
success = mime.SaveBody("pdfFiles/" & mime.Filename)
ElseIf (mime.ContentType.Equals("text/xml")) Then
success = mime.SaveBody("xmlFiles/" & mime.Filename)
Else
success = mime.SaveBody("otherFiles/" & mime.Filename)
End If
If (Not success) Then
MessageBox.Show(mime.LastErrorText)
End If
End If
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim mime As New Chilkat.Mime()
Dim success As Boolean
success = mime.UnlockComponent("Anything for 30-day trial")
If (success = False) Then
MsgBox("Failed to unlock component")
Exit Sub
End If
' Load a MIME document from a file:
success = mime.LoadMimeFile("testMime.txt")
If (success = False) Then
MsgBox(mime.LastErrorText)
Exit Sub
End If
TraverseMime(mime)
End Sub