File tree Expand file tree Collapse file tree 3 files changed +60
-0
lines changed
Expand file tree Collapse file tree 3 files changed +60
-0
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ console.log("AWS Lambda SES Forwarder // @arithmetric // Version 3.0.0");
99//
1010// Expected keys/values:
1111// - fromEmail: Forwarded emails will come from this verified address
12+ // - subjectPrefix: Forwarded emails subject will contain this prefix
1213// - emailBucket: S3 bucket name where SES stores emails.
1314// - emailKeyPrefix: S3 key name prefix where SES stores email. Include the
1415// trailing slash.
@@ -19,6 +20,7 @@ console.log("AWS Lambda SES Forwarder // @arithmetric // Version 3.0.0");
1920// The key must be lowercase.
2021var defaultConfig = {
2122 fromEmail : "noreply@example.com" ,
23+ subjectPrefix : "" ,
2224 emailBucket : "s3-bucket-name" ,
2325 emailKeyPrefix : "emailsPrefix/" ,
2426 forwardMapping : {
@@ -186,6 +188,15 @@ exports.processMessage = function(data, next) {
186188 return fromText ;
187189 } ) ;
188190
191+ // Add a prefix to the Subject
192+ if ( data . config . subjectPrefix ) {
193+ header = header . replace (
194+ / ^ S u b j e c t : ( .* ) / mg,
195+ function ( match , subject ) {
196+ return 'Subject: ' + data . config . subjectPrefix + subject ;
197+ } ) ;
198+ }
199+
189200 // Remove the Return-Path header.
190201 header = header . replace ( / ^ R e t u r n - P a t h : ( .* ) \r ? \n / mg, '' ) ;
191202
Original file line number Diff line number Diff line change 1+ Received: from example.com (example.com [127.0.0.1])
2+ by inbound-smtp.us-west-2.amazonaws.com with SMTP id 81fu1unjk93bm5cb0jlk23fll33spcvf3633l8qg1
3+ for info@example.com;
4+ Fri, 11 Mar 2016 06:20:55 +0000 (UTC)
5+ X-SES-Spam-Verdict: PASS
6+ X-SES-Virus-Verdict: PASS
7+ 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;
8+ From: Betsy at betsy@example.com <info@example.com>
9+ To: info@example.com
10+ Subject: [PREFIX] Test message from Betsy
11+ Message-Id: <B9ebWRD-000123-3K@example.com>
12+ Date: Fri, 11 Mar 2016 01:20:54 -0500
13+ Reply-To: Betsy <betsy@example.com>
14+
15+ This is a test message to info@example.com.
16+
17+ It was sent from betsy@example.com.
18+
19+ These lines should not be affected:
20+ From: test@example.com
21+ Reply-To: test@example.com
22+ Return-Path: test@example.com
23+ DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple;
24+ s=gdwg2y3kokkkomn55z2ilkup5wp5hhxx; d=amazonses.com; t=1457977483;
25+ h=Date:From:Reply-To:To:Message-ID:Subject:MIME-Version;
Original file line number Diff line number Diff line change @@ -100,5 +100,29 @@ describe('index.js', function() {
100100 done ( ) ;
101101 } ) ;
102102 } ) ;
103+
104+ it ( 'should allow adding a prefix to the Subject in emails' , function ( done ) {
105+ var data = {
106+ config : {
107+ subjectPrefix : "[PREFIX] "
108+ } ,
109+ email : {
110+ source : "betsy@example.com"
111+ } ,
112+ emailData : fs . readFileSync ( "test/assets/message.txt" ) . toString ( ) ,
113+ log : console . log ,
114+ recipients : [ "jim@example.com" ] ,
115+ originalRecipient : "info@example.com"
116+ } ;
117+ var emailDataProcessed = fs . readFileSync (
118+ "test/assets/message.subjectprefix.txt" ) . toString ( ) ;
119+ index . processMessage ( data , function ( err , data ) {
120+ assert . ok ( ! err , "processEmail returned successfully" ) ;
121+ assert . equal ( data . emailData ,
122+ emailDataProcessed ,
123+ "processEmail updated email data" ) ;
124+ done ( ) ;
125+ } ) ;
126+ } ) ;
103127 } ) ;
104128} ) ;
You can’t perform that action at this time.
0 commit comments