diff options
author | Runxi Yu <me@runxiyu.org> | 2025-04-02 00:12:52 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2025-04-02 00:12:52 +0800 |
commit | 1c233292ad415779596e5d9d385759372b4245cd (patch) | |
tree | 178645adff0d7265d8ef2704a831af277dfbc220 | |
parent | LMTP: Return 550 on errors (diff) | |
download | forge-1c233292ad415779596e5d9d385759372b4245cd.tar.gz forge-1c233292ad415779596e5d9d385759372b4245cd.tar.zst forge-1c233292ad415779596e5d9d385759372b4245cd.zip |
LMTP: Add an SMTP request context
-rw-r--r-- | lmtp_server.go | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/lmtp_server.go b/lmtp_server.go index 2049231..998b53c 100644 --- a/lmtp_server.go +++ b/lmtp_server.go @@ -6,6 +6,7 @@ package main import ( "bytes" + "context" "errors" "fmt" "io" @@ -21,8 +22,10 @@ import ( type lmtpHandler struct{} type lmtpSession struct { - from string - to []string + from string + to []string + ctx context.Context + cancel context.CancelFunc } func (session *lmtpSession) Reset() { @@ -31,6 +34,7 @@ func (session *lmtpSession) Reset() { } func (session *lmtpSession) Logout() error { + session.cancel() return nil } @@ -49,7 +53,11 @@ func (session *lmtpSession) Rcpt(to string, _ *smtp.RcptOptions) error { } func (*lmtpHandler) NewSession(_ *smtp.Conn) (smtp.Session, error) { - session := &lmtpSession{} + ctx, cancel := context.WithCancel(context.Background()) + session := &lmtpSession{ + ctx: ctx, + cancel: cancel, + } return session, nil } |