1 | import path from 'path' |
||
2 | import chalk from 'chalk' |
||
3 | import fs from 'fs' |
||
4 | import mkdir from './library/mkdir' |
||
5 | |||
6 | const successTemplate = fs.readFileSync(`${__dirname}/templates/success.xml`, { encoding: 'utf-8' }) |
||
7 | |||
8 | const sendRawEmail = (req, res, dateDir, fullDir, log) => { |
||
9 | if (!req.body['RawMessage.Data']) { |
||
10 | throw new Error('RawMessage.Data is required and was not sent') |
||
11 | } |
||
12 | |||
13 | mkdir(path.join(dateDir)) |
||
14 | mkdir(path.join(fullDir)) |
||
15 | log(` 🍣 ${chalk.green('Raw Email Received')} |
||
16 | ${chalk.blue('From:')} ${req.body.Source} |
||
17 | ${chalk.blue('To:')} ${req.body['Destinations.member.1']} |
||
18 | ${chalk.blue('Raw Message:')} ${process.cwd()}/${path.join(fullDir)}/raw-message |
||
19 | `) |
||
20 | const decodedBody = Buffer.from(req.body['RawMessage.Data'], 'base64').toString() |
||
0 ignored issues
–
show
|
|||
21 | fs.writeFileSync(`${fullDir}/raw-message`, decodedBody) |
||
22 | |||
23 | res.status(200).send( |
||
24 | successTemplate.replace('{{message}}', `${process.cwd()}/${path.join(fullDir)}/raw-message`) |
||
25 | ) |
||
26 | } |
||
27 | |||
28 | module.exports = sendRawEmail |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.