add dot-stuffing for SMTP DATA command (RFC 5321 §4.5.2)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-14 05:25:55 +01:00
parent 54ce92e280
commit c38c31bf4d

View File

@@ -82,9 +82,14 @@ struct SMTPCommandRunner {
throw SMTPError.sendFailed("DATA rejected: \(response.message)")
}
// Dot-stuff: lines starting with "." must be prefixed with an extra "."
// to prevent premature DATA termination (RFC 5321 §4.5.2)
let stuffed = content
.replacingOccurrences(of: "\r\n.", with: "\r\n..")
// sendCommand appends \r\n, so sending "content\r\n." produces "content\r\n.\r\n"
// which is the correct DATA termination sequence
let payload = content + "\r\n."
let payload = stuffed + "\r\n."
let dataResponse = try await connection.sendCommand(payload)
guard dataResponse.isSuccess else {