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.
use chilkat; $imap = new chilkat::CkImap(); # Anything unlocks the component and begins a fully-functional 30-day trial. $success = $imap->UnlockComponent("Anything for 30-day trial"); if ($success != 1) { print $imap->lastErrorText() . "\n"; exit; } # Connect to an IMAP server. $success = $imap->Connect("mail.chilkatsoft.com"); if ($success != 1) { print $imap->lastErrorText() . "\n"; exit; } # Login $success = $imap->Login("myLogin","myPassword"); if ($success != 1) { print $imap->lastErrorText() . "\n"; exit; } # Select an IMAP mailbox $success = $imap->SelectMailbox("Inbox"); if ($success != 1) { print $imap->lastErrorText() . "\n"; exit; } # The AutoUnwrapSecurity method controls whether signed/encrypted emails are automatically # decrypted and/or verified. # When set to 1, 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 1, even though it's # already the default value: $imap->put_AutoUnwrapSecurity(1); # 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 eq null ) { print $imap->lastErrorText() . "\n"; exit; } # Loop over the bundle, for ($i = 0; $i <= $bundle->get_MessageCount() - 1; $i++) { $email = $bundle->GetEmail($i); print $email->ck_from() . "\r\n"; print $email->subject() . "\r\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() == 1) { print "This email was encrypted when received." . "\r\n"; if ($email->get_Decrypted() == 1) { print "This email was successfully decrypted. It was encrypted by:" . "\r\n"; print $email->encryptedBy() . "\r\n"; } else { print "This email was not decrypted." . "\r\n"; } } if ($email->get_ReceivedSigned() == 1) { print "This email was signed when received." . "\r\n"; if ($email->get_SignaturesValid() == 1) { print "The signature was verified. It was signed by:" . "\r\n"; print $email->signedBy() . "\r\n"; } else { print "The signature verification failed." . "\r\n"; } } # The email's body, HTML body, attachments, etc. # are decrypted and available just like any non-encrypted email. print "--" . "\r\n"; } # Disconnect from the IMAP server. $imap->Disconnect(); |
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2010 Chilkat Software, Inc. All Rights Reserved.