Skip to content

Commit

Permalink
fix(api-submit): Fix submit.js mailboxId and reference request fields…
Browse files Browse the repository at this point in the history
… ZMS-158 (#690)

* Added submission api endpoint to api docs generation

* submit.js fix request, fix message request types
  • Loading branch information
NickOvt committed May 16, 2024
1 parent aacf132 commit 37b6793
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
23 changes: 19 additions & 4 deletions lib/api/submit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
12 changes: 10 additions & 2 deletions lib/schemas/request/messages-schemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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')
Expand All @@ -63,5 +70,6 @@ module.exports = {
Header,
Attachment,
ReferenceWithAttachments,
Bimi
Bimi,
ReferenceWithoutAttachments
};

0 comments on commit 37b6793

Please sign in to comment.