Sub HandlePart(Headers As String, Body As String, Msg As Message)
If Regex.Matcher2("Content-Transfer-Encoding:\s*base64", _
Regex.CASE_INSENSITIVE, Headers).Find Then
'we are dealing with an attachment
Dim filename As String
Dim m As Matcher
m = Regex.Matcher2("filename=\s*q([^q]+)q".Replace("q", QUOTE), Regex.CASE_INSENSITIVE, Headers)
If m.Find Then filename = m.Group(1) Else filename = "attachment" & (Msg.Attachments.Size + 1)
Dim su As StringUtils
Dim out As OutputStream
out = File.OpenOutput(dir, filename, False)
Dim data() As Byte
data = su.DecodeBase64(Body)
Log("file saved: " & filename & " (" & data.Length & " bytes)")
out.WriteBytes(data, 0, data.Length)
out.Close
Msg.Attachments.Add(filename)
Else If Regex.Matcher2("Content-Type:\s*text/", _
Regex.CASE_INSENSITIVE, Headers).Find Then
Msg.Body = Body
End If
End Sub