pop3

    可接入任意传输层的增量响应解析与会话状态机

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

    #可执行 API 示例

    增加 STAT/LIST 的类型化响应读取和重复编号拒绝。这些例子调用公开 API,并随 moon test 执行。

    ///|
    test "typed STAT and LIST reply consumers" {
    let s = @pop3.Session::new()
    ignore(s.feed(b"+OK\r\n"))
    ignore(s.issue(@pop3.User("u")))
    ignore(s.feed(b"+OK\r\n"))
    ignore(s.issue(@pop3.Pass("p")))
    ignore(s.feed(b"+OK\r\n"))
    ignore(s.issue(@pop3.Stat))
    let r = s.feed(b"+OK 2 300\r\n")
    assert_eq(r[0].stat(), (2, 300))
    ignore(s.issue(@pop3.List(None)))
    let r = s.feed(b"+OK list\r\n1 100\r\n2 200\r\n.\r\n")
    assert_eq(r[0].listing(), [(1, 100), (2, 200)])
    }

    0.5 已提供 TCP/隐式 TLS/STLS、APOP/PLAIN 与 Dovecot 互通。TLS 的可信握手由 Node 宿主实现;核心状态示例见 tls_auth_test.mbt。仍缺其它 SASL、PIPELINING 和流式大邮件。

    PopError

    pub suberror PopError {
    Invalid(String)
    } derive(
    Debug
    )

    Command

    pub(all) enum Command {
    User(String)
    Pass(String)
    Apop(String, String)
    Capa
    Stls
    Auth(String)
    Stat
    List(Int?)
    Uidl(Int?)
    Retr(Int)
    Dele(Int)
    Top(Int, Int)
    Noop
    Rset
    Quit
    } derive(Eq,
    Debug
    )

    Command::encode

    fn Command::encode(self : Command) -> String raise PopError

    Phase

    pub(all) enum Phase {
    Greeting
    Authorization
    TlsHandshake
    Transaction
    Closed
    } derive(Eq,
    Debug
    )

    Reply

    pub struct Reply {
    ok : Bool
    message : String
    body : Bytes
    continuation : Bool
    } derive(Eq,
    Debug
    )

    Reply::listing

    fn Reply::listing(self : Reply) -> Array[(Int, Int)] raise PopError

    Parse the unstuffed multiline LIST body; reject duplicate message numbers.

    Reply::stat

    fn Reply::stat(self : Reply) -> (Int, Int) raise PopError

    Parse a positive STAT reply as message count and total octets.

    Session

    pub struct Session {
    // private fields
    } derive(
    Debug
    )

    Session::authenticate_response

    fn Session::authenticate_response(self : Session, response : String) -> String raise PopError

    Session::feed

    fn Session::feed(self : Session, input : Bytes) -> Array[Reply] raise PopError

    Session::finish

    fn Session::finish(self : Session) -> Unit raise PopError

    Session::issue

    fn Session::issue(self : Session, command : Command) -> String raise PopError

    Session::new

    fn Session::new() -> Session

    Session::phase

    fn Session::phase(self : Session) -> Phase

    Session::tls_established

    fn Session::tls_established(self : Session) -> Unit raise PopError

    Called by the transport only after a verified TLS handshake, never on STLS +OK alone.