diff --git a/lib/get-raw-email.js b/lib/get-raw-email.js index 119252d4..af5e2b1f 100644 --- a/lib/get-raw-email.js +++ b/lib/get-raw-email.js @@ -16,7 +16,7 @@ const crypto = require('crypto'); const { MIME_BOUNDARY_PREFIX } = require('./consts'); function getKeyHeader(licenseInfo) { - if (!licenseInfo) { + if (!licenseInfo?.details?.key) { return 'UNLICENSED_COPY'; } return msgpack.encode({ n: crypto.randomBytes(4), t: Date.now(), l: Buffer.from(licenseInfo.details.key, 'hex') }).toString('base64url'); diff --git a/test/api-test.js b/test/api-test.js index 0ba9836d..f85a2910 100644 --- a/test/api-test.js +++ b/test/api-test.js @@ -395,6 +395,48 @@ test('API tests', async t => { assert.strictEqual(messageNewWebhook.data.subject, 'Fwd: Test message 🤣'); }); + await t.test('submit by reference', async () => { + const response = await server + .post(`/v1/account/${defaultAccountId}/submit`) + .send({ + reference: { + message: message2.id, + action: 'forward', + inline: true, + forwardAttachments: true, + messageId: '' + }, + to: [ + { + name: 'Test Received', + address: 'test.received@example.com' + } + ], + text: 'Hallo hallo! 🙃', + html: 'Hallo hallo! 🙃', + messageId: '' + }) + .expect(200); + + assert.ok(response.body.messageId); + assert.ok(response.body.queueId); + + let received = false; + let messageNewWebhook = false; + while (!received) { + await new Promise(r => setTimeout(r, 1000)); + let webhooks = webhooksServer.webhooks.get(defaultAccountId); + messageNewWebhook = webhooks.find(wh => wh.path === 'INBOX' && wh.event === 'messageNew' && wh.data.messageId === ''); + if (messageNewWebhook) { + received = true; + } + } + + assert.ok(/Begin forwarded message/.test(messageNewWebhook.data.text.plain)); + assert.strictEqual(messageNewWebhook.data.attachments[0].filename, 'transparent.gif'); + assert.strictEqual(messageNewWebhook.data.subject, 'Fwd: Test message 🤣'); + }); + await t.test('create a mailbox', async () => { const response = await server .post(`/v1/account/${defaultAccountId}/mailbox`)