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
(Visual FoxPro) 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).
LOCAL loImap LOCAL lnSuccess LOCAL loSbMime LOCAL loMime LOCAL lnAlreadySavedParts LOCAL loSa LOCAL lnNumFiles LOCAL i LOCAL loEmail LOCAL loCert * This example requires the Chilkat API to have been previously unlocked. * See Global Unlock Sample for sample code. * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Imap') loImap = CreateObject('Chilkat.Imap') * Connect to an IMAP server. * Use TLS loImap.Ssl = 1 loImap.Port = 993 lnSuccess = loImap.Connect("imap.someMailServer.com") IF (lnSuccess <> 1) THEN ? loImap.LastErrorText RELEASE loImap CANCEL ENDIF lnSuccess = loImap.Login("myLogin","myPassword") IF (lnSuccess <> 1) THEN ? loImap.LastErrorText RELEASE loImap CANCEL ENDIF * Select an IMAP mailbox lnSuccess = loImap.SelectMailbox("Inbox") IF (lnSuccess <> 1) THEN ? loImap.LastErrorText RELEASE loImap CANCEL ENDIF * Download the 1st email (as MIME) in the Inbox by sequence number. * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.StringBuilder') loSbMime = CreateObject('Chilkat.StringBuilder') lnSuccess = loImap.FetchSingleAsMimeSb(1,0,loSbMime) IF (lnSuccess <> 1) THEN ? loImap.LastErrorText RELEASE loImap RELEASE loSbMime CANCEL ENDIF * Load it into a MIME object and check to see if it is signed * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Mime') loMime = CreateObject('Chilkat.Mime') loMime.LoadMimeSb(loSbMime) lnAlreadySavedParts = 0 IF (loMime.ContainsSignedParts() = 1) THEN * This will save the .p7s and other parts... loSa = loMime.ExtractPartsToFiles("qa_output") IF (loMime.LastMethodSuccess = 1) THEN lnNumFiles = loSa.Count i = 0 DO WHILE i < lnNumFiles ? "Created: " + loSa.GetString(i) i = i + 1 ENDDO RELEASE loSa lnAlreadySavedParts = 1 ENDIF ENDIF * Load the MIME into an Email object. This unwraps the security layers and verifies signatures. * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Email') loEmail = CreateObject('Chilkat.Email') loEmail.SetFromMimeSb(loSbMime) IF (loEmail.ReceivedSigned = 1) THEN ? "This email was signed." * Check to see if the signatures were verified. IF (loEmail.SignaturesValid = 1) THEN ? "Digital signature(s) verified." ? "Signer: " + loEmail.SignedBy * The certificate used for signing may be obtained * by calling email.GetSignedByCert. loCert = loEmail.GetSignedByCert() IF (loEmail.LastMethodSuccess <> 1) THEN ? "Failed to get signing certificate object." ELSE ? "Signing cert: " + loCert.SubjectCN RELEASE loCert ENDIF ENDIF ELSE ? "Digital signature verification failed." ENDIF IF (lnAlreadySavedParts <> 1) THEN loEmail.SaveAllAttachments("qa_output") ENDIF RELEASE loImap RELEASE loSbMime RELEASE loMime RELEASE loEmail |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.