mailbox

    Bounded byte-stream mboxrd archive decoding, Maildir storage and MoonMIME integration

    Download zip
    Version
    0.10.0
    License
    MIT AND Apache-2.0
    Last updated
    last month
    Downloads
    30

    #可执行 API 示例

    增加 maildir flags 更新及规范化接口。这些例子调用公开 API,并随 moon test 执行。

    ///|
    test "Maildir flag updates preserve unique identity" {
    let n = @mailbox.parse_maildir_name("123.host")
    let updated = n.with_flags("RS")
    assert_eq(updated.unique, "123.host")
    assert_eq(updated.encode(), "123.host:2,RS")
    assert_true(
    try {
    ignore(n.with_flags("?"))
    false
    } catch {
    _ => true
    },
    )
    }

    本例只处理 Maildir 文件名;另有 Node Maildir 磁盘宿主,提供单 key 锁、文件同步和基于硬链接的不覆盖投递,见 README.md。该宿主面向用户掌控的私有目录,不保证外部程序遵守锁、目录 fsync、断电持久性或多操作事务;MoonBit MIME 解析也不是完整 MIME 兼容实现。

    MailboxError

    pub suberror MailboxError {
    Invalid(String)
    } derive(
    Debug
    )
    pub struct Header {
    name : String
    value : String
    } derive(Eq,
    Debug
    )

    Header::equal

    fn Header::equal(Header, Header) -> Bool

    Header::not_equal

    fn Header::not_equal(x : Header, y : Header) -> Bool

    Header::to_repr

    MaildirName

    pub(all) struct MaildirName {
    unique : String
    flags : String
    has_info : Bool
    } derive(Eq,
    Debug
    )

    MaildirName::encode

    fn MaildirName::encode(self : MaildirName) -> String raise MailboxError

    MaildirName::equal

    fn MaildirName::equal(MaildirName, MaildirName) -> Bool

    MaildirName::not_equal

    fn MaildirName::not_equal(x : MaildirName, y : MaildirName) -> Bool

    MaildirName::with_flags

    fn MaildirName::with_flags(self : MaildirName, flags : String) -> MaildirName raise MailboxError

    Return a canonical filename with the supplied standard Maildir flags.

    MboxrdDecoder

    pub struct MboxrdDecoder {
    // private fields
    }

    Incremental container decoder, independent of MIME. One 1MiB input chunk, one bounded line and one bounded message at a time; callers drain results.

    MboxrdDecoder::feed

    fn MboxrdDecoder::feed(self : MboxrdDecoder, chunk : Bytes) -> Array[RawMessage] raise MailboxError

    Results are complete records only. Any error poisons the entire decoder; previously returned records stay valid, but this call returns no partial array.

    MboxrdDecoder::finish

    Strict EOF: a nonempty partial line or a missing container blank is truncated. The empty mailbox returns [], and successful completion closes the decoder.

    MboxrdDecoder::new

    fn MboxrdDecoder::new(max_message_bytes? : Int, max_line_bytes? : Int) -> MboxrdDecoder raise MailboxError

    Budgets count DECODED content bytes and physical line bytes including LF. No whole-file size limit; offsets and record numbers use signed 64-bit ints.

    Message

    pub(all) struct Message {
    envelope : String
    content : String
    } derive(Eq,
    Debug
    )

    Message::equal

    fn Message::equal(Message, Message) -> Bool

    Message::not_equal

    fn Message::not_equal(x : Message, y : Message) -> Bool

    Message::to_repr

    MimePart

    pub struct MimePart {
    fields : Array[Header]
    media_type : String
    parameters : Map[String, String]
    body : Bytes
    children : Array[MimePart]
    } derive(
    Debug
    )

    MimePart::filename

    fn MimePart::filename(self : MimePart) -> String? raise MailboxError

    Returns display metadata only; never use the result directly as a filesystem path.

    MimePart::text

    fn MimePart::text(self : MimePart) -> String raise MailboxError

    MimePart::to_repr

    RawMessage

    pub struct RawMessage {
    number : Int64
    source_start : Int64
    source_end : Int64
    envelope : Bytes
    content : Bytes
    } derive(Eq,
    Debug
    )

    One completed mboxrd record. Source offsets include envelope/quoting/separator; content only removes reversible From quoting and ONE container blank line. Bytes are owned snapshots, never aliases into the decoder's mutable buffers.

    RawMessage::equal

    fn RawMessage::equal(RawMessage, RawMessage) -> Bool

    RawMessage::not_equal

    fn RawMessage::not_equal(x : RawMessage, y : RawMessage) -> Bool

    decode_charset

    fn decode_charset(data : Bytes, charset : String) -> String raise MailboxError

    Decode explicitly supported MIME charsets; unsupported charsets never silently corrupt text.

    decode_header

    fn decode_header(value : String) -> String raise MailboxError

    Decode an unstructured header/display phrase. Not an address parser or wire encoder.

    decode_transfer

    fn decode_transfer(data : Bytes, encoding : String) -> Bytes raise MailboxError

    encode_mboxrd

    fn encode_mboxrd(messages : Array[Message]) -> String raise MailboxError

    header_values

    fn header_values(content : String, name : String) -> Array[String] raise MailboxError

    headers

    fn headers(content : String) -> Array[Header] raise MailboxError

    Ordered duplicate-preserving RFC-style header extraction; no MIME decoding.

    parse_maildir_name

    fn parse_maildir_name(name : String) -> MaildirName raise MailboxError

    parse_mboxrd

    fn parse_mboxrd(source : String) -> Array[Message] raise MailboxError

    mboxrd text codec. Content is normalized to LF and one final LF. One blank separator line is removed between messages; MIME bytes are not decoded.

    parse_mime

    fn parse_mime(data : Bytes) -> MimePart raise MailboxError

    parse_mime_parameters

    fn parse_mime_parameters(text : String) -> (String, Map[String, String]) raise MailboxError