From 37b6793976c9d73dc7796bb0f1072472569f4f5b Mon Sep 17 00:00:00 2001 From: NickOvt Date: Thu, 16 May 2024 10:00:50 +0300 Subject: [PATCH] fix(api-submit): Fix submit.js mailboxId and reference request fields ZMS-158 (#690) * Added submission api endpoint to api docs generation * submit.js fix request, fix message request types --- lib/api/submit.js | 23 +++++++++++++++++++---- lib/schemas/request/messages-schemas.js | 12 ++++++++++-- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/lib/api/submit.js b/lib/api/submit.js index 47af61c9..8e35dd98 100644 --- a/lib/api/submit.js +++ b/lib/api/submit.js @@ -15,7 +15,7 @@ const Transform = require('stream').Transform; const { sessSchema, sessIPSchema, booleanSchema, metaDataSchema } = require('../schemas'); const { preprocessAttachments } = require('../data-url'); const { userId, mailboxId } = require('../schemas/request/general-schemas'); -const { AddressOptionalName, AddressOptionalNameArray, Header, Attachment, ReferenceWithAttachments } = require('../schemas/request/messages-schemas'); +const { AddressOptionalName, AddressOptionalNameArray, Header, ReferenceWithoutAttachments } = require('../schemas/request/messages-schemas'); const { successRes } = require('../schemas/response/general-schemas'); class StreamCollect extends Transform { @@ -631,7 +631,7 @@ module.exports = (db, server, messageHandler, userHandler, settingsHandler) => { description: 'Use this method to send emails from a user account', validationObjs: { requestBody: { - mailbox: mailboxId, + mailbox: Joi.string().hex().lowercase().length(24).description('ID of the Mailbox'), from: AddressOptionalName.description('Addres for the From: header'), replyTo: AddressOptionalName.description('Address for the Reply-To: header'), to: Joi.array() @@ -664,12 +664,27 @@ module.exports = (db, server, messageHandler, userHandler, settingsHandler) => { .empty('') .max(1024 * 1024) .description('HTML formatted message'), - attachments: Joi.array().items(Attachment).description('Attachments for the message'), + attachments: Joi.array() + .items( + Joi.object({ + filename: Joi.string().empty('').max(255).description('Attachment filename'), + contentType: Joi.string().empty('').max(255).description('MIME type for the attachment file'), + encoding: Joi.string().empty('').default('base64').description('Encoding to use to store the attachments'), + contentTransferEncoding: Joi.string().empty('').description('Transfer encoding'), + contentDisposition: Joi.string().empty('').trim().lowercase().valid('inline', 'attachment').description('Content Disposition'), + content: Joi.string().required().description('Base64 encoded attachment content'), + cid: Joi.string() + .empty('') + .max(255) + .description('Content-ID value if you want to reference to this attachment from HTML formatted message') + }) + ) + .description('Attachments for the message'), meta: metaDataSchema.label('metaData').description('Optional metadata, must be an object or JSON formatted string'), sess: sessSchema, ip: sessIPSchema, - reference: ReferenceWithAttachments.description( + reference: ReferenceWithoutAttachments.description( 'Optional referenced email. If uploaded message is a reply draft and relevant fields are not provided then these are resolved from the message to be replied to' ), // if true then treat this message as a draft diff --git a/lib/schemas/request/messages-schemas.js b/lib/schemas/request/messages-schemas.js index 48de170c..12c53d89 100644 --- a/lib/schemas/request/messages-schemas.js +++ b/lib/schemas/request/messages-schemas.js @@ -30,7 +30,8 @@ const Attachment = Joi.object({ encoding: Joi.string().empty('').default('base64').description('Encoding to use to store the attachments'), contentTransferEncoding: Joi.string().empty('').description('Transfer encoding'), content: Joi.string().required().description('Base64 encoded attachment content'), - cid: Joi.string().empty('').max(255).description('Content-ID value if you want to reference to this attachment from HTML formatted message') + cid: Joi.string().empty('').max(255).description('Content-ID value if you want to reference to this attachment from HTML formatted message'), + contentDisposition: Joi.string().empty('').trim().lowercase().valid('inline', 'attachment').description('Content Disposition') }).$_setFlag('objectName', 'Attachment'); const ReferenceWithAttachments = Joi.object({ @@ -51,6 +52,12 @@ const ReferenceWithAttachments = Joi.object({ ) }).$_setFlag('objectName', 'ReferenceWithAttachments'); +const ReferenceWithoutAttachments = Joi.object({ + mailbox: mailboxId, + id: messageId, + action: Joi.string().valid('reply', 'replyAll', 'forward').required().description('Either reply, replyAll or forward') +}).$_setFlag('objectName', 'Reference'); + const Bimi = Joi.object({ domain: Joi.string().domain().required().description('Domain name for the BIMI record. It does not have to be the same as the From address.'), selector: Joi.string().empty('').max(255).description('Optional BIMI selector') @@ -63,5 +70,6 @@ module.exports = { Header, Attachment, ReferenceWithAttachments, - Bimi + Bimi, + ReferenceWithoutAttachments };