@tribe-x/imap-server
v0.0.25
Published
IMAP server module for Node.js
Readme
imap-server
IMAP Server module for Nodejs forked from https://github.com/xpensia/ImapServer.
The goal of the fork is to add plugins, support unit tests, and modernize the codebase to ESM.
This project is inspired by Haraka a SMTP server for Nodejs. All features of an IMAP server are implemented as plugins, so it can adapt to many use cases.
Installation
npm install @tribe-x/imap-serverUsage
import ImapServer from '@tribe-x/imap-server';
import plugins from '@tribe-x/imap-server/plugins/index.js';
// create server handler
const serverHandler = new ImapServer();
// use built-in plugins
serverHandler.use(plugins.announce);
serverHandler.use(plugins.debug);
// ...use more builtin or custom plugins
const server = serverHandler.listen(1143, () => {
console.log("IMAP server listening on port 1143");
});Plugins
Built-in plugins
announce
Required by IMAP4rev1. This plugin also send the optional capability list.
starttls
Provide encrypted communication for IMAP via the STARTTLS command.
server.use(plugins.starttls, {
/* mandatory hash of options for crypto.createCredentials
* http://nodejs.org/api/crypto.html#crypto_crypto_createcredentials_details
* with at least key & cert
*/
key: Buffer.from('<PRIVATE_KEY>', 'utf8'),
cert: Buffer.from('<CERTIFICATE>', 'utf8')
});debug
This plugin log various information.
authentification helper
Here's how to implement auth plain without worrying about the underlying protocol:
import WrapAuthPlain from '@tribe-x/imap-server/util/auth_plain_wrapper.js';
const authPlainPlugin = WrapAuthPlain((connection, username, password, next) => {
if (username === '[email protected]' && password === 'foobar') {
next(null, 'OK');
} else {
next(null, 'NO');
}
});Notes
Default port : 143
SSL port : 993
rfc3501 (IMAP4rev1) : http://tools.ietf.org/html/rfc3501
return flags : OK, NO, BAD
getCapabilities ( connection ) Sync, return [cap, ...]
register
connection ( connection, next )
starttls ( next )
auth_* ( next )
unknown_command ( connection, line, next )
