![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Swift) IMAP Download and Verify Signed MIMEDownloads the original MIME of a digitally signed email and saves the .p7s signature along with other MIME parts. It then imports the email into a Chilkat email object to unwrap the S/MIME and verify the signature, and subsequently saves the attachments if they haven't been saved already. Note: This example requires Chilkat v11.0.0 or greater.
func chilkatTest() { var success: Bool = false // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. let imap = CkoImap()! // Connect to an IMAP server. // Use TLS imap.ssl = true imap.port = 993 success = imap.connect("imap.example.com") if success == false { print("\(imap.lastErrorText!)") return } success = imap.login("myLogin", password: "myPassword") if success == false { print("\(imap.lastErrorText!)") return } // Select an IMAP mailbox success = imap.selectMailbox("Inbox") if success == false { print("\(imap.lastErrorText!)") return } // Download the 1st email (as MIME) in the Inbox by sequence number. let sbMime = CkoStringBuilder()! success = imap.fetchSingle(asMimeSb: 1, bUid: false, sbMime: sbMime) if success == false { print("\(imap.lastErrorText!)") return } // Load it into a MIME object and check to see if it is signed let mime = CkoMime()! mime.loadSb(sbMime) var alreadySavedParts: Bool = false if mime.containsSignedParts() == true { // This will save the .p7s and other parts... let st = CkoStringTable()! success = mime.parts(toFiles: "c:/temp/qa_output", st: st) if success == true { var numFiles: Int = st.count.intValue var i: Int = 0 while i < numFiles { print("Created: \(st.string(at: i)!)") i = i + 1 } alreadySavedParts = true } } // Load the MIME into an Email object. This unwraps the security layers and verifies signatures. let email = CkoEmail()! email.setFromMimeSb(sbMime) if email.receivedSigned == true { print("This email was signed.") // Check to see if the signatures were verified. if email.signaturesValid == true { print("Digital signature(s) verified.") print("Signer: \(email.signedBy!)") // The certificate used for signing may be obtained // by calling email.GetSignedByCert. let cert = CkoCert()! success = email.lastSignerCert(i, cert: cert) if success == false { print("Failed to get signing certificate object.") } else { print("Signing cert: \(cert.subjectCN!)") } } } else { print("Digital signature verification failed.") } if alreadySavedParts != true { email.saveAllAttachments("c:/temp/qa_output") } } |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.