AutoIt
AutoIt
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 AutoIt Downloads
Local $bSuccess = False
; 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).
$oImap = ObjCreate("Chilkat.Imap")
$oImap.Ssl = True
$oImap.Port = 993
$bSuccess = $oImap.Connect("imap.example.com")
If ($bSuccess = False) Then
ConsoleWrite($oImap.LastErrorText & @CRLF)
Exit
EndIf
$bSuccess = $oImap.Login("user@example.com","myPassword")
If ($bSuccess = False) Then
ConsoleWrite($oImap.LastErrorText & @CRLF)
Exit
EndIf
$bSuccess = $oImap.SelectMailbox("Inbox")
If ($bSuccess = False) Then
ConsoleWrite($oImap.LastErrorText & @CRLF)
Exit
EndIf
; Search for the message ids to download, returning UIDs.
Local $bWantUids = True
$oMsgSet = ObjCreate("Chilkat.MessageSet")
$bSuccess = $oImap.QueryMbx("ALL",$bWantUids,$oMsgSet)
If ($bSuccess = False) Then
ConsoleWrite($oImap.LastErrorText & @CRLF)
Exit
EndIf
If ($oMsgSet.Count > 0) Then
Local $iUid = $oMsgSet.GetId(0)
; Download the message's MIME into a StringBuilder. The id is a UID.
Local $bUseUid = True
$oSbMime = ObjCreate("Chilkat.StringBuilder")
$bSuccess = $oImap.FetchSingleAsMimeSb($iUid,$bUseUid,$oSbMime)
If ($bSuccess = False) Then
ConsoleWrite($oImap.LastErrorText & @CRLF)
Exit
EndIf
ConsoleWrite("MIME length: " & $oSbMime.Length & " chars" & @CRLF)
EndIf
$bSuccess = $oImap.Disconnect()
If ($bSuccess = False) Then
ConsoleWrite($oImap.LastErrorText & @CRLF)
Exit
EndIf