@@ -1449,6 +1449,7 @@ rspamd_config:register_dependency('DMARC_CHECK', symbols['dkim_allow_symbol'])
1449
1449
if opts .munging then
1450
1450
local lua_maps = require " lua_maps"
1451
1451
local lua_maps_expressions = require " lua_maps_expressions"
1452
+ local lua_mime = require " lua_mime"
1452
1453
1453
1454
local munging_defaults = {
1454
1455
reply_goes_to_list = false ,
@@ -1481,7 +1482,72 @@ if opts.munging then
1481
1482
end
1482
1483
1483
1484
local function dmarc_munge_callback (task )
1485
+ if not task :has_symbol (dmarc_symbols .allow ) then
1486
+ lua_util .debugm (N , task , ' skip munging, no %s symbol' ,
1487
+ dmarc_symbols .allow )
1488
+ -- Excepted
1489
+ return
1490
+ end
1491
+ -- TODO: Add policy check to skip munging for non-strict policies
1492
+ if munging_opts .munge_map_condition then
1493
+ local accepted ,trace = munging_opts .munge_map_condition :process (task )
1494
+ if not accepted then
1495
+ lua_util .debugm (task , ' skip munging, maps condition not satisified: (%s)' ,
1496
+ trace )
1497
+ -- Excepted
1498
+ return
1499
+ end
1500
+ end
1501
+ -- Now, look for domain for munging
1502
+ local mr = task :get_recipients ({ ' mime' , ' orig' })
1503
+ local rcpt_found
1504
+ if mr then
1505
+ for _ ,r in ipairs (mr ) do
1506
+ if r .domain and munging_opts .list_map :get_key (r .domain ) then
1507
+ rcpt_found = r
1508
+ break
1509
+ end
1510
+ end
1511
+ end
1512
+
1513
+ if not rcpt_found then
1514
+ lua_util .debugm (task , ' skip munging, recipients are not in list_map' )
1515
+ -- Excepted
1516
+ return
1517
+ end
1518
+
1519
+ local via_name = rcpt_found .user
1520
+ local via_addr = rcpt_found .addr
1521
+
1522
+ local from = task :get_from ({ ' mime' , ' orig' })
1523
+
1524
+ if not from or not from [1 ] then
1525
+ lua_util .debugm (task , ' skip munging, from is bad' )
1526
+ -- Excepted
1527
+ return
1528
+ end
1529
+
1530
+ from = from [1 ]
1531
+
1532
+ if from .name then
1533
+ from .name = string.format (' %s via %s' , from .name , via_name )
1534
+ else
1535
+ from .name = string.format (' %s via %s' , from .user or ' unknown' , via_name )
1536
+ end
1484
1537
1538
+ local hdr_encoded = rspamd_util .fold_header (' From' ,
1539
+ rspamd_util .mime_header_encode (string.format (' %s <%s>' ,
1540
+ from .name , via_addr )))
1541
+ lua_mime .modify_headers ({
1542
+ remove = {[' From' ] = {0 }},
1543
+ add = {
1544
+ [' From' ] = {order = 1 , value = hdr_encoded },
1545
+ [' Reply-To' ] = {order = 0 , value = from .addr }
1546
+ }
1547
+ })
1548
+ lua_util .debugm (N , task , ' munged DMARC header for %s: %s -> %s' ,
1549
+ from .domain , hdr_encoded , from .addr )
1550
+ rspamd_logger .infox (task , ' munged DMARC header for %s' , from .domain )
1485
1551
end
1486
1552
1487
1553
rspamd_config :register_symbol ({
0 commit comments