Visual Basic 6.0
Visual Basic 6.0
Fetch a Single Message's MIME into a StringBuilder
See more IMAP Examples
Demonstrates the Chilkat Imap.FetchSingleAsMimeSb method, which downloads one message's MIME into a StringBuilder. The first argument is the message id, the second (bUid) selects UID vs sequence number, and the third is the StringBuilder, which is cleared first. This example downloads a message by UID and prints the MIME length.
Background: Chilkat interprets the received MIME as UTF-8. Messages using Base64 or quoted-printable transfer encoding are safe because their encoded bytes are ASCII. Raw
8bit or binary content, or unencoded text in a charset such as ISO-8859-1 or Shift_JIS, can be misinterpreted — in those cases use FetchSingleBd to get the exact bytes.Chilkat Visual Basic 6.0 Downloads
Dim success As Long
success = 0
' Demonstrates the Imap.FetchSingleAsMimeSb method, which downloads one message's MIME into a
' StringBuilder. The 1st argument is the message id, the 2nd (bUid) selects UID vs sequence
' number, and the 3rd is the StringBuilder (cleared first).
Dim imap As New ChilkatImap
imap.Ssl = 1
imap.Port = 993
success = imap.Connect("imap.example.com")
If (success = 0) Then
Debug.Print imap.LastErrorText
Exit Sub
End If
success = imap.Login("user@example.com","myPassword")
If (success = 0) Then
Debug.Print imap.LastErrorText
Exit Sub
End If
success = imap.SelectMailbox("Inbox")
If (success = 0) Then
Debug.Print imap.LastErrorText
Exit Sub
End If
' Search for the message ids to download, returning UIDs.
Dim wantUids As Long
wantUids = 1
Dim msgSet As New MessageSet
success = imap.QueryMbx("ALL",wantUids,msgSet)
If (success = 0) Then
Debug.Print imap.LastErrorText
Exit Sub
End If
If (msgSet.Count > 0) Then
Dim uid As Long
uid = msgSet.GetId(0)
' Download the message's MIME into a StringBuilder. The id is a UID.
Dim useUid As Long
useUid = 1
Dim sbMime As New ChilkatStringBuilder
success = imap.FetchSingleAsMimeSb(uid,useUid,sbMime)
If (success = 0) Then
Debug.Print imap.LastErrorText
Exit Sub
End If
Debug.Print "MIME length: " & sbMime.Length & " chars"
End If
success = imap.Disconnect()
If (success = 0) Then
Debug.Print imap.LastErrorText
Exit Sub
End If