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
(PureBasic) 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).
IncludeFile "CkMime.pb" IncludeFile "CkImap.pb" IncludeFile "CkEmail.pb" IncludeFile "CkStringArray.pb" IncludeFile "CkStringBuilder.pb" IncludeFile "CkCert.pb" Procedure ChilkatExample() ; This example requires the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. imap.i = CkImap::ckCreate() If imap.i = 0 Debug "Failed to create object." ProcedureReturn EndIf ; Connect to an IMAP server. ; Use TLS CkImap::setCkSsl(imap, 1) CkImap::setCkPort(imap, 993) success.i = CkImap::ckConnect(imap,"imap.someMailServer.com") If success <> 1 Debug CkImap::ckLastErrorText(imap) CkImap::ckDispose(imap) ProcedureReturn EndIf success = CkImap::ckLogin(imap,"myLogin","myPassword") If success <> 1 Debug CkImap::ckLastErrorText(imap) CkImap::ckDispose(imap) ProcedureReturn EndIf ; Select an IMAP mailbox success = CkImap::ckSelectMailbox(imap,"Inbox") If success <> 1 Debug CkImap::ckLastErrorText(imap) CkImap::ckDispose(imap) ProcedureReturn EndIf ; Download the 1st email (as MIME) in the Inbox by sequence number. sbMime.i = CkStringBuilder::ckCreate() If sbMime.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success = CkImap::ckFetchSingleAsMimeSb(imap,1,0,sbMime) If success <> 1 Debug CkImap::ckLastErrorText(imap) CkImap::ckDispose(imap) CkStringBuilder::ckDispose(sbMime) ProcedureReturn EndIf ; Load it into a MIME object and check to see if it is signed mime.i = CkMime::ckCreate() If mime.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkMime::ckLoadMimeSb(mime,sbMime) alreadySavedParts.i = 0 If CkMime::ckContainsSignedParts(mime) = 1 ; This will save the .p7s and other parts... sa.i = CkMime::ckExtractPartsToFiles(mime,"qa_output") If CkMime::ckLastMethodSuccess(mime) = 1 numFiles.i = CkStringArray::ckCount(sa) i.i = 0 While i < numFiles Debug "Created: " + CkStringArray::ckGetString(sa,i) i = i + 1 Wend CkStringArray::ckDispose(sa) alreadySavedParts = 1 EndIf EndIf ; Load the MIME into an Email object. This unwraps the security layers and verifies signatures. email.i = CkEmail::ckCreate() If email.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkEmail::ckSetFromMimeSb(email,sbMime) If CkEmail::ckReceivedSigned(email) = 1 Debug "This email was signed." ; Check to see if the signatures were verified. If CkEmail::ckSignaturesValid(email) = 1 Debug "Digital signature(s) verified." Debug "Signer: " + CkEmail::ckSignedBy(email) ; The certificate used for signing may be obtained ; by calling email.GetSignedByCert. cert.i = CkEmail::ckGetSignedByCert(email) If CkEmail::ckLastMethodSuccess(email) <> 1 Debug "Failed to get signing certificate object." Else Debug "Signing cert: " + CkCert::ckSubjectCN(cert) CkCert::ckDispose(cert) EndIf EndIf Else Debug "Digital signature verification failed." EndIf If alreadySavedParts <> 1 CkEmail::ckSaveAllAttachments(email,"qa_output") EndIf CkImap::ckDispose(imap) CkStringBuilder::ckDispose(sbMime) CkMime::ckDispose(mime) CkEmail::ckDispose(email) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.