aboutsummaryrefslogtreecommitdiff
path: root/mx_recv.go
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-01-12 18:25:01 +0800
committerRunxi Yu <me@runxiyu.org>2025-01-12 18:25:01 +0800
commit355f9fa1ad82afbc3880239baaff43375fb47372 (patch)
tree4a61a8f8e0fbf70b5116902278118ca14eb7ac92 /mx_recv.go
parentRestructure mta_recv -> mx_recv (diff)
downloadmaild-355f9fa1ad82afbc3880239baaff43375fb47372.tar.gz
maild-355f9fa1ad82afbc3880239baaff43375fb47372.tar.zst
maild-355f9fa1ad82afbc3880239baaff43375fb47372.zip
Put server_state in the session struct
Diffstat (limited to 'mx_recv.go')
-rw-r--r--mx_recv.go23
1 files changed, 12 insertions, 11 deletions
diff --git a/mx_recv.go b/mx_recv.go
index bcba494..f79ff6e 100644
--- a/mx_recv.go
+++ b/mx_recv.go
@@ -31,6 +31,7 @@ type mx_recv_session struct {
remote_server_name string
current_mail_from string
current_rcpt_to []string
+ server_state server_state_t
// ctx context.Context
}
@@ -43,7 +44,7 @@ func (session *mx_recv_session) handle() error {
})
_, _ = session.buf_conn.WriteString("220 " + session.my_server_name + " " + VERSION + "\r\n")
_ = session.buf_conn.Flush()
- server_state := server_state_begin
+ session.server_state = server_state_begin
for {
line, err := session.buf_conn.ReadString('\n')
if err != nil {
@@ -78,7 +79,7 @@ func (session *mx_recv_session) handle() 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))
- server_state = server_state_begin
+ session.server_state = server_state_begin
session.current_mail_from = ""
session.current_rcpt_to = []string{""}
case "HELO":
@@ -89,11 +90,11 @@ func (session *mx_recv_session) handle() error {
}
session.remote_server_name = param
_ = session.remote_server_name // TODO
- server_state = server_state_helo
+ session.server_state = server_state_helo
_, _ = session.buf_conn.WriteString("250 " + session.my_server_name + "\r\n")
_ = session.buf_conn.Flush()
case "MAIL":
- switch server_state {
+ switch session.server_state {
case server_state_begin:
_, _ = session.buf_conn.WriteString("503 5.5.1 Error: send HELO/EHLO first\r\n")
_ = session.buf_conn.Flush()
@@ -112,12 +113,12 @@ func (session *mx_recv_session) handle() error {
}
session.current_mail_from = param[len("FROM:"):]
session.current_rcpt_to = []string{}
- server_state = server_state_mail
+ session.server_state = server_state_mail
_, _ = session.buf_conn.WriteString("250 2.1.0 Ok\r\n")
_ = session.buf_conn.Flush()
// TODO: Address validation
case "RCPT":
- if server_state != server_state_mail && server_state != server_state_rcpt {
+ if session.server_state != server_state_mail && session.server_state != server_state_rcpt {
_, _ = session.buf_conn.WriteString("503 5.5.1 Error: need MAIL command\r\n")
_ = session.buf_conn.Flush()
break
@@ -135,11 +136,11 @@ func (session *mx_recv_session) handle() error {
break switch_cmd
}
session.current_rcpt_to = append(session.current_rcpt_to, recipient)
- server_state = server_state_rcpt
+ session.server_state = server_state_rcpt
_, _ = session.buf_conn.WriteString("250 2.1.5 Ok\r\n")
_ = session.buf_conn.Flush()
case "DATA":
- if server_state != server_state_rcpt {
+ if session.server_state != server_state_rcpt {
_, _ = session.buf_conn.WriteString("503 5.5.1 Error: need RCPT command\r\n")
_ = session.buf_conn.Flush()
break
@@ -195,7 +196,7 @@ func (session *mx_recv_session) handle() error {
_, _ = session.buf_conn.WriteString("500 2.0.0 Error: " + err.Error() + "\r\n")
}
_ = session.buf_conn.Flush()
- server_state = server_state_helo
+ session.server_state = server_state_helo
case "QUIT":
_, _ = session.buf_conn.WriteString("221 2.0.0 Bye\r\n")
_ = session.buf_conn.Flush()
@@ -204,8 +205,8 @@ func (session *mx_recv_session) handle() error {
_, _ = session.buf_conn.WriteString("250 2.0.0 Ok\r\n")
_ = session.buf_conn.Flush()
case "RSET":
- if server_state != server_state_begin {
- server_state = server_state_helo
+ if session.server_state != server_state_begin {
+ session.server_state = server_state_helo
}
_, _ = session.buf_conn.WriteString("250 2.0.0 Ok\r\n")
_ = session.buf_conn.Flush()