MFC Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

MFC Examples

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


 

 

 

 

 

 

 

 

Search/Download only Encrypted Emails

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

Download Chilkat C/C++ Libraries for VC++ 9.0 / Win32

Download Chilkat C/C++ Libraries for VC++ 8.0 / Win32

Download Chilkat C/C++ 64-bit Libraries for VC++ 8.0 / x64

Download Chilkat Visual Studio 2005 C/C++ Libs for Windows Mobile, Pocket PC, SmartPhone, WinCE

Download Chilkat C/C++ Libraries for VC++ 7.0 / Win32

Download Chilkat C/C++ Libraries for VC++ 6.0 / Win32

Download Chilkat C/C++ Libraries for VC++ 6.0, Win 95/98/NT4 Compatible

// Needs #include <CkImap.h>
// Needs #include <CkMessageSet.h>
// Needs #include <CkEmailBundle.h>
// Needs #include <CkEmail.h>

    CkString strOut;

    CkImap imap;

    bool success;

    //  Anything unlocks the component and begins a fully-functional 30-day trial.
    success = imap.UnlockComponent("Anything for 30-day trial");
    if (success != true) {
        strOut.append(imap.lastErrorText());
        strOut.append("\r\n");
        SetDlgItemText(IDC_EDIT1,strOut.getUnicode());
        return;
    }

    //  Connect to an IMAP server.
    success = imap.Connect("www.cknotes.com");
    if (success != true) {
        strOut.append(imap.lastErrorText());
        strOut.append("\r\n");
        SetDlgItemText(IDC_EDIT1,strOut.getUnicode());
        return;
    }

    //  Login
    success = imap.Login("myLogin","myPassword");
    if (success != true) {
        strOut.append(imap.lastErrorText());
        strOut.append("\r\n");
        SetDlgItemText(IDC_EDIT1,strOut.getUnicode());
        return;
    }

    //  Select an IMAP mailbox
    success = imap.SelectMailbox("Inbox");
    if (success != true) {
        strOut.append(imap.lastErrorText());
        strOut.append("\r\n");
        SetDlgItemText(IDC_EDIT1,strOut.getUnicode());
        return;
    }

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

    CkMessageSet *messageSet = 0;
    bool fetchUids;
    fetchUids = true;
    messageSet = imap.Search(headerSearch,fetchUids);
    if (messageSet == 0 ) {
        strOut.append(imap.lastErrorText());
        strOut.append("\r\n");
        SetDlgItemText(IDC_EDIT1,strOut.getUnicode());
        return;
    }

    //  Download the emails indicated in the messageSet.
    //  The emails are automatically decrypted.
    CkEmailBundle *bundle = 0;
    bundle = imap.FetchBundle(*messageSet);
    if (bundle == 0 ) {
        delete messageSet;
        strOut.append(imap.lastErrorText());
        strOut.append("\r\n");
        SetDlgItemText(IDC_EDIT1,strOut.getUnicode());
        return;
    }

    //  Display some information from each email:
    long i;
    for (i = 0; i <= bundle->get_MessageCount() - 1; i++) {
        CkEmail *email = 0;
        email = bundle->GetEmail(i);

        strOut.append(email->getHeaderField("Date"));
        strOut.append("\r\n");
        strOut.append(email->subject());
        strOut.append("\r\n");
        strOut.append(email->ck_from());
        strOut.append("\r\n");

        strOut.append("Received Encrypted: ");
        strOut.appendInt(email->get_ReceivedEncrypted());
        strOut.append("\r\n");
        if (email->get_ReceivedEncrypted() == true) {
            strOut.append("Successfully Decrypted: ");
            strOut.appendInt(email->get_Decrypted());
            strOut.append("\r\n");
        }

        strOut.append("Received Signed: ");
        strOut.appendInt(email->get_ReceivedSigned());
        strOut.append("\r\n");
        if (email->get_ReceivedSigned() == true) {
            strOut.append("Signature Verified: ");
            strOut.appendInt(email->get_SignaturesValid());
            strOut.append("\r\n");
        }

        strOut.append("--");
        strOut.append("\r\n");

        delete email;
    }

    //  Disconnect from the IMAP server.
    imap.Disconnect();

    delete messageSet;
    delete bundle;

    SetDlgItemText(IDC_EDIT1,strOut.getUnicode());

Need a specific example? Send a request to support@chilkatsoft.com

© 2000-2008 Chilkat Software, Inc. All Rights Reserved.