Skip to content

Commit

Permalink
Merge db14329 into ca8c475
Browse files Browse the repository at this point in the history
  • Loading branch information
ccjmne committed Oct 19, 2018
2 parents ca8c475 + db14329 commit bc8da3f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
18 changes: 9 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ exports.processMessage = function(data) {
var body = match && match[2] ? match[2] : '';

// Add "Reply-To:" with the "From" address if it doesn't already exists
if (!/^Reply-To: /mi.test(header)) {
match = header.match(/^From: (.*(?:\r?\n\s+.*)*\r?\n)/m);
if (!/^reply-to:\s?/mi.test(header)) {
match = header.match(/^from:\s?(.*(?:\r?\n\s+.*)*\r?\n)/mi);
var from = match && match[1] ? match[1] : '';
if (from) {
header = header + 'Reply-To: ' + from;
Expand All @@ -202,7 +202,7 @@ exports.processMessage = function(data) {
// so replace the message's "From:" header with the original
// recipient (which is a verified domain)
header = header.replace(
/^From: (.*(?:\r?\n\s+.*)*)/mg,
/^from:\s?(.*(?:\r?\n\s+.*)*)/mgi,
function(match, from) {
var fromText;
if (data.config.fromEmail) {
Expand All @@ -218,31 +218,31 @@ exports.processMessage = function(data) {
// Add a prefix to the Subject
if (data.config.subjectPrefix) {
header = header.replace(
/^Subject: (.*)/mg,
/^subject:\s?(.*)/mgi,
function(match, subject) {
return 'Subject: ' + data.config.subjectPrefix + subject;
});
}

// Replace original 'To' header with a manually defined one
if (data.config.toEmail) {
header = header.replace(/^To: (.*)/mg, () => 'To: ' + data.config.toEmail);
header = header.replace(/^to:\s?(.*)/mgi, () => 'To: ' + data.config.toEmail);
}

// Remove the Return-Path header.
header = header.replace(/^Return-Path: (.*)\r?\n/mg, '');
header = header.replace(/^return-path:\s?(.*)\r?\n/mgi, '');

// Remove Sender header.
header = header.replace(/^Sender: (.*)\r?\n/mg, '');
header = header.replace(/^sender:\s?(.*)\r?\n/mgi, '');

// Remove Message-ID header.
header = header.replace(/^Message-ID: (.*)\r?\n/mig, '');
header = header.replace(/^message-id:\s?(.*)\r?\n/mgi, '');

// Remove all DKIM-Signature headers to prevent triggering an
// "InvalidParameterValue: Duplicate header 'DKIM-Signature'" error.
// These signatures will likely be invalid anyways, since the From
// header was modified.
header = header.replace(/^DKIM-Signature: .*\r?\n(\s+.*\r?\n)*/mg, '');
header = header.replace(/^dkim-signature:\s?.*\r?\n(\s+.*\r?\n)*/mgi, '');

data.emailData = header + body;
return Promise.resolve(data);
Expand Down
2 changes: 1 addition & 1 deletion test/assets/message.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ X-SES-Virus-Verdict: PASS
Message-ID: <duplicit-invalid-messageid@localhost>
Received-SPF: none (spfCheck: 127.0.0.1 is neither permitted nor denied by domain of example.com) client-ip=10.0.0.1; envelope-from=postmaster@example.com; helo=example.com;
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1457977479; bh=yu5f99IGBuY/QbF1MYj9KjHmHUGQlS13FY53b5YLEb8=; h=Date:From:Reply-To:To:Subject:References:From:Subject; b=Osl8Z/p7lL3v/D60aBh3AJ5coNE6AORIwAEOa66ogh8UI1GLbTo0JgRwN0amg4n8lOU2RJyyNR10+rfx1ciwiP8ypfs0GjllxhgoeXtxCqtsdil5ILvkrxVloOH84tkKDVrvWv0xtZ4S1kOUDVY0EoBnC9xx7dU+WkNA2YmQSQgEji0jb8OeWowvOFxUsIwURewzONCMLm6+ZJqAVVediv6td3U3NRlN3Nfm7IHO8uxvQdDLTbJhqmIx3Ld5x///G9DOkclE+2pHgX0xZwOsbkPsfRRyeDWlrjPWwU2Wm8E481U0CsjmaEbSwk4lkEoFKQH7WfvmULFXftK0YZZMjA==
From: Betsy <betsy@example.com>
from:Betsy <betsy@example.com>
To: info@example.com
Subject: Test message from Betsy
Message-Id: <B9ebWRD-000123-3K@example.com>
Expand Down

0 comments on commit bc8da3f

Please sign in to comment.