summaryrefslogtreecommitdiffstats
path: root/src/libmime/mime_headers.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2023-11-23 15:37:29 +0000
committerVsevolod Stakhov <vsevolod@rspamd.com>2023-11-23 15:37:29 +0000
commit30faab04ebbd968910a33b52238df84b8be23776 (patch)
tree78ce96457bb22642081d4a8ebd0cf9801cf4d515 /src/libmime/mime_headers.c
parent46cefe8be0cb2bc7958cb93e49fdf6c6b32e8a03 (diff)
downloadrspamd-30faab04ebbd968910a33b52238df84b8be23776.tar.gz
rspamd-30faab04ebbd968910a33b52238df84b8be23776.zip
[Fix] Fix issues with the raw header on header insertion/modification
Diffstat (limited to 'src/libmime/mime_headers.c')
-rw-r--r--src/libmime/mime_headers.c39
1 files changed, 33 insertions, 6 deletions
diff --git a/src/libmime/mime_headers.c b/src/libmime/mime_headers.c
index daba57f0d..e7b9c0c9b 100644
--- a/src/libmime/mime_headers.c
+++ b/src/libmime/mime_headers.c
@@ -1,11 +1,11 @@
-/*-
- * Copyright 2016 Vsevolod Stakhov
+/*
+ * Copyright 2023 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -1198,9 +1198,36 @@ void rspamd_message_set_modified_header(struct rspamd_task *task,
nhdr->name = hdr_elt->name;
nhdr->value = rspamd_mempool_alloc(task->task_pool,
raw_len + 1);
- nhdr->raw_len = rspamd_strlcpy(nhdr->value, raw_value,
- raw_len + 1);
- nhdr->raw_value = nhdr->value;
+ rspamd_strlcpy(nhdr->value, raw_value, raw_len + 1);
+ /* TODO: unfold header value, sigh */
+
+ /* Deal with the raw value */
+ size_t namelen = strlen(hdr_elt->name);
+ char *rawbuf = rspamd_mempool_alloc(task->task_pool, namelen +
+ raw_len +
+ sizeof(": \r\n"));
+ /* Name: value<newline> */
+ nhdr->raw_value = rawbuf;
+ memcpy(rawbuf, hdr_elt->name, namelen);
+ rawbuf += namelen;
+ memcpy(rawbuf, ": ", sizeof(": ") - 1);
+ nhdr->separator = rspamd_mempool_strdup(task->task_pool, " ");
+ rawbuf += sizeof(": ") - 1;
+ memcpy(rawbuf, raw_value, raw_len);
+
+ if (MESSAGE_FIELD(task, nlines_type) == RSPAMD_TASK_NEWLINES_LF) {
+ rawbuf[raw_len++] = '\n';
+ }
+ else {
+ rawbuf[raw_len++] = '\r';
+
+ if (MESSAGE_FIELD(task, nlines_type) == RSPAMD_TASK_NEWLINES_CRLF) {
+ rawbuf[raw_len++] = '\n';
+ }
+ }
+
+ rawbuf[raw_len] = '\0';
+ nhdr->raw_len = raw_len;
nhdr->decoded = rspamd_mime_header_decode(task->task_pool,
raw_value, raw_len, NULL);