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
(PowerBuilder) 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).
integer li_rc oleobject loo_Imap integer li_Success oleobject loo_SbMime oleobject loo_Mime integer li_AlreadySavedParts oleobject loo_Sa integer li_NumFiles integer i oleobject loo_Email oleobject loo_Cert // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. loo_Imap = create oleobject // Use "Chilkat_9_5_0.Imap" for versions of Chilkat < 10.0.0 li_rc = loo_Imap.ConnectToNewObject("Chilkat.Imap") if li_rc < 0 then destroy loo_Imap MessageBox("Error","Connecting to COM object failed") return end if // Connect to an IMAP server. // Use TLS loo_Imap.Ssl = 1 loo_Imap.Port = 993 li_Success = loo_Imap.Connect("imap.someMailServer.com") if li_Success <> 1 then Write-Debug loo_Imap.LastErrorText destroy loo_Imap return end if li_Success = loo_Imap.Login("myLogin","myPassword") if li_Success <> 1 then Write-Debug loo_Imap.LastErrorText destroy loo_Imap return end if // Select an IMAP mailbox li_Success = loo_Imap.SelectMailbox("Inbox") if li_Success <> 1 then Write-Debug loo_Imap.LastErrorText destroy loo_Imap return end if // Download the 1st email (as MIME) in the Inbox by sequence number. loo_SbMime = create oleobject // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 li_rc = loo_SbMime.ConnectToNewObject("Chilkat.StringBuilder") li_Success = loo_Imap.FetchSingleAsMimeSb(1,0,loo_SbMime) if li_Success <> 1 then Write-Debug loo_Imap.LastErrorText destroy loo_Imap destroy loo_SbMime return end if // Load it into a MIME object and check to see if it is signed loo_Mime = create oleobject // Use "Chilkat_9_5_0.Mime" for versions of Chilkat < 10.0.0 li_rc = loo_Mime.ConnectToNewObject("Chilkat.Mime") loo_Mime.LoadMimeSb(loo_SbMime) li_AlreadySavedParts = 0 if loo_Mime.ContainsSignedParts() = 1 then // This will save the .p7s and other parts... loo_Sa = loo_Mime.ExtractPartsToFiles("qa_output") if loo_Mime.LastMethodSuccess = 1 then li_NumFiles = loo_Sa.Count i = 0 do while i < li_NumFiles Write-Debug "Created: " + loo_Sa.GetString(i) i = i + 1 loop destroy loo_Sa li_AlreadySavedParts = 1 end if end if // Load the MIME into an Email object. This unwraps the security layers and verifies signatures. loo_Email = create oleobject // Use "Chilkat_9_5_0.Email" for versions of Chilkat < 10.0.0 li_rc = loo_Email.ConnectToNewObject("Chilkat.Email") loo_Email.SetFromMimeSb(loo_SbMime) if loo_Email.ReceivedSigned = 1 then Write-Debug "This email was signed." // Check to see if the signatures were verified. if loo_Email.SignaturesValid = 1 then Write-Debug "Digital signature(s) verified." Write-Debug "Signer: " + loo_Email.SignedBy // The certificate used for signing may be obtained // by calling email.GetSignedByCert. loo_Cert = loo_Email.GetSignedByCert() if loo_Email.LastMethodSuccess <> 1 then Write-Debug "Failed to get signing certificate object." else Write-Debug "Signing cert: " + loo_Cert.SubjectCN destroy loo_Cert end if end if else Write-Debug "Digital signature verification failed." end if if li_AlreadySavedParts <> 1 then loo_Email.SaveAllAttachments("qa_output") end if destroy loo_Imap destroy loo_SbMime destroy loo_Mime destroy loo_Email |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.