Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
Read S/MIME Encrypted EmailRead S/MIME encrypted email.
#include <C_CkImap.h> #include <C_CkEmailBundle.h> #include <C_CkEmail.h> void ChilkatSample(void) { HCkImap imap; BOOL success; long numToFetch; HCkEmailBundle bundle; long i; HCkEmail email; imap = CkImap_Create(); // Anything unlocks the component and begins a fully-functional 30-day trial. success = CkImap_UnlockComponent(imap,"Anything for 30-day trial"); if (success != TRUE) { printf("%s\n",CkImap_lastErrorText(imap)); return; } // Connect to an IMAP server. success = CkImap_Connect(imap,"mail.chilkatsoft.com"); if (success != TRUE) { printf("%s\n",CkImap_lastErrorText(imap)); return; } // Login success = CkImap_Login(imap,"myLogin","myPassword"); if (success != TRUE) { printf("%s\n",CkImap_lastErrorText(imap)); return; } // Select an IMAP mailbox success = CkImap_SelectMailbox(imap,"Inbox"); if (success != TRUE) { printf("%s\n",CkImap_lastErrorText(imap)); return; } // The AutoUnwrapSecurity method controls whether signed/encrypted emails are automatically // decrypted and/or verified. // When set to TRUE, which is the default, security envelopes are automatically "unwrapped" // when a message is retrieved from the server. Signed emails are automatically verified, and // encrypted emails are automatically decrypted, restoring the email to the original state before // signing and/or encrypting. Information about the signing and encrypting certificates can be // retrieved from the Email object (methods: GetSignedByCert, GetEncryptedByCert; // properties: SignedBy, EncryptedBy, SignaturesValid, Decrypted, ReceivedSigned, // ReceivedEncrypted). // This example will explicity set AutoUnwrapSecurity to TRUE, even though it's // already the default value: CkImap_putAutoUnwrapSecurity(imap,TRUE); // The NumMessages property contains the number of messages in the selected mailbox. numToFetch = CkImap_getNumMessages(imap); // Download all the email in the Inbox. bundle = CkImap_FetchSequence(imap,1,numToFetch); if (bundle == 0 ) { printf("%s\n",CkImap_lastErrorText(imap)); return; } // Loop over the bundle, for (i = 0; i <= CkEmailBundle_getMessageCount(bundle) - 1; i++) { email = CkEmailBundle_GetEmail(bundle,i); printf("%s\n",CkEmail_ck_from(email)); printf("%s\n",CkEmail_subject(email)); // At this point, if the email was signed and/or encrypted, it is already "unwrapped", i.e. // the email is already decrypted and in a state as if it were never signed or encrypted. // You may check to see if the email was received encrypted or signed, and if so, // whether it was successfully unwrapped and who signed or encrypted it: if (CkEmail_getReceivedEncrypted(email) == TRUE) { printf("This email was encrypted when received.\n"); if (CkEmail_getDecrypted(email) == TRUE) { printf("This email was successfully decrypted. It was encrypted by:\n"); printf("%s\n",CkEmail_encryptedBy(email)); } else { printf("This email was not decrypted.\n"); } } if (CkEmail_getReceivedSigned(email) == TRUE) { printf("This email was signed when received.\n"); if (CkEmail_getSignaturesValid(email) == TRUE) { printf("The signature was verified. It was signed by:\n"); printf("%s\n",CkEmail_signedBy(email)); } else { printf("The signature verification failed.\n"); } } // The email's body, HTML body, attachments, etc. // are decrypted and available just like any non-encrypted email. printf("--\n"); CkEmail_Dispose(email); } // Disconnect from the IMAP server. CkImap_Disconnect(imap); CkEmailBundle_Dispose(bundle); CkImap_Dispose(imap); } |
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2008 Chilkat Software, Inc. All Rights Reserved.