In this case, we’re going to allow any sender address contained in a list of format noreply@domain.com to be rewritten to noreply+allow@domain.com (line 3)
Script
if ( message.getHeader('from')!=null) { const fromStr = message.getHeader("From").toLowerCase(); const addresses = ["noreply@wanted.com", "noreply@other.com"]; for (let id in addresses) { if (fromStr.indexOf(addresses[id])!=-1) { let updated = addresses[id].replace("@", "+allow@"); message.setHeader('From', updated); print('noreply@wanted.com was rewritten to '+updated); replaced=true; break; } } }
MIME-Version: 1.0 Received: by 10.223.112.12 with HTTP; Sat, 18 Jun 2011 22:42:26 -0700 (PDT) Date: Sun, 19 Jun 2011 17:42:26 +1200 Subject: CHANGE_SUBJECT!!! From: noreply@other.com To: support@thepluginpeople.com Content-Type: text/plain; charset=UTF-8 (!) Match me. This is the real textssss
Validation Script
assert.equal( message.getHeader('from'), 'noreply+allow@other.com');
RuntimeReport
Showing the applied header update
Issue
With comment header prefix showing the value coming through: