@@ -4,7 +4,10 @@ const BbPromise = require("bluebird"),
44 _ = require ( "lodash" ) ,
55 Slack = require ( "../slack" ) ;
66
7- class EmailParser {
7+ /**
8+ * Parses SES "Received" notifications incoming via SNS
9+ */
10+ class SesReceivedParser {
811
912 parse ( event ) {
1013 return BbPromise . try ( ( ) => JSON . parse ( _ . get ( event , "Records[0].Sns.Message" , "{}" ) ) )
@@ -16,40 +19,35 @@ class EmailParser {
1619 }
1720
1821 // AWS SES Message
19- console . log ( "message =" , JSON . stringify ( message , null , 2 ) ) ;
2022 const source = _ . get ( message , "mail.source" ) ;
21- const messageId = _ . get ( message , "mail.messageId " ) ;
23+ const destination = _ . get ( message , "mail.destination " ) ;
2224 const timestamp = _ . get ( message , "mail.timestamp" ) ;
2325 const subject = _ . get ( message , "mail.commonHeaders.subject" ) ;
26+ const content = _ . get ( message , "content" ) ;
2427
25- let color = Slack . COLORS . accent ;
26-
27- const fields = [ {
28- title : "Subject" ,
29- value : subject ,
30- short : true
31- } ] ;
28+ const fields = [ ] ;
3229 if ( source ) {
3330 fields . push ( {
3431 title : "From" ,
3532 value : source ,
3633 short : true
3734 } ) ;
3835 }
39- if ( subject ) {
36+ if ( destination ) {
4037 fields . push ( {
41- title : "Subject " ,
42- value : subject ,
38+ title : "To " ,
39+ value : _ . join ( destination , ",\n" ) ,
4340 short : true
4441 } ) ;
4542 }
4643
4744 const slackMessage = {
4845 attachments : [ {
4946 fallback : "New email received from SES" ,
50- color : color ,
47+ color : Slack . COLORS . accent ,
48+ author_name : "Amazon SES" ,
5149 title : subject ,
52- text : "" ,
50+ text : content ,
5351 fields : fields ,
5452 ts : Slack . toEpochTime ( new Date ( timestamp ) )
5553 } ]
@@ -59,4 +57,4 @@ class EmailParser {
5957 }
6058}
6159
62- module . exports = EmailParser ;
60+ module . exports = SesReceivedParser ;
0 commit comments