diff --git a/packages/inbound-mail-parser/src/parser.d.ts b/packages/inbound-mail-parser/src/parser.d.ts index 1379e3a51..97f08a71a 100644 --- a/packages/inbound-mail-parser/src/parser.d.ts +++ b/packages/inbound-mail-parser/src/parser.d.ts @@ -6,6 +6,7 @@ declare interface ParseConfig { declare interface ParseRequest { body?: {}; + payload?: {}; files?: any[]; } diff --git a/packages/inbound-mail-parser/src/parser.js b/packages/inbound-mail-parser/src/parser.js index 38b639e84..1111c63c0 100644 --- a/packages/inbound-mail-parser/src/parser.js +++ b/packages/inbound-mail-parser/src/parser.js @@ -39,7 +39,7 @@ class Parse { constructor(config, request) { this.keys = config.keys; this.request = request; - this.payload = request.body || {}; + this.payload = request.body || request.payload || {}; this.files = request.files || []; } diff --git a/packages/inbound-mail-parser/src/parser.spec.js b/packages/inbound-mail-parser/src/parser.spec.js index 83d04445a..0add7ec79 100644 --- a/packages/inbound-mail-parser/src/parser.spec.js +++ b/packages/inbound-mail-parser/src/parser.spec.js @@ -2,7 +2,7 @@ const Parse = require('./parser'); describe('test_parse', () => { describe('test_parse_key_values', () => { - it('should return the key values specified in the config from the payload', () => { + it('should return the key values specified in the config from the body', () => { const config = { keys: ['to', 'from'], }; @@ -24,6 +24,29 @@ describe('test_parse', () => { expect(keyValues).to.be.an('object'); expect(keyValues).to.deep.equal(expectedValues); }); + + it('should return the key values specified in the config from the payload', () => { + const config = { + keys: ['to', 'from'], + }; + const request = { + payload: { + to: 'inbound@inbound.example.com', + from: 'Test User ', + subject: 'Test Subject', + }, + }; + + const parse = new Parse(config, request); + const keyValues = parse.keyValues(); + const expectedValues = { + to: 'inbound@inbound.example.com', + from: 'Test User ', + }; + + expect(keyValues).to.be.an('object'); + expect(keyValues).to.deep.equal(expectedValues); + }); }); describe('test_parse_get_raw_email', () => {