-
Notifications
You must be signed in to change notification settings - Fork 451
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from arithmetric/feature/case_insensitive_forw…
…ard_mapping Recipient string comparison should be case insensitive
- Loading branch information
Showing
2 changed files
with
50 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ console.log("AWS Lambda SES Forwarder // @arithmetric // Version 2.3.0"); | |
// forward and the value is an array of email addresses to which to send the | ||
// message. To match all email addresses on a domain, use a key without the | ||
// name part of an email address before the "at" symbol (i.e. `@example.com`). | ||
// The key must be lowercase. | ||
var defaultConfig = { | ||
fromEmail: "[email protected]", | ||
emailBucket: "s3-bucket-name", | ||
|
@@ -67,15 +68,16 @@ exports.transformRecipients = function(data, next) { | |
var newRecipients = []; | ||
data.originalRecipients = data.recipients; | ||
data.recipients.forEach(function(origEmail) { | ||
if (data.config.forwardMapping.hasOwnProperty(origEmail)) { | ||
var origEmailKey = origEmail.toLowerCase(); | ||
if (data.config.forwardMapping.hasOwnProperty(origEmailKey)) { | ||
newRecipients = newRecipients.concat( | ||
data.config.forwardMapping[origEmail]); | ||
data.config.forwardMapping[origEmailKey]); | ||
data.originalRecipient = origEmail; | ||
} else { | ||
var origEmailDomain; | ||
var pos = origEmail.lastIndexOf("@"); | ||
var pos = origEmailKey.lastIndexOf("@"); | ||
if (pos !== -1) { | ||
origEmailDomain = origEmail.slice(pos); | ||
origEmailDomain = origEmailKey.slice(pos); | ||
} | ||
if (origEmailDomain && | ||
data.config.forwardMapping.hasOwnProperty(origEmailDomain)) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,9 +17,49 @@ describe('index.js', function() { | |
"[email protected]", | ||
"[email protected]" | ||
] | ||
}, | ||
log: console.log | ||
} | ||
} | ||
}, | ||
context: { | ||
succeed: function() { | ||
assert.ok(false, | ||
'context.succeed() was called, but should not be'); | ||
done(); | ||
} | ||
}, | ||
log: console.log | ||
}; | ||
index.transformRecipients(data, function(err, data) { | ||
assert.ok(!err, "transformRecipients returned successfully"); | ||
assert.equal(data.recipients[0], | ||
"[email protected]", | ||
"parseEvent made 1/2 substitutions"); | ||
assert.equal(data.recipients[1], | ||
"[email protected]", | ||
"parseEvent made 2/2 substitutions"); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should transform recipients in a case insensitive way', | ||
function(done) { | ||
var data = { | ||
recipients: ["[email protected]"], | ||
config: { | ||
forwardMapping: { | ||
"[email protected]": [ | ||
"[email protected]", | ||
"[email protected]" | ||
] | ||
} | ||
}, | ||
context: { | ||
succeed: function() { | ||
assert.ok(false, | ||
'context.succeed() was called, but should not be'); | ||
done(); | ||
} | ||
}, | ||
log: console.log | ||
}; | ||
index.transformRecipients(data, function(err, data) { | ||
assert.ok(!err, "transformRecipients returned successfully"); | ||
|
@@ -36,7 +76,7 @@ describe('index.js', function() { | |
it('should transform recipients according a domain wildcard mapping', | ||
function(done) { | ||
var data = { | ||
recipients: ["info@example.com"], | ||
recipients: ["info@EXAMPLE.com"], | ||
config: { | ||
forwardMapping: { | ||
"@example.com": [ | ||
|