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


 

 

 

 

 

 

 

 

Delete All IMAP Email

Demonstrates two ways to delete all email in a mailbox on an IMAP server.

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>

    CkString strOut;

    bool success;
    CkImap imap;

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

    //  Turn on session logging:
    imap.put_KeepSessionLog(true);

    //  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("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.RubyMail");
    if (success != true) {
        strOut.append(imap.lastErrorText());
        strOut.append("\r\n");
        SetDlgItemText(IDC_EDIT1,strOut.getUnicode());
        return;
    }

    CkMessageSet *messageSet = 0;

    //  Get the complete set of Uids for email in the selected mailbox.
    messageSet = imap.GetAllUids();
    if (messageSet == 0 ) {
        strOut.append(imap.lastErrorText());
        strOut.append("\r\n");
        SetDlgItemText(IDC_EDIT1,strOut.getUnicode());
        return;
    }

    //  Set the Deleted flag for each message.
    //  (ExpungeAndClose must be called to finalize the delete.)
    success = imap.SetFlags(*messageSet,"Deleted",1);
    if (success != true) {
        strOut.append(imap.lastErrorText());
        strOut.append("\r\n");
        SetDlgItemText(IDC_EDIT1,strOut.getUnicode());
        return;
    }

    //  Alternatively, the Deleted flag may be set for each UID
    //  individiually, but this is less efficient:
    long i;
    long n;
    n = messageSet->get_Count();
    for (i = 0; i <= n - 1; i++) {
        success = imap.SetFlag(messageSet->GetId(i),messageSet->get_HasUids(),"Deleted",1);
        if (success != true) {
            strOut.append(imap.lastErrorText());
            strOut.append("\r\n");
            SetDlgItemText(IDC_EDIT1,strOut.getUnicode());
            return;
        }

    }

    //  Expunge and close the mailbox.
    success = imap.ExpungeAndClose();
    if (success != true) {
        strOut.append(imap.lastErrorText());
        strOut.append("\r\n");
        SetDlgItemText(IDC_EDIT1,strOut.getUnicode());
        return;
    }

    //  Display the session log.
    strOut.append(imap.sessionLog());
    strOut.append("\r\n");

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

    delete messageSet;

    SetDlgItemText(IDC_EDIT1,strOut.getUnicode());

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

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