diff options
Diffstat (limited to 'mx_recv.go')
-rw-r--r-- | mx_recv.go | 17 |
1 files changed, 8 insertions, 9 deletions
@@ -34,10 +34,9 @@ type mx_recv_session struct { current_mail_from string current_rcpt_to []string server_state server_state_t - ctx context.Context } -func (session *mx_recv_session) handle() error { +func (session *mx_recv_session) handle(ctx context.Context) error { session.buf_conn = bufio.NewReadWriter(bufio.NewReader(session.net_conn), bufio.NewWriter(session.net_conn)) config_consistent_run(func() { session.my_server_name = config.Server_name @@ -132,7 +131,7 @@ func (session *mx_recv_session) handle() error { } recipient_address, _, _ := mailkit.Strip_angle_brackets(param[len("TO:"):]) var count int - err := session.db.QueryRow(session.ctx, "SELECT COUNT (*) FROM addresses WHERE address = $1", recipient_address).Scan(&count) + err := session.db.QueryRow(ctx, "SELECT COUNT (*) FROM addresses WHERE address = $1", recipient_address).Scan(&count) if err != nil { _, _ = session.buf_conn.WriteString("451 Internal error: " + err.Error() + "\r\n") _ = session.buf_conn.Flush() @@ -184,13 +183,14 @@ func (session *mx_recv_session) handle() error { if err != nil { return err } - err = deliver_local(session.ctx, session.db, session.current_mail_from, session.current_rcpt_to, current_data, session.current_rcpt_to) + err = deliver_local(ctx, session.db, session.current_mail_from, session.current_rcpt_to, current_data, session.current_rcpt_to) var err_local_recipients_not_found *err_local_recipients_not_found_t - if errors.As(err, &err_local_recipients_not_found) { + switch { + case errors.As(err, &err_local_recipients_not_found): _, _ = session.buf_conn.WriteString("550 5.1.1 Recipient address rejected: " + err_local_recipients_not_found.Error() + "\r\n") - } else if err != nil { + case err != nil: _, _ = session.buf_conn.WriteString("500 2.0.0 Error: " + err.Error() + "\r\n") - } else { + default: _, _ = session.buf_conn.WriteString("250 2.0.0 Ok: Accepted\r\n") } _ = session.buf_conn.Flush() @@ -222,7 +222,6 @@ func (session *mx_recv_session) handle() error { func handle_mx_recv_conn(ctx context.Context, net_conn net.Conn) error { session := mx_recv_session{ net_conn: net_conn, - ctx: ctx, } - return session.handle() + return session.handle(ctx) } |