diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-12-20 17:11:34 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-12-20 17:14:18 +0000 |
commit | dcb7971bc217705e51e6d109809c20f42282d8d9 (patch) | |
tree | c120f1d6afc40e517389adeb0949713b7623e9cf /src/libserver/protocol.c | |
parent | 4a13cf8c0ac843fb8868c29e40b58ba5fb99409e (diff) | |
download | rspamd-dcb7971bc217705e51e6d109809c20f42282d8d9.tar.gz rspamd-dcb7971bc217705e51e6d109809c20f42282d8d9.zip |
[Minor] Fix rewrite subject
Diffstat (limited to 'src/libserver/protocol.c')
-rw-r--r-- | src/libserver/protocol.c | 47 |
1 files changed, 30 insertions, 17 deletions
diff --git a/src/libserver/protocol.c b/src/libserver/protocol.c index cc88cfd0c..8b7c4b6f6 100644 --- a/src/libserver/protocol.c +++ b/src/libserver/protocol.c @@ -768,38 +768,51 @@ rspamd_emails_tree_ucl (GHashTable *input, struct rspamd_task *task) static const gchar * make_rewritten_subject (struct rspamd_metric *metric, struct rspamd_task *task) { - static gchar subj_buf[1024]; - gchar *p = subj_buf, *end, *res; - const gchar *s, *c; + GString *subj_buf; + gchar *res; + const gchar *s, *c, *p; + gsize slen = 0; - end = p + sizeof(subj_buf); c = metric->subject; + if (c == NULL) { c = SPAM_SUBJECT; } + p = c; s = task->subject; - while (p < end) { - if (*c == '\0') { - *p = '\0'; - break; - } - else if (*c == '%' && *(c + 1) == 's') { - p += rspamd_strlcpy (p, (s != NULL) ? s : "", end - p); - c += 2; - } - else { - *p = *c++; + if (s) { + slen = strlen (s); + } + + subj_buf = g_string_sized_new (strlen (c) + slen); + + while (*p) { + if (*p == '%' && *(p + 1) == 's') { + g_string_append_len (subj_buf, c, p - c); + + if (s) { + g_string_append_len (subj_buf, s, slen); + } + + p += 2; + c = p; } - p++; + + p ++; + } + + if (p > c) { + g_string_append_len (subj_buf, c, p - c); } - res = rspamd_mime_header_encode (subj_buf, strlen (subj_buf)); + res = rspamd_mime_header_encode (subj_buf->str, subj_buf->len); rspamd_mempool_add_destructor (task->task_pool, (rspamd_mempool_destruct_t)g_free, res); + g_string_free (subj_buf, TRUE); return res; } |