Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #114 Sender email without name #118

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,21 @@ exports.processMessage = function(data) {
function(match, from) {
var fromText;
if (data.config.fromEmail) {
fromText = 'From: ' + from.replace(/<(.*)>/, '').trim() +
' <' + data.config.fromEmail + '>';
} else {
if (from.indexOf('<') >= 0 && from.indexOf('>') >= 0) {
fromText = 'From: ' + from.replace(/<(.*)>/, '').trim() +
' <' + data.config.fromEmail + '>';
} else {
// No display name format
fromText = 'From: ' + from.replace('@', ' at ').trim() +
' <' + data.config.fromEmail + '>';
}
} else if (from.indexOf('<') >= 0 && from.indexOf('>') >= 0) {
fromText = 'From: ' + from.replace('<', 'at ').replace('>', '') +
' <' + data.originalRecipient + '>';
} else {
// No display name format
fromText = 'From: ' + from.replace('@', ' at ').trim() +
' <' + data.originalRecipient + '>';
}
return fromText;
});
Expand Down
24 changes: 24 additions & 0 deletions test/assets/message.simplefrom.processed.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Received: from example.com (example.com [127.0.0.1])
by inbound-smtp.us-west-2.amazonaws.com with SMTP id 81fu1unjk93bm5cb0jlk23fll33spcvf3633l8qg1
for [email protected];
Fri, 11 Mar 2016 06:20:55 +0000 (UTC)
X-SES-Spam-Verdict: PASS
X-SES-Virus-Verdict: PASS
Received-SPF: none (spfCheck: 127.0.0.1 is neither permitted nor denied by domain of example.com) client-ip=10.0.0.1; [email protected]; helo=example.com;
From: betsy at example.com <[email protected]>
To: [email protected]
Subject: Test message from Betsy
Date: Fri, 11 Mar 2016 01:20:54 -0500
Reply-To: [email protected]

This is a test message to [email protected].

It was sent from [email protected].

These lines should not be affected:
From: [email protected]
Reply-To: [email protected]
Return-Path: [email protected]
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple;
s=gdwg2y3kokkkomn55z2ilkup5wp5hhxx; d=amazonses.com; t=1457977483;
h=Date:From:Reply-To:To:Message-ID:Subject:MIME-Version;
35 changes: 35 additions & 0 deletions test/assets/message.simplefrom.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Return-Path: <[email protected]>
Received: from example.com (example.com [127.0.0.1])
by inbound-smtp.us-west-2.amazonaws.com with SMTP id 81fu1unjk93bm5cb0jlk23fll33spcvf3633l8qg1
for [email protected];
Fri, 11 Mar 2016 06:20:55 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=gdwg2y3kokomn5a55z2ilkup5wp5hhxx; d=amazonses.com; t=1457977483; h=Date:From:Reply-To:To:Message-ID:Subject:MIME-Version:Content-Type;
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple;
s=gdwg2y3kokkkomn55z2ilkup5wp5hhxx; d=amazonses.com; t=1457977483;
h=Date:From:Reply-To:To:Message-ID:Subject:MIME-Version:Content-Type:References:Feedback-ID;
bh=yu5f22IGBuY/QbF1MYj9KjHbPKMQlS13FY53b5YLEb8=;
b=EX4NWAbgp5EuCQ6WzaNg74GiPRxNV/oPWHbd/QAyZmfutsD2Dzr6HYfA2XJ0aEui
/RRmYfnjvB8lk3MJRhL/TMHDO/LCWLnXV4OLgkZH6IuVFVZnI2p9pAG11E1AWD9l8AW
NTuhRooMHNWMDJgEdo84jnDXIqKSvPR8o0y45M7I=
X-SES-Spam-Verdict: PASS
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; [email protected]; 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: [email protected]
To: [email protected]
Subject: Test message from Betsy
Message-Id: <[email protected]>
Date: Fri, 11 Mar 2016 01:20:54 -0500

This is a test message to [email protected].

It was sent from [email protected].

These lines should not be affected:
From: [email protected]
Reply-To: [email protected]
Return-Path: [email protected]
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple;
s=gdwg2y3kokkkomn55z2ilkup5wp5hhxx; d=amazonses.com; t=1457977483;
h=Date:From:Reply-To:To:Message-ID:Subject:MIME-Version;
24 changes: 24 additions & 0 deletions test/assets/message.simplefrom_custom.processed.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Received: from example.com (example.com [127.0.0.1])
by inbound-smtp.us-west-2.amazonaws.com with SMTP id 81fu1unjk93bm5cb0jlk23fll33spcvf3633l8qg1
for [email protected];
Fri, 11 Mar 2016 06:20:55 +0000 (UTC)
X-SES-Spam-Verdict: PASS
X-SES-Virus-Verdict: PASS
Received-SPF: none (spfCheck: 127.0.0.1 is neither permitted nor denied by domain of example.com) client-ip=10.0.0.1; [email protected]; helo=example.com;
From: betsy at example.com <[email protected]>
To: [email protected]
Subject: Test message from Betsy
Date: Fri, 11 Mar 2016 01:20:54 -0500
Reply-To: [email protected]

This is a test message to [email protected].

It was sent from [email protected].

These lines should not be affected:
From: [email protected]
Reply-To: [email protected]
Return-Path: [email protected]
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple;
s=gdwg2y3kokkkomn55z2ilkup5wp5hhxx; d=amazonses.com; t=1457977483;
h=Date:From:Reply-To:To:Message-ID:Subject:MIME-Version;
51 changes: 50 additions & 1 deletion test/processMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,54 @@ describe('index.js', function() {
});
});

it('should process email data without display name', function(done) {
var data = {
config: {},
email: {
source: "[email protected]"
},
emailData:
fs.readFileSync("test/assets/message.simplefrom.txt").toString(),
log: console.log,
recipients: ["[email protected]"],
originalRecipient: "[email protected]"
};
var emailDataProcessed = fs.readFileSync(
"test/assets/message.simplefrom.processed.txt").toString();
index.processMessage(data)
.then(function(data) {
assert.equal(data.emailData,
emailDataProcessed,
"processEmail updated email data");
done();
});
});

it('should process overridden email without display name', function(done) {
var data = {
config: {
fromEmail: "[email protected]"
},
email: {
source: "[email protected]"
},
emailData:
fs.readFileSync("test/assets/message.simplefrom.txt").toString(),
log: console.log,
recipients: ["[email protected]"],
originalRecipient: "[email protected]"
};
var emailDataProcessed = fs.readFileSync(
"test/assets/message.simplefrom_custom.processed.txt").toString();
index.processMessage(data)
.then(function(data) {
assert.equal(data.emailData,
emailDataProcessed,
"processEmail updated email data");
done();
});
});

it('should preserve an existing Reply-To header in emails', function(done) {
var data = {
config: {},
Expand Down Expand Up @@ -110,7 +158,8 @@ describe('index.js', function() {
source: "[email protected]"
},
emailData:
fs.readFileSync("test/assets/message.from_multiline.source.txt").toString(),
fs.readFileSync(
"test/assets/message.from_multiline.source.txt").toString(),
log: console.log,
recipients: ["[email protected]"],
originalRecipient: "[email protected]"
Expand Down