13 releases (1 stable)

1.0.0 Aug 22, 2023
0.10.0 Jul 5, 2023
0.7.0 Aug 5, 2022
0.6.0 Jun 14, 2022
0.2.2 Feb 22, 2021

#38 in Email

Download history 79/week @ 2023-11-20 47/week @ 2023-11-27 79/week @ 2023-12-04 59/week @ 2023-12-11 14/week @ 2023-12-18 88/week @ 2023-12-25 21/week @ 2024-01-01 36/week @ 2024-01-08 40/week @ 2024-01-15 14/week @ 2024-01-22 14/week @ 2024-01-29 37/week @ 2024-02-05 58/week @ 2024-02-12 52/week @ 2024-02-19 53/week @ 2024-02-26 48/week @ 2024-03-04

219 downloads per month
Used in melib

MIT/Apache

640KB
13K SLoC

imap-codec

This library provides parsing and serialization for IMAP4rev1 implementations. It is based on imap-types and a rock-solid and well-documented building block for IMAP client and server implementations in Rust. The complete formal syntax of IMAP4rev1 and several IMAP extensions are implemented.

Features

  • Parsing works in streaming mode. Incomplete is returned when there is insufficient data to make a final decision. No message will be truncated.
  • Parsing is zero-copy by default. Allocation is avoided during parsing, but all messages can explicitly be converted into more flexible owned variants.
  • Fuzzing and property-based tests exercise the library. The library is fuzz-tested never to produce a message it can't parse itself.

Usage

use imap_codec::{
    codec::{Decode, Encode},
    command::Command,
};

fn main() {
    let input = b"ABCD UID FETCH 1,2:* (BODY.PEEK[1.2.3.4.MIME]<42.1337>)\r\n";

    let (remainder, parsed) = Command::decode(input).unwrap();
    println!("# Parsed\n\n{:#?}\n\n", parsed);

    let buffer = parsed.encode().dump();

    // Note: IMAP4rev1 may produce messages that are not valid UTF-8.
    println!("# Serialized\n\n{:?}", std::str::from_utf8(&buffer));
}

License

This crate is dual-licensed under Apache 2.0 and MIT terms.

Dependencies

~2.4–3.5MB
~64K SLoC