Skip to content

Commit 421576b

Browse files
committed
Provide more information in README.
1 parent da87682 commit 421576b

File tree

1 file changed

+94
-13
lines changed

1 file changed

+94
-13
lines changed

README.md

Lines changed: 94 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,126 @@
11

22

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 supporting NIO (Non-blocking I/O) based IMAP client.
5+
6+
IMAP NIO client provides a framework to allow access to 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.
57

68

79
## Table of Contents
810

11+
- [Background](#background)
912
- [Install](#install)
13+
- [Configuration](#configuration)
1014
- [Usage](#usage)
1115
- [Contribute](#contribute)
1216
- [License](#license)
1317

18+
19+
## Background
20+
21+
Traditional accessing IMAP message store uses [JavaMail API](https://www.oracle.com/technetwork/java/javamail/index.html), which requires blocking I/O where a thread is blocked when performing I/O with the other end.This project was developed to allow for relieving the waiting thread to perform other tasks. This design efficiently improves the threads utilization and allows the consuming application to maximize the hardware throughput and capacity.
22+
23+
Following is a list of distinguishing features in this project:
24+
- Highly customizable thread model and server/client idle max limit.
25+
- Leverages the well-established framework - [Netty](https://netty.io/)
26+
- Future-based design enables a clean separation of IMAP client threads pool versus consumers threads pool.
27+
- IMAPv4, [RFC3501](https://tools.ietf.org/html/rfc3501) support.
28+
- ID command, [RFC2971](https://tools.ietf.org/html/rfc2971) support.
29+
- IDLE command, [RFC2177](https://tools.ietf.org/html/rfc2177) support
30+
- MOVE command, [RFC6851](https://tools.ietf.org/html/rfc6851) support
31+
- UNSELECT command, [RFC3691](https://tools.ietf.org/html/rfc3691) support
32+
33+
This project is ideal for applications that have a high requirement to optimize the threads utilization for improving its overall resource capacity. Mostly appropriate for consumers performing a great amount of sessions and communications with the IMAP server.
34+
35+
Following external references will establish the foundation for understanding this project:
36+
[Netty](https://netty.io/)
37+
[IMAP4rev1](https://tools.ietf.org/html/rfc3501)
38+
39+
1440
## Install
1541

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.
42+
If you've never used git before, please take a moment to familiarize yourself with [what it is and how it works](https://git-scm.com/book/en/v2/Getting-Started-Git-Basics). To install this project, you'll [need to have git installed and set up](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) on your local development environment.
43+
44+
Install by running the following command.
45+
46+
```
47+
git clone https://github.com/lafaspot/imapnio.git
48+
```
49+
50+
This will create a directory called imapnio and download the contents of this repo to it.
51+
52+
53+
## Configuration
54+
This is a Java library. After downloading it, compile it using the following command.
1755
$ mvn clean install
1856

19-
- For contibutors run deploy to do a push to nexus servers
20-
$ mvn clean deploy -Dgpg.passphrase=[pathPhrase]
57+
Then update your project's pom.xml file dependencies, as follows:
58+
```
59+
<dependency>
60+
<groupId>com.github.krdev.imapnio</groupId>
61+
<artifactId>imapnio.core</artifactId>
62+
<version>1.0.23</version>
63+
</dependency>
64+
```
65+
Finally, import the relevant classes and use this library according to the usage section below.
2166

67+
- For contributors run deploy to do a push to nexus servers
68+
```
69+
$ mvn clean deploy -Dgpg.passphrase=[pathPhrase]
70+
```
2271

2372
## Usage
2473

25-
Compile and use it as a regular IMAP client.
74+
Following code examples provide a list of usages on how to connect and communicate with any IMAP server.
75+
76+
### Create a client
77+
```java
78+
// Create a IMAPClient instance with number of threads to handle the server requests
79+
final int numOfThreadsServed = 5;
80+
final IMAPClient imapClient = new IMAPClient(numOfThreadsServed);
81+
```
82+
### Establish a session with an IMAP server
83+
```java
84+
// Create a new session via the imap client created above and connect to that server. For the illustration purpose,
85+
// "imaps://imap.server.com:993" is used
86+
final IMAPSession session = imapClient.createSession(new URI("imaps://imap.server.com:993"), new GenericListener(), new LogManager());
87+
// connect to the remote server
88+
session.connect();
89+
```
90+
91+
### Execute the IMAP command to IMAP server
92+
Following codes uses a Capability command as an example.
93+
94+
```java
95+
// Instantiates your own IMAPCommandListener instance
96+
final IMAPCommandListener listener = new MyOwnIMAPCommandListener();
97+
// fire CAPABILITY command with the tag name you want to track
98+
final String tagName = "A0001";
99+
session.executeCapabilityCommand(tagName, listener);
100+
```
101+
102+
### Handle the response from IMAP server
103+
onMessage() method will be called on the registered IMAPCommandListener.
104+
Following example shows how to read IMAPResponse sent from the server.
26105

27106
```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(...);
107+
@Override
108+
public void onMessage(final IMAPSession session, final IMAPResponse response) {
109+
System.out.println("Response from IMAPServer is==>tag:" + response.getTag() + ",getRest():"
110+
+ response.getRest() + ",toString():" + response.toString());
111+
}
34112
```
35113

114+
36115
## Contribute
37116

38117
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.
39118

119+
40120
## Maintainers
41121

42-
Luis Alves: (lafa at verizonmedia.com)
122+
Luis Alves: lafa@verizonmedia.com
123+
43124

44125
## License
45126

0 commit comments

Comments
 (0)