I have attached a raw email message encoded Base64. I would like to extract the message body, and then decode it to utf-8. There don't seem to be any tags to identify the beginning and end of the body, so I'm at a loss as to how to do this. The code below is for a Sub I have created to decode Base64, but it does not deal with extracting the body. Is there a way of doing this? Any help gretly appreciated.
Best regards
B4X:
Sub Base64Decode(MyString As String) As String
If Regex.Matcher2("^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$", _
Regex.CASE_INSENSITIVE, MyString).Find = True Then
'Log("Base64Text")
Try
Dim su As StringUtils
Dim Data() As Byte = su.DecodeBase64(MyString)
MyString = BytesToString(Data, 0, Data.Length, "UTF8")
Catch
Log("LastException: " & LastException)
End Try
End If
Return MyString
End Sub
Thank you DonManfred. Yes, I know the boundaries are there, but the MailParser doesn't recognize them. When parsed this message comes through as a 0 byte file. In an earlier post Erel has stated that the MailParser is specifically not compatible with multipart/alternative, so the result is not unexpected. I am trying to find a way to display this type of message in a WebView by extracting the text part for the body by some other means, and then decoding it. I haven't even thought of trying to decode the html. Do you have any other thoughts?
I've just tested MailParser with the mail you posted and it parses this email successfully.
It treats each part as an attachment:
B4X:
Dim m As Message = MailParser.ParseMail(File.ReadString(File.DirAssets, "RawMailLibrary.txt"), File.DirInternal)
For Each s As String In m.Attachments
Log(File.ReadString(File.DirInternal, s))
Next