mailbox

    邮箱文本归档和 Maildir 文件名状态解析

    Download zip
    Version
    0.6.0
    License
    MIT
    Last updated
    5 hours ago
    Downloads
    1

    #可执行 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
    )

    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::with_flags

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

    Return a canonical filename with the supplied standard Maildir flags.

    Message

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

    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

    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