Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

Java Examples

Web API Categories

ASN.1
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
Geolocation
Google APIs
Google Calendar
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text

HTTP
HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
REST
REST Misc
RSA Encryption
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Socket/SSL/TLS
Spider
Stream
Tar Archive
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

(Java) Using IMAP IDLE to Wait for Updates

This example demonstrates how to use the IMAP IDLE functionality in Chilkat.

Chilkat Java Downloads

Java Libs for Windows, Linux, Alpine Linux,
MAC OS X, Solaris, FreeBSD, OpenBSD,
Raspberry Pi and other single board computers

Java Libs for Android

import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    CkImap imap = new CkImap();

    boolean success;

    //  ....
    //  ....
    //  ....

    //  Select an IMAP mailbox
    success = imap.SelectMailbox("INBOX");
    if (success != true) {
        System.out.println(imap.lastErrorText());
        return;
    }

    //  After a mailbox has been selected, IDLE may begin.
    //  Idling tells the IMAP server to push unsolicited updates for the selected
    //  mailbox to the connected client (which is your application).
    success = imap.IdleStart();
    if (success != true) {
        System.out.println(imap.lastErrorText());
        return;
    }

    //  Once idling has started, your code still has to periodically check to see
    //  if any updates have arrived.  However, this is significantly different
    //  then what normally occurs when checking email.  The IdleCheck does NOT
    //  send a message to the IMAP server.  It simply checks the connection to see
    //  if any data has arrived.  If so, it can be consumed and the client (your app)
    //  can react appropriately.

    //  Note: It is recommended that idling only run for a max of 20 minutes before stopping and
    //  re-starting the IDLE.  This is to maintain a minimum low level of activity so that
    //  the IMAP server does not disconnect (which it may do if it considers the connection to
    //  be truly inactive, i.e. forgotten).

    //  To check the connection for IDLE updates, call IdleCheck.  The 1st argument indicates how
    //  long we're willing to wait. We'll wait 1 millisecond:
    String idleResultXml;
    idleResultXml = imap.idleCheck(1);
    if (imap.get_LastMethodSuccess() != true) {
        System.out.println(imap.lastErrorText());
        return;
    }

    //  See the online reference documentation for details regarding the XML that is returned.
    //  Your application code would parse the XML to determine what action to take.
    //  If the XML contains "<idle></idle>", then no updates are available and your application
    //  would call IdleCheck again at some point in the future.

    //  If updates are available, the IDLE must be terminated by calling IdleDone, like this:
    success = imap.IdleDone();
    if (success != true) {
        System.out.println(imap.lastErrorText());
        return;
    }

    //  Once the IDLE is terminated, your application can make calls to fetch email, etc.
    //  Any attempt to communicate with the IMAP server prior to terminating the IDLE will
    //  result in failure.

    //  IMPORTANT: Please realize that your application code will be structured differently than shown here.
    //  The call to IdleCheck will likely be in a function/procedure that is periodically called
    //  after the IdleStart has been called from some other location in your app.

  }
}

 

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