Sub ParseMultipartBody (Mail As String, Msg As Message)
'find first boundary
index = Mail.IndexOf2("--" & boundary, index)
ReadNextLine(Mail)
Dim headers As StringBuilder
headers.Initialize
Do While index < Mail.Length
Dim line As String
line = ReadNextLine(Mail)
If line.Length > 0 Then
headers.Append(line).Append(" ")
Else If index < Mail.Length Then
Dim nextPart As Int
nextPart = Mail.IndexOf2("--" & boundary, index)
If nextPart-1 > index Then
HandlePart(headers.ToString, Mail.SubString2(index, nextPart-1), Msg)
Else If nextPart = -1 Then
HandlePart(headers.ToString, Mail.SubString2(index, Mail.Length), Msg)
End If
If nextPart = -1 Then Return
index = nextPart
ReadNextLine(Mail)
headers.Initialize
End If
Loop
End Sub