|
1 | 1 |
|
2 | 2 |
|
3 | | -# IMAP NIO client in Java |
4 | | -Java IMAP nio client that is designed to scale well for thousands of connections per machine and reduce contention when using large number of threads and cpus. |
| 3 | +# imapnio |
| 4 | +A Java library that supports NIO (Non-blocking I/O) based IMAP clients. |
| 5 | + |
| 6 | +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. |
5 | 7 |
|
6 | 8 |
|
7 | 9 | ## Table of Contents |
8 | 10 |
|
| 11 | +- [Background](#background) |
9 | 12 | - [Install](#install) |
10 | 13 | - [Usage](#usage) |
11 | 14 | - [Contribute](#contribute) |
12 | 15 | - [License](#license) |
13 | 16 |
|
| 17 | + |
| 18 | +## Background |
| 19 | + |
| 20 | +The traditional accessing IMAP message store uses [JavaMail API](https://www.oracle.com/technetwork/java/javamail/index.html), 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. |
| 21 | + |
| 22 | +Some of the more distinguishing features of this library are: |
| 23 | +- Highly customizable thread model and server/client idle max limit. |
| 24 | +- Leverages the well-established framework [Netty](https://netty.io/) |
| 25 | +- Future-based design enables a clean separation of IMAP client threads pool versus consumers threads pool. |
| 26 | +- IMAPv4, [RFC3501](https://tools.ietf.org/html/rfc3501) support. |
| 27 | +- ID command, [RFC2971](https://tools.ietf.org/html/rfc2971) support. |
| 28 | +- IDLE command, [RFC2177](https://tools.ietf.org/html/rfc2177) support |
| 29 | +- MOVE command, [RFC6851](https://tools.ietf.org/html/rfc6851) support |
| 30 | +- UNSELECT command, [RFC3691](https://tools.ietf.org/html/rfc3691) support |
| 31 | + |
| 32 | +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. |
| 33 | + |
14 | 34 | ## Install |
15 | 35 |
|
16 | | -This is packaged as a java library and can be imported as maven or gradle dependency in your project. There are no special installation instructions. |
17 | | -$ mvn clean install |
| 36 | +This is a Java library. After downloading it, compile it using `mvn clean install` |
18 | 37 |
|
19 | | -- For contibutors run deploy to do a push to nexus servers |
20 | | -$ mvn clean deploy -Dgpg.passphrase=[pathPhrase] |
| 38 | +Then, update your project's pom.xml file dependencies, as follows: |
| 39 | +``` |
| 40 | + <dependency> |
| 41 | + <groupId>com.github.krdev.imapnio</groupId> |
| 42 | + <artifactId>imapnio.core</artifactId> |
| 43 | + <version>1.0.23</version> |
| 44 | + </dependency> |
| 45 | +``` |
| 46 | +Finally, import the relevant classes and use this library according to the usage section below. |
21 | 47 |
|
| 48 | +- For contributors run deploy to do a push to nexus servers |
| 49 | +``` |
| 50 | +$ mvn clean deploy -Dgpg.passphrase=[pathPhrase] |
| 51 | +``` |
22 | 52 |
|
23 | 53 | ## Usage |
24 | 54 |
|
25 | | -Compile and use it as a regular IMAP client. |
| 55 | +The following code examples demonstrate basic functionality relate to connecting to and communicating with IMAP servers. |
| 56 | + |
| 57 | +### Create a client |
| 58 | +```java |
| 59 | + // Create a IMAPClient instance with number of threads to handle the server requests |
| 60 | + final int numOfThreadsServed = 5; |
| 61 | + final IMAPClient imapClient = new IMAPClient(numOfThreadsServed); |
| 62 | +``` |
| 63 | +### Establish a session with an IMAP server |
| 64 | +```java |
| 65 | + // Create a new session via the imap client created above and connect to that server. For the illustration purpose, |
| 66 | + // "imaps://imap.server.com:993" is used |
| 67 | + final IMAPSession session = imapClient.createSession(new URI("imaps://imap.server.com:993"), new GenericListener(), new LogManager()); |
| 68 | + // connect to the remote server |
| 69 | + session.connect(); |
| 70 | +``` |
| 71 | + |
| 72 | +### Execute the IMAP command to IMAP server |
| 73 | +Following codes uses a Capability command as an example. |
| 74 | + |
| 75 | +```java |
| 76 | + // Instantiates your own IMAPCommandListener instance |
| 77 | + final IMAPCommandListener listener = new MyOwnIMAPCommandListener(); |
| 78 | + // fire CAPABILITY command with the tag name you want to track |
| 79 | + final String tagName = "A0001"; |
| 80 | + session.executeCapabilityCommand(tagName, listener); |
| 81 | +``` |
| 82 | + |
| 83 | +### Handle the response from IMAP server |
| 84 | +onMessage() method will be called on the registered IMAPCommandListener. |
| 85 | +Following example shows how to read IMAPResponse sent from the server. |
26 | 86 |
|
27 | 87 | ```java |
28 | | - // Create a new session |
29 | | - final IMAPSession session = theClient.createSession(new URI("imaps://imap.server.com:993"), new GenericListener(), logManager); |
30 | | - // connect to the remote server |
31 | | - session.connect(); |
32 | | - // fire OAUTH2 command |
33 | | - session.executeOAuth2Command(...); |
| 88 | + @Override |
| 89 | + public void onMessage(final IMAPSession session, final IMAPResponse response) { |
| 90 | + System.out.println("Response from IMAPServer is==>tag:" + response.getTag() + ",getRest():" |
| 91 | + + response.getRest() + ",toString():" + response.toString()); |
| 92 | + } |
34 | 93 | ``` |
35 | 94 |
|
| 95 | + |
36 | 96 | ## Contribute |
37 | 97 |
|
38 | 98 | Please refer to the [contributing.md](Contributing.md) for information about how to get involved. We welcome issues, questions, and pull requests. Pull Requests are welcome. |
39 | 99 |
|
| 100 | + |
40 | 101 | ## Maintainers |
41 | 102 |
|
42 | | -Luis Alves: (lafa at verizonmedia.com) |
| 103 | +Luis Alves: lafa@verizonmedia.com |
| 104 | + |
43 | 105 |
|
44 | 106 | ## License |
45 | 107 |
|
|
0 commit comments