MFC Examples

ChilkatHOMEAndroid™ASPVisual BasicVB.NETC#iOS (IPhone)Objective-CC++CMFCDelphiFoxProJavaPerl
PHP ExtensionPHP ActiveXPythonPowerShellRubySQL ServerVBScript

MFC Examples

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


 

 

 

 

 

 

 

 

How to Process a Large IMAP Mailbox

Demonstrates how to process a mailbox containing a large number of emails. This example was prompted by a Chilkat customer who needed to efficiently process a mailbox with over 100,000 emails. The technique is to first select the mailbox, which updates the imap.NumMessages property to reflect the number of messages in the mailbox. The emails in the mailbox have sequence numbers ranging from 1 to NumMessages. Two new methods, FetchSequence and FetchSequenceHeaders, can then be used to fetch emails based on sequence number ranges.

Downloads:

MS Windows Visual C/C++ Libraries
Linux/CentOS C/C++ Libraries
MAC OS X C/C++ Libraries
Solaris C/C++ Libraries
C++ Builder Libraries
// Needs #include <CkImap.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("mail.chilkatsoft.com");
    if (success != true) {
        strOut.append(imap.lastErrorText());
        strOut.append("\r\n");
        SetDlgItemText(IDC_EDIT1,strOut.getUnicode());
        return;
    }

    //  Login
    success = imap.Login("admin@chilkatsoft.com","*myPassword5*");
    if (success != true) {
        strOut.append(imap.lastErrorText());
        strOut.append("\r\n");
        SetDlgItemText(IDC_EDIT1,strOut.getUnicode());
        return;
    }

    //  Our experience has been that with some IMAP servers,
    //  the response time for selecting a mailbox increases with
    //  the size of the mailbox.  You may need to increase the
    //  ReadTimeout to a value larger than the default of 30 seconds.
    //  In this case, it is set to 60 seconds.
    imap.put_ReadTimeout(60);

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

    //  After selecting a mailbox, the NumMessages property will
    //  be updated to reflect the total number of emails in the mailbox:
    strOut.appendInt(imap.get_NumMessages());
    strOut.append("\r\n");

    //  The emails in the mailbox will always have sequence numbers
    //  ranging from 1 to NumMessages.  There are two new methods
    //  that can be called to fetch emails for a range of sequence
    //  numbers: FetchSequence and FetchSequenceHeaders.
    //  They are identical except one returns full emails whereas
    //  the other returns headers-only.

    //  This example assumes there are more than 10 emails in the
    //  mailbox and fetches the 1st 10 emails:
    CkEmailBundle *bundle = 0;
    long startSeqNum;
    startSeqNum = 1;
    long numToFetch;
    numToFetch = 10;
    bundle = imap.FetchSequence(startSeqNum,numToFetch);
    if (bundle == 0 ) {
        strOut.append(imap.lastErrorText());
        strOut.append("\r\n");
        SetDlgItemText(IDC_EDIT1,strOut.getUnicode());
        return;
    }

    //  Print the From and Subject of each email:
    long i;
    for (i = 0; i <= bundle->get_MessageCount() - 1; i++) {
        CkEmail *email = 0;
        //  GetEmail does not communication with the IMAP server.
        //  It simply extracts a single email from the in-memory bundle.
        email = bundle->GetEmail(i);

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

        strOut.append("--");
        strOut.append("\r\n");
        delete email;
    }

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

    delete bundle;

    SetDlgItemText(IDC_EDIT1,strOut.getUnicode());

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

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