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 {
{
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;
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 */
}
u.s.flags |= RSPAMD_DKIM_FLAG_OVERSIGN;
+
+ if (existing) {
+ u.s.flags |= RSPAMD_DKIM_FLAG_OVERSIGN_EXISTING;
+ }
+
u.s.count = 0;
}
else {
}
/* 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 {