Sub POP_DownloadCompleted (Success As Boolean, MessageId As Int, MessageText As String)
If Success = False Then
Log(LastException.Message)
Log("ff")
Else
Log(MessageId)
'Parse the mail
Dim m As Message
m = MailParser.ParseMail(MessageText, File.DirRootExternal)
'extract information
subject=m.Subject
body=m.Body
Log(DecodeQuotePrintable(body))
body=DecodeQuotePrintable(body)
date=m.ContentType
'save the data in txt file
sql2.ExecNonQuery2("INSERT INTO table1 VALUES(?, ?, ?)", Array As Object(subject, body, body))
Log(body)
End If
End Sub
Sub DecodeQuotePrintable(q As String) As String
Dim m As Matcher
m = Regex.Matcher("=\?([^?]*)\?Q\?(.*)\?=$", q)
If m.Find Then
Dim charset As String
Dim data As String
charset = m.Group(1)
data = m.Group(2)
Dim bytes As List
bytes.Initialize
Dim i As Int
Do While i < data.Length
Dim c As String
c = data.CharAt(i)
If c = "_" Then
bytes.AddAll(" ".GetBytes(charset))
Else If c = "=" Then
Dim hex As String
hex = data.CharAt(i + 1) & data.CharAt(i + 2)
i = i + 2
bytes.Add(Bit.ParseInt(hex, 16))
Else
bytes.AddAll(c.GetBytes(charset))
End If
i = i + 1
Loop
Dim b(bytes.Size) As Byte
For i = 0 To bytes.Size - 1
b(i) = bytes.Get(i)
Next
Return BytesToString(b, 0, b.Length, charset)
Else
Return q
End If
End Sub