npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

imap-core

v1.0.0

Published

IMAP server constructor

Downloads

11

Readme

imap-core

Node.js module to create custom IMAP servers.

This is something I have used mostly for client work as the lower level dependency for some specific application that servers IMAP. I don't have any such clients right no so I published the code if anyone finds it useful. I removed all proprietary code developed for clients, the module is only about the lower level protocol usage and does not contain any actual server logic.

You can see an example implementation of an IMAP server from the example script. Most of the code is inherited from the Hoodiecrow test-IMAP server module but this module can be used for asynchronous data access while in Hoodiecrow everything was synchronous (storage was an in-memory object that was accessed and updated synchronously).

Demo

Install dependencies

npm install

Run the example

node examples/index.js

Connect to the server on port 9993

openssl s_client -crlf -connect localhost:9993

Once connected use testuser:pass to log in

< * OK test ready
> A LOGIN testuser pass
< A OK testuser authenticated

IMAP extension support

This project is going to support only selected extensions, that are minimally required.

Sequence number handling

Sequence numbers are handled automatically, no need to do this in the application side – you only need to keep count of the incrementing UID's. All sequence number based operations are converted to use UID values instead.

Handling large input

Unfortunately input handling for a single command is not stream based, so everything sent to the server is loaded into memory before being processed. Literal size can be limited though and in this case the server refuses to process literals bigger than configured size.

SEARCH query

Search query is provided as a tree structure.

Possible SEARCH terms

  • Array – a list of AND terms
  • or - in the form of {key: 'or', value: [terms]} where terms is a list of OR terms
  • not - inverts another term. In the form of {key: 'not', value: term} where term is the term that must be inverted
  • flag - describes a flag term. In the form of {key: 'flag', value: 'term', exists: bool} where term is the flag name to look for and bool indicates if the flag must be bresent (true) or missing (false)
  • header - describes a header value. Header key is a case insensitive exact match (eg. 'X-Foo' matches header 'X-Foo:' but not 'X-Fooz:'). Header value is a partial match. In the form of {key: 'header', header: 'keyterm', value: 'valueterm'} where keyterm is the header key name and valueterm is the value of the header. If value is empty then the query acts as boolean, if header key is present, then it matches, otherwise it does not match
  • uid - is a an array of UID values (numbers)
  • all - if present then indicates that all messages should match
  • internaldate - operates on the date the message was received. Date value is day based, so timezone and time should be discarded. In the form of {key: 'internaldate', operator: 'op', value: 'val'} where op is one of '<', '=', '>=' and val is a date string
  • date - operates on the date listed in the massage Date: header. Date value is day based, so timezone and time should be discarded. In the form of {key: 'date', operator: 'op', value: 'val'} where op is one of '<', '=', '>=' and val is a date string
  • body - looks for a partial match in the message BODY (does not match header fields). In the form of {key: 'body', value: 'term'} where term is the partial match to look for
  • text - looks for a partial match in the entire message, including the body and headers. In the form of {key: 'text', value: 'term'} where term is the partial match to look for
  • size - matches message size. In the form of {key: 'size', value: num, operator: 'op'} where op is one of '<', '=', '>' and num is the size of the message
  • charset - sets the charset to be used in the text fields. Can be ignored as everything should be UTF-8 by default

Currently implemented RFC3501 commands

  • APPEND
  • CAPABILITY
  • CHECK
  • CLOSE
  • COPY
  • CREATE
  • DELETE
  • EXPUNGE
  • FETCH
  • LIST
  • LOGIN
  • LOGOUT
  • LSUB
  • NOOP
  • RENAME
  • SEARCH
  • SELECT
  • STARTTLS
  • STATUS
  • STORE
  • SUBSCRIBE
  • UID COPY
  • UID STORE
  • UNSUBSCRIBE

Extensions

  • Conditional STORE rfc4551 and ENABLE
  • Special-Use Mailboxes rfc6154
  • ID extension rfc2971
  • IDLE command rfc2177
  • NAMESPACE rfc2342 (hard coded single user namespace)
  • UNSELECT rfc3691
  • AUTHENTICATE PLAIN and SASL-IR

Unlike the Hoodiecrow project you can not enable or disable extensions, everything is as it is.