Git Product home page Git Product logo

imapnio's Introduction

imapnio

A Java library that supports NIO (Non-blocking I/O) based IMAP clients.

The IMAP NIO client provides a framework to access an IMAP message store using None-blocking I/O mechanism. This design scales well for thousands of connections per machine and reduces contention when using a large number of threads and CPUs.

Table of Contents

Background

The traditional accessing IMAP message store uses JavaMail API, which requires a blocking I/O. In this case, threads are blocked when performing I/O with the other end. This project was developed to relieve the waiting thread to perform other tasks, and it's design efficiently improves thread utilization to maximize hardware throughput and capacity.

Some of the more distinguishing features of this library are:

  • Highly customizable thread model and server/client idle max limit.
  • Leverages the well-established framework Netty
  • Future-based design enables a clean separation of IMAP client threads pool versus consumers threads pool.
  • IMAPv4, RFC3501 support.
  • ID command, RFC2971 support.
  • IDLE command, RFC2177 support
  • MOVE command, RFC6851 support
  • UNSELECT command, RFC3691 support

This project is ideal for applications that have a high requirement to optimize thread utilization and improve overall resource capacity. Specifically, this is best for situations where users perform a very high level of sessions and communication with the IMAP server.

Install

This is a Java library. After downloading it, compile it using mvn clean install

Then, update your project's pom.xml file dependencies, as follows:

  <dependency>
      <groupId>com.github.krdev.imapnio</groupId>
      <artifactId>imapnio.core</artifactId>
      <version>2.0.0</version>
  </dependency>

Finally, import the relevant classes and use this library according to the usage section below.

  • For contributors run deploy to do a push to nexus servers
	$ mvn clean deploy -Dgpg.passphrase=[pathPhrase]

Usage

The following code examples demonstrate basic functionality relate to connecting to and communicating with IMAP servers.

Create a client

  // Create a ImapAsyncClient instance with number of threads to handle the server requests
  final int numOfThreadsServed = 5;
  final ImapAsyncClient imapClient = new ImapAsyncClient(numOfThreads);

Establish a session with an IMAP server

  // Create a new session via the ImapAsyncClient instance created above and connect to that server.  For the illustration purpose, 
  // "imaps://imap.server.com:993" is used
  final URI serverUri = new URI("imaps://imap.server.com:993");
  final ImapAsyncSessionConfig config = new ImapAsyncSessionConfig();
  config.setConnectionTimeoutMillis(5000);
  config.setReadTimeoutMillis(6000);
  final List<String> sniNames = null;

  final LogManager logManager = new LogManager(Level.DEBUG, LogPage.DEFAULT_SIZE);
  logManager.setLegacy(true);
  final InetSocketAddress localAddress = null;
  final Future<ImapAsyncSession> future = aclient.createSession(serverUri, config, localAddress, sniNames);
  
  //this version is a future-based nio client.  Check whether future is done by following code.
  if (future.isDone()) {
	System.out.println("Future is done.");
  }

Execute the IMAP command to IMAP server

Following codes uses a Capability command as an example.

  // Executes the capability command
  final Future<ImapAsyncResponse> capaCmdFuture = session.execute(new CapaCommand());

Handle the response from IMAP server

If the future of the executed command is done, obtain the response. Following example shows how to read ImapAsyncResponse which wraps the content sent from the server.

  if (capaCmdFuture.isDone()) {
	System.out.println("Capability command is done.");
	final ImapAsyncResponse resp = future.get(5, TimeUnit.MILLISECONDS);
	final ImapResponseMapper mapper = new ImapResponseMapper();
	final Capability capa = mapper.readValue(resp.getResponseLines().toArray(new IMAPResponse[0]), Capability.class);
	final List<String> values = capa.getCapability("AUTH");
  }

Release

This release, 2.0.x, is a major release. Changes are:

  • It supports non-blocking IO functionality through providing callers with java.util.concurrent.Future object.
  • Listener-based non-blocking IO capability will not be supported in this release.

Contribute

Please refer to the contributing.md for information about how to get involved. We welcome issues, questions, and pull requests. Pull Requests are welcome.

Maintainers

Luis Alves: [email protected]

License

This project is licensed under the terms of the Apache 2.0 open source license. Please refer to LICENSE for the full terms.

imapnio's People

Contributors

krdev avatar lafa avatar jui8wang avatar nituyahoo avatar squintview avatar jpowang avatar remk avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.