Programming Examples

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

C Examples

Bounced Mail
Bz2
Certificates/Keys
Charset
CSV
DKIM / DomainKey
Diffie-Hellman
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

 

 

 

 

 

 

 

 

Determine the Number of Unseen Email Messages

Demonstrates how to determine how many unseen messages exist in an email account on an IMAP server.

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
FreeBSD C++ Libraries
HP-UX C++ Libraries
BlackBerry QNX C++ Libraries
#include <C_CkImap.h>
#include <C_CkMessageSet.h>

void ChilkatSample(void)
    {
    HCkImap imap;
    BOOL success;
    long totalNum;
    HCkMessageSet messageSet;
    BOOL fetchUids;
    long numUnseen;
    long i;
    long msgId;

    imap = CkImap_Create();

    //  Anything unlocks the component and begins a fully-functional 30-day trial.
    success = CkImap_UnlockComponent(imap,"Anything for 30-day trial");
    if (success != TRUE) {
        printf("%s\n",CkImap_lastErrorText(imap));
        return;
    }

    //  Connect to an IMAP server.
    success = CkImap_Connect(imap,"mail.chilkatsoft.com");
    if (success != TRUE) {
        printf("%s\n",CkImap_lastErrorText(imap));
        return;
    }

    //  Login
    success = CkImap_Login(imap,"***","***");
    if (success != TRUE) {
        printf("%s\n",CkImap_lastErrorText(imap));
        return;
    }

    //  Select an IMAP mailbox
    success = CkImap_SelectMailbox(imap,"Inbox");
    if (success != TRUE) {
        printf("%s\n",CkImap_lastErrorText(imap));
        return;
    }

    //  After selecting the mailbox. the total number of emails
    //  is immediately available:

    totalNum = CkImap_getNumMessages(imap);
    printf("%d\n",totalNum);

    //  To determine the number of unseen messages, a call
    //  to Search is required, which returns the set of UIDs
    //  of all unseen messages.

    //  We can choose to fetch UIDs or sequence numbers.

    fetchUids = TRUE;

    messageSet = CkImap_Search(imap,"UNSEEN",fetchUids);
    if (messageSet == 0 ) {
        printf("%s\n",CkImap_lastErrorText(imap));
        return;
    }

    numUnseen = CkMessageSet_getCount(messageSet);
    printf("%d\n",numUnseen);

    printf("UIDs ----\n");

    //  Display the UIDs

    for (i = 0; i <= CkMessageSet_getCount(messageSet) - 1; i++) {
        msgId = CkMessageSet_GetId(messageSet,i);
        printf("%d\n",msgId);
    }

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

    CkMessageSet_Dispose(messageSet);

    CkImap_Dispose(imap);

    }

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

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