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

 

 

 

 

 

 

 

 

How to Copy IMAP Mail to another IMAP Server

Demonstrates how to copy the entire contents of an IMAP mailbox to another 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_CkStringArray.h>

void ChilkatSample(void)
    {
    HCkImap imapSrc;
    BOOL success;
    HCkImap imapDest;
    long startSeqNum;
    long msgCount;
    HCkStringArray sa;
    long i;

    imapSrc = CkImap_Create();

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

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

    //  Login to the source IMAP server
    success = CkImap_Login(imapSrc,"admin@chilkatsoft.com","*myPassword5*");
    if (success != TRUE) {
        printf("%s\n",CkImap_lastErrorText(imapSrc));
        return;
    }

    imapDest = CkImap_Create();

    //  Connect to our destination IMAP server.
    success = CkImap_Connect(imapDest,"mail.example-code.com");
    if (success != TRUE) {
        printf("%s\n",CkImap_lastErrorText(imapDest));
        return;
    }

    //  Login to the destination IMAP server
    success = CkImap_Login(imapDest,"myLogin","*myPassword2*");
    if (success != TRUE) {
        printf("%s\n",CkImap_lastErrorText(imapDest));
        return;
    }

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

    //  After selecting a mailbox, the NumMessages property will
    //  be updated to reflect the total number of emails in the mailbox:
    printf("%d\n",CkImap_getNumMessages(imapSrc));

    //  The emails in the mailbox will always have sequence numbers
    //  ranging from 1 to NumMessages.

    //  This example will copy the first 10 messages.
    //  We'll leave it up to you to write code to copy
    //  the entire sequence range in reasonable size chunks.

    startSeqNum = 1;

    msgCount = 10;

    sa = CkImap_FetchSequenceAsMime(imapSrc,startSeqNum,msgCount);
    if (sa == 0 ) {
        printf("%s\n",CkImap_lastErrorText(imapSrc));
        return;
    }

    for (i = 0; i <= CkStringArray_getCount(sa) - 1; i++) {
        success = CkImap_AppendMime(imapDest,"Inbox",CkStringArray_getString(sa,i));
        if (success != TRUE) {
            printf("%s\n",CkImap_lastErrorText(imapDest));
            return;
        }

    }

    CkStringArray_Dispose(sa);

    //  Disconnect from the IMAP servers.
    CkImap_Disconnect(imapSrc);
    CkImap_Disconnect(imapDest);

    CkImap_Dispose(imapSrc);
    CkImap_Dispose(imapDest);

    }

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

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