Programming Examples

ChilkatHOMEASPVisual BasicVB.NETC#CC++MFCDelphiFoxProJavaPerlPythonRubySQL ServerVBScript

PHP Examples

Bounced Mail
Bz2
Certificates/Keys
Charset
CSV
DKIM / DomainKey
Diffie-Hellman
DSA
Email Object
Encryption
FileAccess
FTP
HTML-to-XML
HTTP
IMAP
MHT / HTML Email
MIME
NTLM
POP3
RSA
SMTP
Socket
Spider
SSH Key
SSH
SSH Tunnel
SFTP
Tar
Upload
XML
Zip


 

 

 

 

 

 

 

 

Read S/MIME Encrypted Email

Read S/MIME encrypted email.

Download Chilkat IMAP ActiveX

<?php

$imap = new COM("Chilkat.Imap");

//  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;
}

//  Connect to an IMAP server.
$success = $imap->Connect('mail.chilkatsoft.com');
if ($success != true) {
    print $imap->lastErrorText() . "\n";
    exit;
}

//  Login
$success = $imap->Login('myLogin','myPassword');
if ($success != true) {
    print $imap->lastErrorText() . "\n";
    exit;
}

//  Select an IMAP mailbox
$success = $imap->SelectMailbox('Inbox');
if ($success != true) {
    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->AutoUnwrapSecurity = true;

//  The NumMessages property contains the number of messages in the selected mailbox.
$numToFetch = $imap->NumMessages;
//  Download all the email in the Inbox.

$bundle = $imap->FetchSequence(1,$numToFetch);
if (is_null($bundle)) {
    print $imap->lastErrorText() . "\n";
    exit;
}

//  Loop over the bundle,

for ($i = 0; $i <= $bundle->MessageCount - 1; $i++) {

    $email = $bundle->GetEmail($i);

    print $email->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->ReceivedEncrypted == true) {

        print 'This email was encrypted when received.' . "\n";
        if ($email->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";
        }

    }

    if ($email->ReceivedSigned == true) {

        print 'This email was signed when received.' . "\n";
        if ($email->SignaturesValid == true) {
            print 'The signature was verified.  It was signed by:' . "\n";
            print $email->signedBy() . "\n";
        }
        else {
            print 'The signature verification failed.' . "\n";
        }

    }

    //  The email's body, HTML body, attachments, etc.
    //  are decrypted and available just like any non-encrypted email.

    print '--' . "\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.