Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(AutoIt) IMAP Download and Verify Signed MIMEDownloads the unmodified MIME of a digitally signed email, saves the .p7s signature (and other MIME parts), then loads the email into a Chilkat email object (which unwraps the S/MIME and verifies the signature) and then saves attachments (if the MIME parts were not already saved).
; This example requires the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. $oImap = ObjCreate("Chilkat.Imap") ; Connect to an IMAP server. ; Use TLS $oImap.Ssl = True $oImap.Port = 993 Local $bSuccess = $oImap.Connect("imap.someMailServer.com") If ($bSuccess <> True) Then ConsoleWrite($oImap.LastErrorText & @CRLF) Exit EndIf $bSuccess = $oImap.Login("myLogin","myPassword") If ($bSuccess <> True) Then ConsoleWrite($oImap.LastErrorText & @CRLF) Exit EndIf ; Select an IMAP mailbox $bSuccess = $oImap.SelectMailbox("Inbox") If ($bSuccess <> True) Then ConsoleWrite($oImap.LastErrorText & @CRLF) Exit EndIf ; Download the 1st email (as MIME) in the Inbox by sequence number. $oSbMime = ObjCreate("Chilkat.StringBuilder") $bSuccess = $oImap.FetchSingleAsMimeSb(1,False,$oSbMime) If ($bSuccess <> True) Then ConsoleWrite($oImap.LastErrorText & @CRLF) Exit EndIf ; Load it into a MIME object and check to see if it is signed $oMime = ObjCreate("Chilkat.Mime") $oMime.LoadMimeSb($oSbMime) Local $bAlreadySavedParts = False If ($oMime.ContainsSignedParts() = True) Then ; This will save the .p7s and other parts... Local $oSa = $oMime.ExtractPartsToFiles("qa_output") If ($oMime.LastMethodSuccess = True) Then Local $iNumFiles = $oSa.Count Local $i = 0 While $i < $iNumFiles ConsoleWrite("Created: " & $oSa.GetString($i) & @CRLF) $i = $i + 1 Wend $bAlreadySavedParts = True EndIf EndIf ; Load the MIME into an Email object. This unwraps the security layers and verifies signatures. $oEmail = ObjCreate("Chilkat.Email") $oEmail.SetFromMimeSb($oSbMime) If ($oEmail.ReceivedSigned = True) Then ConsoleWrite("This email was signed." & @CRLF) ; Check to see if the signatures were verified. If ($oEmail.SignaturesValid = True) Then ConsoleWrite("Digital signature(s) verified." & @CRLF) ConsoleWrite("Signer: " & $oEmail.SignedBy & @CRLF) ; The certificate used for signing may be obtained ; by calling email.GetSignedByCert. Local $oCert = $oEmail.GetSignedByCert() If ($oEmail.LastMethodSuccess <> True) Then ConsoleWrite("Failed to get signing certificate object." & @CRLF) Else ConsoleWrite("Signing cert: " & $oCert.SubjectCN & @CRLF) EndIf EndIf Else ConsoleWrite("Digital signature verification failed." & @CRLF) EndIf If ($bAlreadySavedParts <> True) Then $oEmail.SaveAllAttachments("qa_output") EndIf |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.