Misuse-resistant IMAP Types
This crate provides common types, i.e., structs and enums, to support IMAP implementations.
It tries to become the "standard library" for IMAP in Rust that can be used as a common basis for a diverse set of IMAP
crates, such as parsers, serializers, clients, and servers.
If you are looking for a rock-solid IMAP "codec" implementation, i.e., parsers and serializers, that uses imap-types,
see imap-codec.
Features
- Rust's type system is used to enforce correctness and to make the library misuse-resistant. It's not possible to construct a message that violates the IMAP specification.
- Fuzzing (via cargo fuzz) and property-based tests are used to uncover bugs. The library is fuzz-tested never to produce an invalid message.
Working with imap-types
To ensure correctness, imap-types makes use of types such as AString, Atom, IString, Quoted, and Literal (from the core module). It's good to know these types because IMAP requires different message flows depending on how an information, such as a username or password is represented, e.g., as an atom or literal. When constructing messages, imap-types can automatically choose the best representation. However, it's always possible to manually choose a specific representation.
Examples
This ...
new.unwrap;
... will produce ...
A1 LOGIN alice password
However, ...
new
.unwrap;
... will produce ...
A1 LOGIN "alice\"" {2}
\xCA\xFE
Also, the construction ...
new.unwrap;
... will fail because IMAP doesn't allow NULL bytes in the username (nor password).
You can also use ...
new
.unwrap;
... to produce ...
A1 LOGIN {5}
alice password
... even though "alice" could be encoded more simply with an atom or quoted string.
Also, you can use Rust literals and resort to unchecked constructors when you are certain that your input is correct:
// This could be provided by the email application.
let tag = random;
Command ;
In this case, imap-codec won't stand in your way. However, it won't guarantee that you produce correct messages, either.
License
This crate is dual-licensed under Apache 2.0 and MIT terms.