Chilkat
HOME
Android™
ASP
Visual Basic
VB.NET
C#
iOS (IPhone)
Objective-C
C++
C
MFC
Delphi
FoxPro
Java
Perl
PHP Extension
PHP ActiveX
Python
PowerShell
Ruby
SQL Server
VBScript
Read S/MIME Encrypted EmailRead S/MIME encrypted email. Downloads for Windows/Linux and Install Instructions require 'rubygems' require 'chilkat' imap = Chilkat::CkImap.new() # Anything unlocks the component and begins a fully-functional 30-day trial. success = imap.UnlockComponent("Anything for 30-day trial") if (success != true) print imap.lastErrorText() + "\n" exit end # Connect to an IMAP server. success = imap.Connect("mail.chilkatsoft.com") if (success != true) print imap.lastErrorText() + "\n" exit end # Login success = imap.Login("myLogin","myPassword") if (success != true) print imap.lastErrorText() + "\n" exit end # Select an IMAP mailbox success = imap.SelectMailbox("Inbox") if (success != true) print imap.lastErrorText() + "\n" exit end # 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: imap.put_AutoUnwrapSecurity(true) # The NumMessages property contains the number of messages in the selected mailbox. numToFetch = imap.get_NumMessages() # Download all the email in the Inbox. bundle = imap.FetchSequence(1,numToFetch) if (bundle == nil ) print imap.lastErrorText() + "\n" exit end # Loop over the bundle, for i in 0 .. bundle.get_MessageCount() - 1 email = bundle.GetEmail(i) print email.ck_from() + "\n"; print email.subject() + "\n"; # 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 (email.get_ReceivedEncrypted() == true) print "This email was encrypted when received." + "\n"; if (email.get_Decrypted() == true) print "This email was successfully decrypted. It was encrypted by:" + "\n"; print email.encryptedBy() + "\n"; else print "This email was not decrypted." + "\n"; end end if (email.get_ReceivedSigned() == true) print "This email was signed when received." + "\n"; if (email.get_SignaturesValid() == true) print "The signature was verified. It was signed by:" + "\n"; print email.signedBy() + "\n"; else print "The signature verification failed." + "\n"; end end # The email's body, HTML body, attachments, etc. # are decrypted and available just like any non-encrypted email. print "--" + "\n"; end # Disconnect from the IMAP server. imap.Disconnect() |
© 2000-2010 Chilkat Software, Inc. All Rights Reserved.