From 939938adc794de9a821b732a4bdc737544d3398d Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Fri, 19 May 2017 16:45:31 +0100 Subject: [PATCH] [Fix] Fix brain-damaged spamc protocol for now --- src/libutil/http.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/libutil/http.c b/src/libutil/http.c index 24c5e730c..e5ff95f32 100644 --- a/src/libutil/http.c +++ b/src/libutil/http.c @@ -1813,10 +1813,25 @@ rspamd_http_message_write_header (const gchar* mime_type, gboolean encrypted, else { /* Legacy spamd reply */ if (msg->flags & RSPAMD_HTTP_FLAG_SPAMC) { + gsize real_bodylen; + goffset eoh_pos; + GString tmp; + + /* Unfortunately, spamc protocol is deadly brain damaged */ + tmp.str = (gchar *)msg->body_buf.begin; + tmp.len = msg->body_buf.len; + + if (rspamd_string_find_eoh (&tmp, &eoh_pos) != -1 && + bodylen > eoh_pos) { + real_bodylen = bodylen - eoh_pos; + } + else { + real_bodylen = bodylen; + } + rspamd_printf_fstring (buf, "SPAMD/1.1 0 EX_OK\r\n" - "Content-length: %z\r\n" - "\r\n", - bodylen); + "Content-length: %z\r\n", + real_bodylen); } else { rspamd_printf_fstring (buf, "RSPAMD/1.3 0 EX_OK\r\n"); -- 2.39.5