From f20915ff338cf4b1fab05d900df3eac6234522a6 Mon Sep 17 00:00:00 2001 From: michael Date: Wed, 10 Sep 2025 20:00:34 +0200 Subject: [PATCH] fix(smtp): add missing headers to prevent spam classification Add required SMTP headers to fix spam classification issues: - Message-ID: generated from timestamp and from_address domain - MIME-Version: 1.0 header for proper email formatting - Content-Transfer-Encoding: 8bit for UTF-8 content Fixes rspamd spam score from 10.42/10.00 (reject) to 4.80/10.00 (clean) by resolving MISSING_MID (-2.50), MISSING_MIME_VERSION (-2.00), and R_BAD_CTE_7BIT (-1.05) penalties. Tested with mail-tester.com (10/10 score) and production deployment on tiamat shows successful delivery to inbox instead of spam folder. Related DAW/infrastruktur#35 --- src/smtp.lua | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/smtp.lua b/src/smtp.lua index 4c08b97..a3340a8 100644 --- a/src/smtp.lua +++ b/src/smtp.lua @@ -1,6 +1,6 @@ --- furt-lua/src/smtp.lua +-- src/smtp.lua -- Universal SMTP implementation with SSL compatibility --- Supports both luaossl (Arch/karl) and luasec (OpenBSD/walter) +-- Supports both luaossl (Arch) and luasec (OpenBSD) -- Dragons@Work Digital Sovereignty Project local socket = require("socket") @@ -304,6 +304,11 @@ function SMTP:send_email(to_address, subject, message, from_name) return cleanup_and_fail("DATA command failed: " .. response) end + -- Generate unique Message-ID + -- Extract domain from configured from_address + local hostname = self.from_address:match("@(.+)") or self.server + local message_id = string.format("<%d.%d@%s>", os.time(), math.random(10000), hostname) + -- Build email message local display_name = from_name or "Furt Contact Form" local email_content = string.format( @@ -311,7 +316,10 @@ function SMTP:send_email(to_address, subject, message, from_name) "To: <%s>\r\n" .. "Subject: %s\r\n" .. "Date: %s\r\n" .. + "Message-ID: %s\r\n" .. + "MIME-Version: 1.0\r\n" .. "Content-Type: text/plain; charset=UTF-8\r\n" .. + "Content-Transfer-Encoding: 8bit\r\n" .. "\r\n" .. "%s\r\n" .. ".", @@ -320,6 +328,7 @@ function SMTP:send_email(to_address, subject, message, from_name) to_address, subject, os.date("%a, %d %b %Y %H:%M:%S %z"), + message_id, message )