diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-05-05 09:23:51 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-05-05 09:23:51 +0100 |
commit | 2767ccb6fee0fad125db5848b88136489bebc611 (patch) | |
tree | 2d32ed5bd2acd5b0b8fea9943246447ec47eb8e9 /src | |
parent | 02ede418500d0fb27ef3e4cc9c74580b159ccde2 (diff) | |
download | rspamd-2767ccb6fee0fad125db5848b88136489bebc611.tar.gz rspamd-2767ccb6fee0fad125db5848b88136489bebc611.zip |
[Feature] Allow oversign if exists mode
Diffstat (limited to 'src')
-rw-r--r-- | src/libserver/dkim.c | 45 |
1 files changed, 31 insertions, 14 deletions
diff --git a/src/libserver/dkim.c b/src/libserver/dkim.c index 98b8e1006..3bc43c4b2 100644 --- a/src/libserver/dkim.c +++ b/src/libserver/dkim.c @@ -90,7 +90,8 @@ enum rspamd_dkim_param_type { INIT_LOG_MODULE(dkim) -#define RSPAMD_DKIM_FLAG_OVERSIGN (1u << 0) +#define RSPAMD_DKIM_FLAG_OVERSIGN (1u << 0u) +#define RSPAMD_DKIM_FLAG_OVERSIGN_EXISTING (1u << 1u) union rspamd_dkim_header_stat { struct _st { @@ -432,7 +433,7 @@ rspamd_dkim_parse_hdrlist_common (struct rspamd_dkim_common_ctx *ctx, { const gchar *c, *p, *end = param + len; gchar *h; - gboolean from_found = FALSE, oversign; + gboolean from_found = FALSE, oversign, existing; guint count = 0; struct rspamd_dkim_header *new; gpointer found; @@ -460,15 +461,24 @@ rspamd_dkim_parse_hdrlist_common (struct rspamd_dkim_common_ctx *ctx, while (p <= end) { if ((p == end || *p == ':') && p - c > 0) { oversign = FALSE; + existing = FALSE; h = rspamd_mempool_alloc (ctx->pool, p - c + 1); rspamd_strlcpy (h, c, p - c + 1); g_strstrip (h); - if (sign && rspamd_lc_cmp (h, "(o)", 3) == 0) { - oversign = TRUE; - h += 3; - msg_debug_dkim ("oversign header: %s", h); + if (sign) { + if (rspamd_lc_cmp (h, "(o)", 3) == 0) { + oversign = TRUE; + h += 3; + msg_debug_dkim ("oversign header: %s", h); + } + else if (rspamd_lc_cmp (h, "(x)", 3) == 0) { + oversign = TRUE; + existing = TRUE; + h += 3; + msg_debug_dkim ("oversign existing header: %s", h); + } } /* Check mandatory from */ @@ -492,6 +502,11 @@ rspamd_dkim_parse_hdrlist_common (struct rspamd_dkim_common_ctx *ctx, } u.s.flags |= RSPAMD_DKIM_FLAG_OVERSIGN; + + if (existing) { + u.s.flags |= RSPAMD_DKIM_FLAG_OVERSIGN_EXISTING; + } + u.s.count = 0; } else { @@ -3029,15 +3044,17 @@ rspamd_dkim_sign (struct rspamd_task *task, const gchar *selector, } /* Now add one more entry to oversign */ - cur_len = (strlen (dh->name) + 1) * (count + 1); - headers_len += cur_len; - if (headers_len > 70 && i > 0 && i < ctx->common.hlist->len - 1) { - rspamd_printf_gstring (hdr, " "); - headers_len = cur_len; - } + if (count > 0 || !(hstat.s.flags & RSPAMD_DKIM_FLAG_OVERSIGN_EXISTING)) { + cur_len = (strlen (dh->name) + 1) * (count + 1); + headers_len += cur_len; + if (headers_len > 70 && i > 0 && i < ctx->common.hlist->len - 1) { + rspamd_printf_gstring (hdr, " "); + headers_len = cur_len; + } - for (j = 0; j < count + 1; j++) { - rspamd_printf_gstring (hdr, "%s:", dh->name); + for (j = 0; j < count + 1; j++) { + rspamd_printf_gstring (hdr, "%s:", dh->name); + } } } else { |