@stacksjs/email 0.58.48 → 0.58.49

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,390 @@
1
+ /* eslint-disable eslint-comments/no-unlimited-disable */
2
+ /* eslint-disable */
3
+ import type Stream from 'node:stream'
4
+ import * as AWS from 'aws-sdk'
5
+ import moment from 'moment'
6
+ import { simpleParser as parser } from 'mailparser'
7
+ import { log } from '@stacksjs/logging'
8
+
9
+ // Initialize S3
10
+ const s3 = new AWS.S3({
11
+ apiVersion: '2006-03-01',
12
+ })
13
+
14
+ // Initialize SES
15
+ const ses = new AWS.SES({
16
+ apiVersion: '2010-12-01',
17
+ })
18
+
19
+ // This variable will hold all the domain available in SES so we don't
20
+ // have to query SES each time the Lambda runs, we query SES only when
21
+ // the lambda starts from scratch to circumvent the 1 sec request limit.
22
+ const domains: string[] = []
23
+
24
+ interface Container {
25
+ bucket: string
26
+ unescaped_key: string
27
+ escaped_key: string
28
+ domains: string[]
29
+ folder: string
30
+ // wip
31
+ raw_email?: Buffer | Stream | string
32
+ to?: string
33
+ from?: string
34
+ date?: Date | string
35
+ subject?: string
36
+ message_id?: string
37
+ to_domain?: string
38
+ to_account?: string
39
+ from_domain?: string
40
+ from_account?: string
41
+ path?: string
42
+ }
43
+
44
+ interface S3Event {
45
+ Records: {
46
+ s3: {
47
+ bucket: {
48
+ name: string
49
+ }
50
+ object: {
51
+ key: string
52
+ }
53
+ }
54
+ }[]
55
+ }
56
+
57
+ // This Lambda will filter all the incoming emails based on their From and To field
58
+ export function handler(event: S3Event): Promise<boolean> {
59
+ // if (!event.Records.length)
60
+ // throw new Error('No records in the event')
61
+
62
+ // This JS object will contain all the data within the chain.
63
+ const container: Container = {
64
+ bucket: event.Records[0]?.s3.bucket.name || '',
65
+ unescaped_key: '',
66
+ escaped_key: event.Records[0]?.s3.object.key || '',
67
+ domains,
68
+ folder: 'Sent',
69
+ }
70
+
71
+ get_email_domains(container)
72
+ .then((container) => {
73
+ return unescape_key(container)
74
+ }).then((container) => {
75
+ return load_the_email(container)
76
+ }).then((container) => {
77
+ return parse_the_email(container)
78
+ }).then((container) => {
79
+ return format_time(container)
80
+ }).then((container) => {
81
+ return extract_data(container)
82
+ }).then((container) => {
83
+ return where_to_save(container)
84
+ }).then((container) => {
85
+ return create_s3_boject_key(container)
86
+ }).then((container) => {
87
+ return copy_email_to_inbox(container)
88
+ }).then((container) => {
89
+ return copy_email_to_today(container)
90
+ }).then((container) => {
91
+ return delete_the_email(container)
92
+ }).then(() => {
93
+ return true
94
+ }).catch((error) => {
95
+ console.error(error)
96
+
97
+ return false
98
+ })
99
+ }
100
+
101
+ // List all the emails added to SES, so we can use them to decided where to
102
+ // store the emails. If in the Inbox, or sent. This is important when you
103
+ // upload emails by hand to back them up.
104
+ //
105
+ // Without doing this everything goes to the Inbox folder.
106
+ function get_email_domains(container: Container): Promise<Container> {
107
+ return new Promise((resolve, reject) => {
108
+ // If we have already the domains we don't query SES anymore since you
109
+ // can only query SES once a second. To solve this limitation
110
+ // we grab the data once, and save it in to memory.
111
+ if (container.domains.length)
112
+ return resolve(container)
113
+
114
+ log.info('get_email_domains')
115
+
116
+ const params = {
117
+ IdentityType: 'Domain',
118
+ MaxItems: 100,
119
+ }
120
+
121
+ ses.listIdentities(params, (error, data) => {
122
+ if (error) {
123
+ console.error(params)
124
+ return reject(error)
125
+ }
126
+
127
+ container.domains = data.Identities
128
+
129
+ return resolve(container)
130
+ })
131
+ })
132
+ }
133
+
134
+ // We need to process the path received by S3 since AWS dose escape the
135
+ // string in a special way. They escape the string in a HTML style
136
+ // but for whatever reason they convert spaces in to +ses.
137
+ function unescape_key(container: Container): Promise<Container> {
138
+ return new Promise((resolve, reject) => {
139
+ log.info('unescape_key')
140
+
141
+ // First we convert the + in to spaces
142
+ const plus_to_space = container.escaped_key.replace(/\+/g, ' ')
143
+
144
+ // And then we unescape the string, other wise we lose real + characters
145
+ const unescaped_key = decodeURIComponent(plus_to_space)
146
+
147
+ container.unescaped_key = unescaped_key
148
+
149
+ return resolve(container)
150
+ })
151
+ }
152
+
153
+ // Load the email that we received from SES.
154
+ function load_the_email(container: Container): Promise<Container> {
155
+ return new Promise((resolve, reject) => {
156
+ log.info('load_the_email')
157
+
158
+ const params = {
159
+ Bucket: container.bucket,
160
+ Key: container.unescaped_key,
161
+ }
162
+
163
+ s3.getObject(params, (error, data) => {
164
+ if (error) {
165
+ console.error(params)
166
+ return reject(error)
167
+ }
168
+
169
+ // Save the email for the next promise
170
+ // @ts-expect-error - refactor later
171
+ container.raw_email = data.Body
172
+
173
+ return resolve(container)
174
+ })
175
+ })
176
+ }
177
+
178
+ // Once the raw email is loaded we parse it with one goal in mind, get
179
+ // the date the of the email. This way we don't rely on the SES date, but
180
+ // on the real date the email was created.
181
+ //
182
+ // This way we can even load in to the system old emails as long as they
183
+ // are in the standard raw email format, and not some proprietary solution.
184
+ //
185
+ // That why will be organized with the time the emails were created, and not
186
+ // received in to the system.
187
+ function parse_the_email(container: Container): Promise<Container> {
188
+ return new Promise((resolve, reject) => {
189
+ log.info('parse_the_email')
190
+
191
+ if (!container.raw_email)
192
+ return reject(Error('No raw email to parse'))
193
+
194
+ // Parse the email and extract all that is necessary
195
+ parser(container.raw_email, (error, data) => {
196
+ // Check for internal errors
197
+ if (error) {
198
+ console.error(data)
199
+ return reject(error)
200
+ }
201
+
202
+ // Save the parsed email for the next promise.
203
+ container.date = data.date
204
+ container.from = data.from?.value[0]?.address
205
+ container.to = data.to?.value[0]?.address
206
+ container.subject = data.subject || 'No Subject'
207
+ container.message_id = data.messageId
208
+
209
+ return resolve(container)
210
+ })
211
+ })
212
+ }
213
+
214
+ // We format the date and time to make sure that when the folder is saved
215
+ // in S3, the object will sort one after the other which makes it much
216
+ // easier to see the latest emails.
217
+ function format_time(container: Container): Promise<Container> {
218
+ return new Promise((resolve, reject) => {
219
+ log.info('format_time')
220
+
221
+ // Format the date found in the email message itself
222
+ container.date = moment(container.date).format('YYYY-MM-DD HH:mm:ss Z')
223
+
224
+ return resolve(container)
225
+ })
226
+ }
227
+
228
+ // Extract all the data necessary to organize the incoming emails.
229
+ function extract_data(container: Container): Promise<Container> {
230
+ return new Promise((resolve, reject) => {
231
+ log.info('extract_data')
232
+
233
+ if (!container.to)
234
+ return reject(Error('No To field in the email'))
235
+
236
+ // Since the email string can come in a form of:
237
+ // Name Last <name@example.com>
238
+ // We have to extract just the email address, and discard the rest
239
+ const tmp_to = container.to
240
+ .match(/(?:[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|\\[\x01-\x09\x0B\x0C\x0E-\x7F])*")@(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-zA-Z0-9-]*[a-zA-Z0-9]:(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21-\x5A\x53-\x7F]|\\[\x01-\x09\x0B\x0C\x0E-\x7F])+)\])/gm)[0]
241
+ .split('@')
242
+
243
+ const tmp_from = container.from
244
+ .match(/(?:[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|\\[\x01-\x09\x0B\x0C\x0E-\x7F])*")@(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-zA-Z0-9-]*[a-zA-Z0-9]:(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21-\x5A\x53-\x7F]|\\[\x01-\x09\x0B\x0C\x0E-\x7F])+)\])/gm)[0]
245
+ .split('@')
246
+
247
+ // Get the domain name of the receiving end, so we can group
248
+ // emails by all the domain that were added to SES.
249
+ container.to_domain = tmp_to[1]
250
+
251
+ // Based on the email name, we replace all the + characters, that
252
+ // can be used to organize ones on-line accounts in to /, this way
253
+ // we can build a S3 patch which will automatically organize
254
+ // all the email in structured folder.
255
+ container.to_account = tmp_to[0]?.replace(/\+/g, '/')
256
+
257
+ // Get the domain name of the email which in our case will become the company name
258
+ container.from_domain = tmp_from[1]
259
+
260
+ // Get the name of who sent us the email
261
+ container.from_account = tmp_from[0]
262
+
263
+ // Set all the strings to lower case, because some times different
264
+ // on-line services will have your email in all caps. For example
265
+ // Priceline will do this.
266
+ //
267
+ // Since in the next step we compare the domain that is in SES
268
+ // with the data from the email, wee need to have it all in the
269
+ // same format for the if() statement to work correctly and
270
+ // generate the right path where to save the email.
271
+ container.to_domain = container.to_domain?.toLowerCase()
272
+ container.to_account = container.to_account?.toLowerCase()
273
+ container.from_domain = container.from_domain?.toLowerCase()
274
+ container.from_account = container.from_account?.toLowerCase()
275
+
276
+ // S3 objects have a limit of how they they can be named
277
+ // so we remove everything but...
278
+ container.subject = container.subject?.replace(/[^a-zA-Z0-9 &@:,$=+?;]/g, '_')
279
+
280
+ return resolve(container)
281
+ })
282
+ }
283
+
284
+ // Once we have the domains from SES, and we know the value of the To
285
+ // field, we can decide where the emails should be saved.
286
+ function where_to_save(container: Container): Promise<Container> {
287
+ return new Promise((resolve, reject) => {
288
+ log.info('where_to_save')
289
+
290
+ // Since by default we assume that the email should be saved
291
+ // in the Sent folder, we need to loop over the SES domains
292
+ // and check if there is a match with the To: domain found in
293
+ // the email.
294
+ container.domains.forEach((domain) => {
295
+ if (domain === container.to_domain)
296
+ container.folder = 'Inbox'
297
+ })
298
+
299
+ return resolve(container)
300
+ })
301
+ }
302
+
303
+ // Create Key path for the S3 object to be saved to.
304
+ function create_s3_boject_key(container: Container): Promise<Container> {
305
+ return new Promise((resolve, reject) => {
306
+ log.info('create_s3_boject_key')
307
+
308
+ // create the path where the email needs to be moved for house keeping
309
+ container.path = `${container.to_domain}/${container.to_account}/${container.from_domain}/${container.from_account}/${container.date} - ${container.subject}/` + 'email.eml'
310
+
311
+ return resolve(container)
312
+ })
313
+ }
314
+
315
+ // Copy the email to a new location - we don't put the email that we
316
+ // already have in memory since the system requires a COPY action and not
317
+ // a PUT action.
318
+ // TODO: refactor below
319
+ // WARNING: We are using the escaped_key value, because there is a
320
+ // known bug in the AWS JS SDK which won't unescape the
321
+ // string, so you have to do it - AWS is aware of this issue.
322
+ function copy_email_to_inbox(container: Container): Promise<Container> {
323
+ return new Promise((resolve, reject) => {
324
+ log.info('copy_email_to_inbox')
325
+
326
+ const params = {
327
+ Bucket: container.bucket,
328
+ CopySource: `${container.bucket}/${container.escaped_key}`,
329
+ Key: `${container.folder}/${container.path}`,
330
+ }
331
+
332
+ s3.copyObject(params, (error, data) => {
333
+ if (error) {
334
+ console.error(params)
335
+ return reject(error)
336
+ }
337
+
338
+ return resolve(container)
339
+ })
340
+ })
341
+ }
342
+
343
+ // Similarly to the previous promise, but in this case we COPY the email to
344
+ // the Today folder to showcase all the latest emails that were received
345
+ // within 24h.
346
+ //
347
+ // There is a Lifecycle rule set on the bucket to delete any object inside
348
+ // the Today folder if it is older then 24h.
349
+ //
350
+ // This way it is easier to see all the latest emails.
351
+ function copy_email_to_today(container: Container): Promise<Container> {
352
+ return new Promise((resolve, reject) => {
353
+ log.info('copy_email_to_today')
354
+
355
+ const params = {
356
+ Bucket: container.bucket,
357
+ CopySource: `${container.bucket}/${container.escaped_key}`,
358
+ Key: `today/${container.path}`,
359
+ }
360
+
361
+ s3.copyObject(params, (error, data) => {
362
+ if (error) {
363
+ console.error(params)
364
+ return reject(error)
365
+ }
366
+
367
+ return resolve(container)
368
+ })
369
+ })
370
+ }
371
+
372
+ function delete_the_email(container: Container): Promise<Container> {
373
+ return new Promise((resolve, reject) => {
374
+ log.info('delete_the_email')
375
+
376
+ const params = {
377
+ Bucket: container.bucket,
378
+ Key: container.unescaped_key,
379
+ }
380
+
381
+ s3.deleteObject(params, (error, data) => {
382
+ if (error) {
383
+ console.error(params)
384
+ return reject(error)
385
+ }
386
+
387
+ return resolve(container)
388
+ })
389
+ })
390
+ }
@@ -0,0 +1,296 @@
1
+ /* eslint-disable eslint-comments/no-unlimited-disable */
2
+ /* eslint-disable */
3
+
4
+ const AWS = require('aws-sdk')
5
+ const moment = require('moment')
6
+ const uuidv1 = require('uuid/v1')
7
+ const MailComposer = require('nodemailer/lib/mail-composer')
8
+
9
+ // Initialize S3
10
+ const s3 = new AWS.S3({
11
+ apiVersion: '2006-03-01',
12
+ })
13
+
14
+ // Initialize SES
15
+ const ses = new AWS.SES({
16
+ apiVersion: '2010-12-01',
17
+ })
18
+
19
+ // This lambda will read outgoing emails formatted in JSON, convert them
20
+ // in to a raw email, send them using SES, and store them in S3.
21
+ exports.handler = (event) => {
22
+ // This JS object will contain all the data within the chain
23
+ const container = {
24
+ bucket: event.Records[0].s3.bucket.name,
25
+ key: event.Records[0].s3.object.key,
26
+ email: {
27
+ json: {},
28
+ raw: '',
29
+ },
30
+ uuid: uuidv1(),
31
+ }
32
+
33
+ // -> Start the chain.
34
+ load_the_email(container)
35
+ .then((container) => {
36
+ return extract_data(container)
37
+ }).then((container) => {
38
+ return generate_the_raw_email(container)
39
+ }).then((container) => {
40
+ return send_email(container)
41
+ }).then((container) => {
42
+ return save_raw_email(container)
43
+ }).then((container) => {
44
+ return copy_raw_email(container)
45
+ }).then((container) => {
46
+ return delete_json_email(container)
47
+ }).then((container) => {
48
+ return delete_raw_email(container)
49
+ }).then((container) => {
50
+ return true
51
+ }).catch((error) => {
52
+ console.error(error)
53
+
54
+ return false
55
+ })
56
+ }
57
+
58
+ // Load the JSON email that triggered this Lambda.
59
+ function load_the_email(container) {
60
+ return new Promise((resolve, reject) => {
61
+ console.info('load_the_email')
62
+
63
+ // 1. Set the query.
64
+ const params = {
65
+ Bucket: container.bucket,
66
+ Key: container.key,
67
+ }
68
+
69
+ // -> Execute the query.
70
+ s3.getObject(params, (error, data) => {
71
+ // 1. Check for internal errors.
72
+ if (error)
73
+ return reject(error)
74
+
75
+ // 2. Save the email for the next promise.
76
+ container.email.json = JSON.parse(data.Body)
77
+
78
+ // -> Move to the next chain.
79
+ return resolve(container)
80
+ })
81
+ })
82
+ }
83
+
84
+ // Extract all the data necessary to organize the incoming emails.
85
+ function extract_data(container) {
86
+ return new Promise((resolve, reject) => {
87
+ console.info('extract_data')
88
+
89
+ // 1. Extract all the information
90
+ const tmp_to = container.email.json
91
+ .to
92
+ .match(/[a-z0-9-+]{1,30}@[a-z0-9-]{1,65}.[a-z]{1,}/gm)[0]
93
+ .split('@')
94
+
95
+ const tmp_from = container.email.json
96
+ .from
97
+ .match(/[a-z0-9-+]{1,30}@[a-z0-9-]{1,65}.[a-z]{1,}/gm)[0]
98
+ .split('@')
99
+
100
+ // 2. Get the domain name of the receiving end, so we can group
101
+ // emails by all the domain that were added to SES.
102
+ const to_domain = tmp_to[1]
103
+
104
+ // 3. Based on the email name, we replace all the + characters, that
105
+ // can be used to organize ones on-line accounts in to /, this way
106
+ // we can build a S3 patch which will automatically organize
107
+ // all the email in structured folder.
108
+ const to_account = tmp_to[0].replace(/\+/g, '/')
109
+
110
+ // 4. Get the domain name of the email which in our case will
111
+ // become the company name.
112
+ const from_domain = tmp_from[1]
113
+
114
+ // 5. Get the name of who sent us the email.
115
+ const from_account = tmp_from[0]
116
+
117
+ // 6. Create a human readable time stamp that matches the format
118
+ // S3 Provides in its Event.
119
+ date = moment().format('ddd, DD MMM YYYY HH:MM:SS ZZ')
120
+
121
+ // 7. Create the path where the email needs to be moved
122
+ // so it is properly organized.
123
+ const path = `sent/${
124
+ to_domain
125
+ }/${
126
+ to_account
127
+ }/${
128
+ from_domain
129
+ }/${
130
+ from_account
131
+ }/${
132
+ date
133
+ } - ${
134
+ container.email.json.subject
135
+ }/`
136
+ + 'email'
137
+
138
+ // 8. Save the path for the next promise.
139
+ container.path = path
140
+
141
+ // -> Move to the next chain.
142
+ return resolve(container)
143
+ })
144
+ }
145
+
146
+ // From the JSON file that we loaded in to memory we generate a RAW version that
147
+ // can be used by SES, and later on stored and converted in multiple formats
148
+ function generate_the_raw_email(container, callback) {
149
+ return new Promise((resolve, reject) => {
150
+ console.info('generate_the_raw_email')
151
+
152
+ // 1. Crete the email based on the message object which holds all the
153
+ // necessary information.
154
+ const mail = new MailComposer(container.email.json)
155
+
156
+ // 2. Take the email and compile it down to its text form for storage.
157
+ mail.compile().build((error, raw_message) => {
158
+ // 1. Check if there was an error
159
+ if (error)
160
+ return reject(error)
161
+
162
+ // 2. Save the raw email so we can save it as is in to S3.
163
+ container.email.raw = raw_message
164
+
165
+ // -> Move to the next promise
166
+ return resolve(container)
167
+ })
168
+ })
169
+ }
170
+
171
+ // Use the newly generated RAW email and send it using SES.
172
+ function send_email(container) {
173
+ return new Promise((resolve, reject) => {
174
+ console.info('send_email')
175
+
176
+ // 1. Create the message
177
+ const params = {
178
+ RawMessage: {
179
+ Data: container.email.raw,
180
+ },
181
+ }
182
+
183
+ // -> Send the email out
184
+ ses.sendRawEmail(params, (error, data) => {
185
+ // 1. Check if there was an error
186
+ if (error)
187
+ return reject(error)
188
+
189
+ // -> Move to the next chain
190
+ return resolve(container)
191
+ })
192
+ })
193
+ }
194
+
195
+ // We now save the RAW email to S3 in a temporary folder. We do this because
196
+ // we don't want to create a PUT action in the Sent folder. The reason is
197
+ // that if we were to put the object directly to the destination, it would
198
+ // create a PUT action which would trigger the Convert Lambda. And this is
199
+ // fine. But then then Convert Lambda would save the object with a PUT action
200
+ // which would trigger the Convert Lambda once more, and until infinity.
201
+ // To prevent this loop, we make a temporary PUT event with no triggers,
202
+ // and then we copy the object to the final destination, which triggers
203
+ // the Convert action, and once the convert action makes a PUT nothing else
204
+ // happens.
205
+ function save_raw_email(container) {
206
+ return new Promise((resolve, reject) => {
207
+ console.info('save_raw_email')
208
+
209
+ // 1. Set the query.
210
+ const params = {
211
+ Bucket: container.bucket,
212
+ Key: `tmp/email_out/raw/${container.uuid}`,
213
+ Body: container.email.raw,
214
+ }
215
+
216
+ // -> Execute the query.
217
+ s3.putObject(params, (error, data) => {
218
+ // 1. Check for internal errors.
219
+ if (error)
220
+ return reject(error)
221
+
222
+ // -> Move to the next chain.
223
+ return resolve(container)
224
+ })
225
+ })
226
+ }
227
+
228
+ // Now that we have our RAW email saved we do a copy event so it will trigger the Conversion Lambda
229
+ function copy_raw_email(container) {
230
+ return new Promise((resolve, reject) => {
231
+ console.info('copy_raw_email')
232
+
233
+ // 1. Set the query.
234
+ const params = {
235
+ Bucket: container.bucket,
236
+ CopySource: `${container.bucket}/tmp/email_out/raw/${container.uuid}`,
237
+ Key: container.path,
238
+ }
239
+
240
+ // -> Execute the query.
241
+ s3.copyObject(params, (error, data) => {
242
+ // 1. Check for internal errors.
243
+ if (error)
244
+ return reject(error)
245
+
246
+ // -> Move to the next chain.
247
+ return resolve(container)
248
+ })
249
+ })
250
+ }
251
+
252
+ // And before we finish we clean up the environment by deleting the JSON email,
253
+ function delete_json_email(container) {
254
+ return new Promise((resolve, reject) => {
255
+ console.info('delete_json_email')
256
+
257
+ // 1. Set the query.
258
+ const params = {
259
+ Bucket: container.bucket,
260
+ Key: container.key,
261
+ }
262
+
263
+ // -> Execute the query.
264
+ s3.deleteObject(params, (error, data) => {
265
+ // 1. Check for internal errors.
266
+ if (error)
267
+ return reject(error)
268
+
269
+ // -> Move to the next chain.
270
+ return resolve(container)
271
+ })
272
+ })
273
+ }
274
+
275
+ // And the temporary RAW email.
276
+ function delete_raw_email(container) {
277
+ return new Promise((resolve, reject) => {
278
+ console.info('delete_raw_email')
279
+
280
+ // 1. Set the query.
281
+ const params = {
282
+ Bucket: container.bucket,
283
+ Key: `tmp/email_out/raw/${container.uuid}`,
284
+ }
285
+
286
+ // -> Execute the query.
287
+ s3.deleteObject(params, (error, data) => {
288
+ // 1. Check for internal errors.
289
+ if (error)
290
+ return reject(error)
291
+
292
+ // -> Move to the next chain.
293
+ return resolve(container)
294
+ })
295
+ })
296
+ }