From 5079850140ad53d2cdb2395c90cb65061249579c Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Thu, 16 Jan 2025 08:56:18 +0800 Subject: parse_{smtp,imap}_line --- serve_mx.go | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) (limited to 'serve_mx.go') diff --git a/serve_mx.go b/serve_mx.go index b8e6d44..f938c02 100644 --- a/serve_mx.go +++ b/serve_mx.go @@ -49,28 +49,14 @@ func (session *mx_recv_session) handle(ctx context.Context) error { _ = session.buf_conn.Flush() session.server_state = mx_server_state_begin for { - 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 - } - 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, err := session.buf_conn.ReadString('\n') + if err != nil { + if err == io.EOF { + return err_connection_handler_eof } - cmd = strings.ToUpper(line[:cmd_end]) - param = line[param_start:] + return err } + cmd, param := parse_smtp_line(line) switch_cmd: switch cmd { case "STARTTLS": -- cgit v1.2.3