From: Vsevolod Stakhov Date: Sat, 24 Jun 2017 22:56:56 +0000 (+0100) Subject: [Fix] Use `\n` to fold headers for milter X-Git-Tag: 1.6.2~76 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=3c5de0377a4edaa6ad65043350688df189020de6;p=rspamd.git [Fix] Use `\n` to fold headers for milter --- diff --git a/src/libserver/protocol.c b/src/libserver/protocol.c index 6992307a2..6ccb83229 100644 --- a/src/libserver/protocol.c +++ b/src/libserver/protocol.c @@ -442,6 +442,10 @@ rspamd_protocol_handle_headers (struct rspamd_task *task, mta_name, NULL); debug_task ("read MTA-Name header, value: %s", mta_name); } + IF_HEADER (MILTER_HEADER) { + task->flags |= RSPAMD_TASK_FLAG_MILTER; + debug_task ("read Milter header, value: %V", hv); + } break; default: debug_task ("unknown header: %V", hn); @@ -1172,8 +1176,31 @@ rspamd_protocol_write_ucl (struct rspamd_task *task, RSPAMD_MEMPOOL_DKIM_SIGNATURE); if (dkim_sig) { - GString *folded_header = rspamd_header_value_fold ("DKIM-Signature", - dkim_sig->str, 80, task->nlines_type); + GString *folded_header; + + if (task->flags & RSPAMD_TASK_FLAG_MILTER) { + folded_header = rspamd_header_value_fold ("DKIM-Signature", + dkim_sig->str, 80, RSPAMD_TASK_NEWLINES_LF); + } + else { + folded_header = rspamd_header_value_fold ("DKIM-Signature", + dkim_sig->str, 80, task->nlines_type); + } + /* + * According to milter docs, we need to be extra careful + * when folding headers: + * Neither the name nor the value of the header is checked for standards + * compliance. However, each line of the header must be under 2048 + * characters and should be under 998 characters. + * If longer headers are needed, make them multi-line. + * To make a multi-line header, insert a line feed (ASCII 0x0a, or \n + * in C) followed by at least one whitespace character such as a + * space (ASCII 0x20) or tab (ASCII 0x09, or \t in C). + * The line feed should NOT be preceded by a carriage return (ASCII 0x0d); + * the MTA will add this automatically. + * It is the filter writer's responsibility to ensure that no s + * tandards are violated. + */ ucl_object_insert_key (top, ucl_object_fromstring_common (folded_header->str, folded_header->len, UCL_STRING_RAW), diff --git a/src/libserver/protocol_internal.h b/src/libserver/protocol_internal.h index 48c1c23f1..41ba13d86 100644 --- a/src/libserver/protocol_internal.h +++ b/src/libserver/protocol_internal.h @@ -79,5 +79,6 @@ #define TLS_CIPHER_HEADER "TLS-Cipher" #define TLS_VERSION_HEADER "TLS-Version" #define MTA_NAME_HEADER "MTA-Name" +#define MILTER_HEADER "Milter" #endif //RSPAMD_PROTOCOL_INTERNAL_H diff --git a/src/libserver/task.h b/src/libserver/task.h index cc1cc492a..16e40aad1 100644 --- a/src/libserver/task.h +++ b/src/libserver/task.h @@ -107,6 +107,7 @@ enum rspamd_task_stage { #define RSPAMD_TASK_FLAG_PROFILE (1 << 25) #define RSPAMD_TASK_FLAG_GREYLISTED (1 << 26) #define RSPAMD_TASK_FLAG_OWN_POOL (1 << 27) +#define RSPAMD_TASK_FLAG_MILTER (1 << 28) #define RSPAMD_TASK_IS_SKIPPED(task) (((task)->flags & RSPAMD_TASK_FLAG_SKIP)) #define RSPAMD_TASK_IS_JSON(task) (((task)->flags & RSPAMD_TASK_FLAG_JSON))