Perl Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

Perl Examples

Quick Start
Unicode
Byte Array
Bz2
Certificates
CSV
Email
Encryption
FTP
HTML-to-XML
HTTP
IMAP
MHT
MIME
POP3
RSA
S/MIME
Signatures
SMTP
Socket / SSL
Spider
SFTP
SSH Key
SSH
SSH Tunnel
Tar
HTTP Upload
XML
XMP
Zip

More Examples...
String
Email Object
DKIM / DomainKey
NTLM
FileAccess
RSS
Atom
Self-Extractor
Service
PPMD
Deflate
DH Key Exchange
DSA
Bzip2
LZW

 

 

 

 

 

 

 

Search/Download only Encrypted Emails

Searching an IMAP mailbox for emails that are encrypted and download. Emails are automatically decrypted.

Chilkat Module for Perl 5.8.*

Chilkat Module for Perl 5.10.*

Chilkat Module for Perl 5.8.* (x64)

Chilkat Module for Perl 5.10.* (x64)

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("www.cknotes.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;
}

#  An S/MIME encrypted email should have a content-type
#  header containing the substring "pkcs7-mime":
$headerSearch = "HEADER Content-Type pkcs7-mime";

$fetchUids = 1;
# messageSet is a CkMessageSet
$messageSet = $imap->Search($headerSearch,$fetchUids);
if ($messageSet eq null ) {
    print $imap->lastErrorText() . "\n";
    exit;
}

#  Download the emails indicated in the messageSet.
#  The emails are automatically decrypted.

# bundle is a CkEmailBundle
$bundle = $imap->FetchBundle($messageSet);
if ($bundle eq null ) {

    print $imap->lastErrorText() . "\n";
    exit;
}

#  Display some information from each email:

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

    # email is a CkEmail
    $email = $bundle->GetEmail($i);

    print $email->getHeaderField("Date") . "\r\n";
    print $email->subject() . "\r\n";
    print $email->ck_from() . "\r\n";

    print "Received Encrypted: " . $email->get_ReceivedEncrypted() . "\r\n";
    if ($email->get_ReceivedEncrypted() == 1) {
        print "Successfully Decrypted: " . $email->get_Decrypted() . "\r\n";
    }

    print "Received Signed: " . $email->get_ReceivedSigned() . "\r\n";
    if ($email->get_ReceivedSigned() == 1) {
        print "Signature Verified: " . $email->get_SignaturesValid() . "\r\n";
    }

    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.