![]() |
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 (S/MIME) EmailDemonstrates how to download and verify digitally signed S/MIME email. 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 } // We can choose to fetch UIDs or sequence numbers. var fetchUids: Bool = true // Get the message IDs of all the emails in the mailbox let messageSet = CkoMessageSet()! success = imap.queryMbx("ALL", bUid: fetchUids, msgSet: messageSet) if success == false { print("\(imap.lastErrorText!)") return } let email = CkoEmail()! let cert = CkoCert()! var i: Int = 0 while i < messageSet.count.intValue { var uid: String? = messageSet.getId(i) print("uid: \(uid!)") success = imap.fetchEmail(false, msgId: uid, bUid: true, email: email) if success == false { print("\(imap.lastErrorText!)") return } // The security layers of signed and/or encrypted emails // are automatically "unwrapped" when loaded into // a Chilkat email object. // An application only needs to check to see if an email // was received signed or encrypted, and then examine // the success/failure. For example: 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!)") // Get the certificate used for signing. success = email.lastSignerCert(0, cert: cert) if success == false { print("Failed to get signing certificate object.") } else { print("Signing cert: \(cert.subjectCN!)") } } else { print("Digital signature verification failed.") } } i = i + 1 } // Disconnect from the IMAP server. success = imap.disconnect() } |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.