]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] DMARC: Fix munging when reply-to is presented
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 2 Apr 2021 12:18:58 +0000 (13:18 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 2 Apr 2021 12:19:20 +0000 (13:19 +0100)
src/plugins/lua/dmarc.lua

index cb5a585022ea1e9f4f19dc00ea997af57dcf5d66..8ecf51ec776f00a44aba4ce406fdf5ff92afc5a8 100644 (file)
@@ -1577,19 +1577,33 @@ if opts.munging then
     local add_hdrs = {
       ['From'] = { order = 1, value = hdr_encoded },
     }
+    local remove_hdrs = {
+      {['From'] = 0},
+    }
 
+    local nreply = from.addr
     if munging_opts.reply_goes_to_list then
       -- Reply-to goes to the list
-      table.insert(add_hdrs['Reply-To'], {order = 0, value = via_addr})
-    else
-      add_hdrs['Reply-To'] = {order = 0, value = from.addr}
+      nreply = via_addr
     end
 
+    if task:has_header('Reply-To') then
+      -- If we have reply-to header, then we need to insert an additional
+      -- address there
+      local orig_reply = task:get_header_full('Reply-To')[1]
+      if orig_reply.value then
+        nreply = string.format('%s, %s', orig_reply.value, nreply)
+      end
+      remove_hdrs['Reply-To'] = 1
+    end
+
+    add_hdrs['Reply-To'] = {order = 0, value = nreply}
+
     add_hdrs['X-Original-From'] = { order = 0, value = orig_from_encoded}
     lua_mime.modify_headers(task, {
-      remove = {['From'] = 0},
+      remove = remove_hdrs,
       add = add_hdrs
-      })
+    })
     lua_util.debugm(N, task, 'munged DMARC header for %s: %s -> %s',
             from.domain, hdr_encoded, from.addr)
     rspamd_logger.infox(task, 'munged DMARC header for %s', from.addr)