]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Use `\n` to fold headers for milter
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 24 Jun 2017 22:56:56 +0000 (23:56 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 24 Jun 2017 22:56:56 +0000 (23:56 +0100)
src/libserver/protocol.c
src/libserver/protocol_internal.h
src/libserver/task.h

index 6992307a22c901cbcaa9cb7d2ea2792bc7a72e44..6ccb832298501ad900cd7a4be3a58a82f87a3563 100644 (file)
@@ -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),
index 48c1c23f18192913598132f5258de3f53f7ded1f..41ba13d86798cc534387bd2f9ca3ee9fe01a5c88 100644 (file)
@@ -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
index cc1cc492af6271886035e691f293619660e8cfda..16e40aad1bd2f224a57abff236fa61c6de88afb2 100644 (file)
@@ -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))