AutoIt Requires Chilkat v11.0.0+
AutoIt
Preserve the original email and save a modified copy
See more Email Object Examples
Use with-attachments.eml as a stand-in for bytes from an IMAP fetch or a message queue. Preserve those bytes first. Parse them into an Email object, add a local processing header, and serialize the result into a separate buffer. The archived input remains suitable for later byte-level inspection.
Chilkat AutoIt Downloads
Local $bSuccess = False
; Assumes Chilkat is unlocked. See Global Unlock Sample.
$oMimeBytes = ObjCreate("Chilkat.BinData")
$bSuccess = $oMimeBytes.LoadFile("with-attachments.eml")
If ($bSuccess <> True) Then
ConsoleWrite("Failed: mimeBytes.LoadFile." & @CRLF)
Exit
EndIf
$bSuccess = $oMimeBytes.WriteFile("received-original.eml")
If ($bSuccess <> True) Then
ConsoleWrite("Failed: mimeBytes.WriteFile." & @CRLF)
Exit
EndIf
$oEmail = ObjCreate("Chilkat.Email")
$bSuccess = $oEmail.SetFromMimeBd($oMimeBytes)
If ($bSuccess <> True) Then
ConsoleWrite($oEmail.LastErrorText & @CRLF)
Exit
EndIf
$oEmail.AddHeaderField "X-Workflow-State","reviewed"
; GetMimeBd appends to its destination. Use a fresh buffer for this message.
$oRendered = ObjCreate("Chilkat.BinData")
$bSuccess = $oEmail.GetMimeBd($oRendered)
If ($bSuccess <> True) Then
ConsoleWrite($oEmail.LastErrorText & @CRLF)
Exit
EndIf
$bSuccess = $oRendered.WriteFile("reviewed.eml")
If ($bSuccess <> True) Then
ConsoleWrite("Failed: rendered.WriteFile." & @CRLF)
Exit
EndIf
ConsoleWrite("Archived received-original.eml and saved reviewed.eml." & @CRLF)