diff options
-rw-r--r-- | serve_mx.go | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/serve_mx.go b/serve_mx.go index 4909644..8911486 100644 --- a/serve_mx.go +++ b/serve_mx.go @@ -16,13 +16,13 @@ import ( "go.lindenii.runxiyu.org/lindenii-common/mailkit" ) -type server_state_t uint +type mx_server_state_t uint const ( - server_state_begin server_state_t = iota - server_state_helo - server_state_mail - server_state_rcpt + mx_server_state_begin mx_server_state_t = iota + mx_server_state_helo + mx_server_state_mail + mx_server_state_rcpt ) type mx_recv_session struct { @@ -35,7 +35,7 @@ type mx_recv_session struct { remote_server_name string current_mail_from string current_rcpt_to []string - server_state server_state_t + server_state mx_server_state_t } func (session *mx_recv_session) handle(ctx context.Context) error { @@ -47,7 +47,7 @@ func (session *mx_recv_session) handle(ctx context.Context) error { }) _, _ = session.buf_conn.WriteString("220 " + session.my_server_name + " " + VERSION + "\r\n") _ = session.buf_conn.Flush() - session.server_state = server_state_begin + session.server_state = mx_server_state_begin for { line, err := session.buf_conn.ReadString('\n') if err != nil { @@ -85,7 +85,7 @@ func (session *mx_recv_session) handle(ctx context.Context) error { _ = session.buf_conn.Flush() session.tls_conn = tls.Server(session.net_conn, session.tls_config) session.buf_conn = bufio.NewReadWriter(bufio.NewReader(session.tls_conn), bufio.NewWriter(session.tls_conn)) - session.server_state = server_state_begin + session.server_state = mx_server_state_begin session.current_mail_from = "" session.current_rcpt_to = []string{""} case "HELO": @@ -96,18 +96,18 @@ func (session *mx_recv_session) handle(ctx context.Context) error { } session.remote_server_name = param _ = session.remote_server_name // TODO - session.server_state = server_state_helo + session.server_state = mx_server_state_helo _, _ = session.buf_conn.WriteString("250 " + session.my_server_name + "\r\n") _ = session.buf_conn.Flush() case "MAIL": switch session.server_state { - case server_state_begin: + case mx_server_state_begin: _, _ = session.buf_conn.WriteString("503 5.5.1 Error: send HELO/EHLO first\r\n") _ = session.buf_conn.Flush() break switch_cmd - case server_state_helo: + case mx_server_state_helo: break - case server_state_mail: + case mx_server_state_mail: _, _ = session.buf_conn.WriteString("503 5.5.1 Error: nested MAIL command\r\n") _ = session.buf_conn.Flush() break switch_cmd @@ -119,12 +119,12 @@ func (session *mx_recv_session) handle(ctx context.Context) error { } session.current_mail_from = param[len("FROM:"):] session.current_rcpt_to = []string{} - session.server_state = server_state_mail + session.server_state = mx_server_state_mail _, _ = session.buf_conn.WriteString("250 2.1.0 Ok\r\n") _ = session.buf_conn.Flush() // TODO: Address validation case "RCPT": - if session.server_state != server_state_mail && session.server_state != server_state_rcpt { + if session.server_state != mx_server_state_mail && session.server_state != mx_server_state_rcpt { _, _ = session.buf_conn.WriteString("503 5.5.1 Error: need MAIL command\r\n") _ = session.buf_conn.Flush() break @@ -148,11 +148,11 @@ func (session *mx_recv_session) handle(ctx context.Context) error { break } session.current_rcpt_to = append(session.current_rcpt_to, recipient_address) - session.server_state = server_state_rcpt + session.server_state = mx_server_state_rcpt _, _ = session.buf_conn.WriteString("250 2.1.5 Ok\r\n") _ = session.buf_conn.Flush() case "DATA": - if session.server_state != server_state_rcpt { + if session.server_state != mx_server_state_rcpt { _, _ = session.buf_conn.WriteString("503 5.5.1 Error: need RCPT command\r\n") _ = session.buf_conn.Flush() break @@ -199,7 +199,7 @@ func (session *mx_recv_session) handle(ctx context.Context) error { _, _ = session.buf_conn.WriteString("250 2.0.0 Ok: Accepted\r\n") } _ = session.buf_conn.Flush() - session.server_state = server_state_helo + session.server_state = mx_server_state_helo case "QUIT": _, _ = session.buf_conn.WriteString("221 2.0.0 Bye\r\n") _ = session.buf_conn.Flush() @@ -212,8 +212,8 @@ func (session *mx_recv_session) handle(ctx context.Context) error { _, _ = session.buf_conn.WriteString("250 2.0.0 Ok\r\n") _ = session.buf_conn.Flush() case "RSET": - if session.server_state != server_state_begin { - session.server_state = server_state_helo + if session.server_state != mx_server_state_begin { + session.server_state = mx_server_state_helo } _, _ = session.buf_conn.WriteString("250 2.0.0 Ok\r\n") _ = session.buf_conn.Flush() |