17 releases (1 stable)

new 2.0.0-alpha.4 Jul 23, 2024
2.0.0-alpha.1 Jun 7, 2024
1.0.0 Aug 22, 2023
0.10.0 Jul 5, 2023
0.2.2 Feb 22, 2021

#183 in Parser implementations

Download history 69/week @ 2024-04-03 80/week @ 2024-04-10 34/week @ 2024-04-17 42/week @ 2024-04-24 92/week @ 2024-05-01 55/week @ 2024-05-08 65/week @ 2024-05-15 61/week @ 2024-05-22 56/week @ 2024-05-29 163/week @ 2024-06-05 74/week @ 2024-06-12 57/week @ 2024-06-19 51/week @ 2024-06-26 35/week @ 2024-07-03 246/week @ 2024-07-10 219/week @ 2024-07-17

560 downloads per month
Used in 2 crates

MIT/Apache

1MB
16K SLoC

imap-codec

%%{init: {'theme': 'neutral' } }%%
flowchart LR
    imap-types --> imap-codec
    imap-codec -.-> imap-next
    imap-next -.-> imap-proxy
    imap-next -.-> imap-client
    
    style imap-codec stroke-width:4px
    
    click imap-types href "https://github.com/duesee/imap-codec/tree/main/imap-types"
    click imap-codec href "https://github.com/duesee/imap-codec"
    click imap-next href "https://github.com/duesee/imap-next"
    click imap-proxy href "https://github.com/duesee/imap-proxy"
    click imap-client href "https://github.com/soywod/imap-client"

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.

If you are looking for thin protocol handling, i.e., LITERAL handling, AUTHENTICATE, and IDLE, head over to imap-next.

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::{decode::Decoder, encode::Encoder, CommandCodec};

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

    let codec = CommandCodec::new();
    let (remainder, command) = codec.decode(input).unwrap();
    println!("# Parsed\n\n{:#?}\n\n", command);

    let buffer = codec.encode(&command).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.5–3.5MB
~68K SLoC