From 1c233292ad415779596e5d9d385759372b4245cd Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Wed, 02 Apr 2025 00:12:52 +0800 Subject: [PATCH] LMTP: Add an SMTP request context --- lmtp_server.go | 14 +++++++++++--- diff --git a/lmtp_server.go b/lmtp_server.go index 20492315372c2dd6cd1199056d6d55a23df88866..998b53c810fa0c5f30f9ccf46c0d189980576be3 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 @@ 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 @@ session.to = nil } func (session *lmtpSession) Logout() error { + session.cancel() return nil } @@ -49,7 +53,11 @@ return nil } 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 } -- 2.48.1