Skip to content

Commit 13555b3

Browse files
committed
Done #7
1 parent 03cb084 commit 13555b3

File tree

4 files changed

+277
-88
lines changed

4 files changed

+277
-88
lines changed

index.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
let AWS = require('aws-sdk');
2+
let moment = require('moment');
23
let parser = require("mailparser").simpleParser;
34

45
//
@@ -35,6 +36,10 @@ exports.handler = (event) => {
3536

3637
return parse_the_email(container);
3738

39+
}).then(function(container) {
40+
41+
return format_time(container);
42+
3843
}).then(function(container) {
3944

4045
return extract_data(container);
@@ -198,6 +203,30 @@ function parse_the_email(container)
198203
});
199204
}
200205

206+
//
207+
// We format the date and time to make sure that when the folder is saved
208+
// in S3, the object will sort one after the other which makes it much
209+
// easier to see the latest emails.
210+
//
211+
function format_time(container)
212+
{
213+
return new Promise(function(resolve, reject) {
214+
215+
console.info('format_time');
216+
217+
//
218+
// 1. Format the date found in the email message itself.
219+
//
220+
container.date = moment(container.date).format("YYYY-MM-DD HH:MM:SSS Z");
221+
222+
//
223+
// -> Move to the next chain.
224+
//
225+
return resolve(container);
226+
227+
});
228+
}
229+
201230
//
202231
// Extract all the data necessary to organize the incoming emails.
203232
//

lambda-payloads.json

Lines changed: 28 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,36 @@
11
{
22
"Records": [
33
{
4-
"eventSource": "aws:ses",
5-
"eventVersion": "1.0",
6-
"ses": {
7-
"mail": {
8-
"commonHeaders": {
9-
"date": "Wed, 7 Oct 2015 12:34:56 -0700",
10-
"from": [
11-
"Jane Doe <janedoe@example.com>"
12-
],
13-
"messageId": "<0123456789example.com>",
14-
"returnPath": "janedoe@example.com",
15-
"subject": "Test Subject",
16-
"to": [
17-
"aws+simple-redirect+production@example.com"
18-
]
4+
"eventVersion": "2.0",
5+
"eventSource": "aws:s3",
6+
"awsRegion": "us-east-1",
7+
"eventTime": "1970-01-01T00:00:00.000Z",
8+
"eventName": "ObjectCreated:Put",
9+
"userIdentity": {
10+
"principalId": "EXAMPLE"
11+
},
12+
"requestParameters": {
13+
"sourceIPAddress": "127.0.0.1"
14+
},
15+
"responseElements": {
16+
"x-amz-request-id": "EXAMPLE123456789",
17+
"x-amz-id-2": "EXAMPLE123/5678abcdefghijklambdaisawesome/mnopqrstuvwxyzABCDEFGH"
18+
},
19+
"s3": {
20+
"s3SchemaVersion": "1.0",
21+
"configurationId": "testConfigRule",
22+
"bucket": {
23+
"name": "0x4447-product-s3-email-ses-dev",
24+
"ownerIdentity": {
25+
"principalId": "EXAMPLE"
1926
},
20-
"destination": [
21-
"johndoe@example.com"
22-
],
23-
"headers": [
24-
{
25-
"name": "Return-Path",
26-
"value": "<janedoe@example.com>"
27-
},
28-
{
29-
"name": "Received",
30-
"value": "from mailer.example.com (mailer.example.com [203.0.113.1]) by inbound-smtp.us-east-1.amazonaws.com with SMTP id o3vrnil0e2ic28trm7dfhrc2v0cnbeccl4nbp0g1 for johndoe@example.com; Wed, 07 Oct 2015 12:34:56 +0000 (UTC)"
31-
},
32-
{
33-
"name": "DKIM-Signature",
34-
"value": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=example.com; s=example; h=mime-version:from:date:message-id:subject:to:content-type; bh=jX3F0bCAI7sIbkHyy3mLYO28ieDQz2R0P8HwQkklFj4=; b=sQwJ+LMe9RjkesGu+vqU56asvMhrLRRYrWCbVt6WJulueecwfEwRf9JVWgkBTKiL6m2hr70xDbPWDhtLdLO+jB3hzjVnXwK3pYIOHw3vxG6NtJ6o61XSUwjEsp9tdyxQjZf2HNYee873832l3K1EeSXKzxYk9Pwqcpi3dMC74ct9GukjIevf1H46hm1L2d9VYTL0LGZGHOAyMnHmEGB8ZExWbI+k6khpurTQQ4sp4PZPRlgHtnj3Zzv7nmpTo7dtPG5z5S9J+L+Ba7dixT0jn3HuhaJ9b+VThboo4YfsX9PMNhWWxGjVksSFOcGluPO7QutCPyoY4gbxtwkN9W69HA=="
35-
},
36-
{
37-
"name": "MIME-Version",
38-
"value": "1.0"
39-
},
40-
{
41-
"name": "From",
42-
"value": "Jane Doe <janedoe@example.com>"
43-
},
44-
{
45-
"name": "Date",
46-
"value": "Wed, 7 Oct 2015 12:34:56 -0700"
47-
},
48-
{
49-
"name": "Message-ID",
50-
"value": "<0123456789example.com>"
51-
},
52-
{
53-
"name": "Subject",
54-
"value": "Test Subject"
55-
},
56-
{
57-
"name": "To",
58-
"value": "johndoe@example.com"
59-
},
60-
{
61-
"name": "Content-Type",
62-
"value": "text/plain; charset=UTF-8"
63-
}
64-
],
65-
"headersTruncated": false,
66-
"messageId": "o3vrnil0e2ic28trm7dfhrc2v0clambda4nbp0g1",
67-
"source": "janedoe@example.com",
68-
"timestamp": "1970-01-01T00:00:00.000Z"
27+
"arn": "arn:aws:s3:::example-bucket"
6928
},
70-
"receipt": {
71-
"action": {
72-
"functionArn": "arn:aws:lambda:us-east-1:123456789012:function:Example",
73-
"invocationType": "Event",
74-
"type": "Lambda"
75-
},
76-
"dkimVerdict": {
77-
"status": "PASS"
78-
},
79-
"processingTimeMillis": 574,
80-
"recipients": [
81-
"johndoe@example.com"
82-
],
83-
"spamVerdict": {
84-
"status": "PASS"
85-
},
86-
"spfVerdict": {
87-
"status": "PASS"
88-
},
89-
"timestamp": "1970-01-01T00:00:00.000Z",
90-
"virusVerdict": {
91-
"status": "PASS"
92-
}
29+
"object": {
30+
"key": "TMP/Accepted_+Kevin+%3C%3E+David+%40+Sat+Jan+5%2C+2019+6pm+-+7pm+(CET)+(david%400x4447.com).eml",
31+
"size": 1024,
32+
"eTag": "0123456789abcdef0123456789abcdef",
33+
"sequencer": "0A1B2C3D4E5F678901"
9334
}
9435
}
9536
}

0 commit comments

Comments
 (0)