]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Feature] Allow oversign if exists mode
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sun, 5 May 2019 08:23:51 +0000 (09:23 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sun, 5 May 2019 08:23:51 +0000 (09:23 +0100)
src/libserver/dkim.c

index 98b8e1006567983b9b323ed08f03bfa40e93cb7e..3bc43c4b24045a64b04881746b3273d20577a41c 100644 (file)
@@ -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 {