diff options
author | Runxi Yu <me@runxiyu.org> | 2025-01-16 12:34:46 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2025-01-16 16:33:17 +0800 |
commit | faf7c3566be12f22f346f978d3a5fcf68e4bc8b4 (patch) | |
tree | f1c1bb8c6ade70cb56295a116678293807838080 /serve_imap.go | |
parent | IMAP: Parse SASL (diff) | |
download | maild-faf7c3566be12f22f346f978d3a5fcf68e4bc8b4.tar.gz maild-faf7c3566be12f22f346f978d3a5fcf68e4bc8b4.tar.zst maild-faf7c3566be12f22f346f978d3a5fcf68e4bc8b4.zip |
IMAP: Re-add server protocol state
Diffstat (limited to 'serve_imap.go')
-rw-r--r-- | serve_imap.go | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/serve_imap.go b/serve_imap.go index 524f130..ad50c27 100644 --- a/serve_imap.go +++ b/serve_imap.go @@ -15,17 +15,28 @@ import ( "go.lindenii.runxiyu.org/lindenii-common/clog" ) +type imap_server_state_t uint + +const ( + imap_server_state_not_authenticated imap_server_state_t = iota + imap_server_state_authenticated + imap_server_state_selected + imap_server_state_logout +) + type imap_recv_session struct { buf_conn *bufio.ReadWriter net_conn net.Conn tls_conn *tls.Conn my_server_name string db *pgxpool.Pool + server_state imap_server_state_t } const IMAP_CAPABILITIES = "CAPABILITY IMAP4rev2 AUTH=PLAIN" func (session *imap_recv_session) handle(ctx context.Context) error { + session.server_state = imap_server_state_not_authenticated session.buf_conn = bufio.NewReadWriter(bufio.NewReader(session.net_conn), bufio.NewWriter(session.net_conn)) _, _ = session.buf_conn.WriteString("* OK [" + IMAP_CAPABILITIES + "] " + VERSION + "\r\n") _ = session.buf_conn.Flush() @@ -52,6 +63,11 @@ func (session *imap_recv_session) handle(ctx context.Context) error { _, _ = session.buf_conn.WriteString(tag + " OK CAPABILITY completed\r\n") _ = session.buf_conn.Flush() case "AUTHENTICATE": + if session.server_state != imap_server_state_authenticated { + _, _ = session.buf_conn.WriteString(line + " TODO you are already authenticated") + _ = session.buf_conn.Flush() + break switch_cmd + } space_that_ends_the_method := strings.IndexByte(param, ' ') method := param[:space_that_ends_the_method] switch method { @@ -74,7 +90,12 @@ func (session *imap_recv_session) handle(ctx context.Context) error { session.buf_conn.WriteString(" TODO need three sasl segments\r\n") break switch_cmd } - authcid, passwd := segments[1], segments[2] + authcid, passwd := string(segments[1]), string(segments[2]) + if authcid == "test" && passwd == "test" { // TODO + session.server_state = imap_server_state_authenticated + } else { + + } default: _, _ = session.buf_conn.WriteString(line + " TODO i don't know this authentication method\r\n") _ = session.buf_conn.Flush() |