diff options
author | Runxi Yu <me@runxiyu.org> | 2025-01-15 20:13:41 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2025-01-15 20:14:01 +0800 |
commit | 9e28e23c2c514ecec4a67e900c378691b427edcd (patch) | |
tree | 208ba24d579495fbfd4eb583e44ffed6ae7ec89f /serve_mx.go | |
parent | Note in config to add TLS listeners for IMAP (diff) | |
download | maild-9e28e23c2c514ecec4a67e900c378691b427edcd.tar.gz maild-9e28e23c2c514ecec4a67e900c378691b427edcd.tar.zst maild-9e28e23c2c514ecec4a67e900c378691b427edcd.zip |
Put mx side parsing code into a block
Diffstat (limited to '')
-rw-r--r-- | serve_mx.go | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/serve_mx.go b/serve_mx.go index 8911486..b8e6d44 100644 --- a/serve_mx.go +++ b/serve_mx.go @@ -49,25 +49,28 @@ func (session *mx_recv_session) handle(ctx context.Context) error { _ = session.buf_conn.Flush() session.server_state = mx_server_state_begin for { - line, err := session.buf_conn.ReadString('\n') - if err != nil { - if err == io.EOF { - return err_connection_handler_eof + var cmd, param string + { + line, err := session.buf_conn.ReadString('\n') + if err != nil { + if err == io.EOF { + return err_connection_handler_eof + } + return err } - return err - } - line = strings.TrimSuffix(line, "\n") - line = strings.TrimSuffix(line, "\r") - cmd_end := strings.IndexByte(line, ' ') - var param_start int - if cmd_end == -1 { - cmd_end = len(line) - param_start = len(line) - } else { - param_start = cmd_end + 1 + line = strings.TrimSuffix(line, "\n") + line = strings.TrimSuffix(line, "\r") + cmd_end := strings.IndexByte(line, ' ') + var param_start int + if cmd_end == -1 { + cmd_end = len(line) + param_start = len(line) + } else { + param_start = cmd_end + 1 + } + cmd = strings.ToUpper(line[:cmd_end]) + param = line[param_start:] } - cmd := strings.ToUpper(line[:cmd_end]) - param := line[param_start:] switch_cmd: switch cmd { case "STARTTLS": |