Skip to content

Commit 37b6793

Browse files
authored
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
1 parent aacf132 commit 37b6793

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

lib/api/submit.js

+19-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const Transform = require('stream').Transform;
1515
const { sessSchema, sessIPSchema, booleanSchema, metaDataSchema } = require('../schemas');
1616
const { preprocessAttachments } = require('../data-url');
1717
const { userId, mailboxId } = require('../schemas/request/general-schemas');
18-
const { AddressOptionalName, AddressOptionalNameArray, Header, Attachment, ReferenceWithAttachments } = require('../schemas/request/messages-schemas');
18+
const { AddressOptionalName, AddressOptionalNameArray, Header, ReferenceWithoutAttachments } = require('../schemas/request/messages-schemas');
1919
const { successRes } = require('../schemas/response/general-schemas');
2020

2121
class StreamCollect extends Transform {
@@ -631,7 +631,7 @@ module.exports = (db, server, messageHandler, userHandler, settingsHandler) => {
631631
description: 'Use this method to send emails from a user account',
632632
validationObjs: {
633633
requestBody: {
634-
mailbox: mailboxId,
634+
mailbox: Joi.string().hex().lowercase().length(24).description('ID of the Mailbox'),
635635
from: AddressOptionalName.description('Addres for the From: header'),
636636
replyTo: AddressOptionalName.description('Address for the Reply-To: header'),
637637
to: Joi.array()
@@ -664,12 +664,27 @@ module.exports = (db, server, messageHandler, userHandler, settingsHandler) => {
664664
.empty('')
665665
.max(1024 * 1024)
666666
.description('HTML formatted message'),
667-
attachments: Joi.array().items(Attachment).description('Attachments for the message'),
667+
attachments: Joi.array()
668+
.items(
669+
Joi.object({
670+
filename: Joi.string().empty('').max(255).description('Attachment filename'),
671+
contentType: Joi.string().empty('').max(255).description('MIME type for the attachment file'),
672+
encoding: Joi.string().empty('').default('base64').description('Encoding to use to store the attachments'),
673+
contentTransferEncoding: Joi.string().empty('').description('Transfer encoding'),
674+
contentDisposition: Joi.string().empty('').trim().lowercase().valid('inline', 'attachment').description('Content Disposition'),
675+
content: Joi.string().required().description('Base64 encoded attachment content'),
676+
cid: Joi.string()
677+
.empty('')
678+
.max(255)
679+
.description('Content-ID value if you want to reference to this attachment from HTML formatted message')
680+
})
681+
)
682+
.description('Attachments for the message'),
668683

669684
meta: metaDataSchema.label('metaData').description('Optional metadata, must be an object or JSON formatted string'),
670685
sess: sessSchema,
671686
ip: sessIPSchema,
672-
reference: ReferenceWithAttachments.description(
687+
reference: ReferenceWithoutAttachments.description(
673688
'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'
674689
),
675690
// if true then treat this message as a draft

lib/schemas/request/messages-schemas.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ const Attachment = Joi.object({
3030
encoding: Joi.string().empty('').default('base64').description('Encoding to use to store the attachments'),
3131
contentTransferEncoding: Joi.string().empty('').description('Transfer encoding'),
3232
content: Joi.string().required().description('Base64 encoded attachment content'),
33-
cid: Joi.string().empty('').max(255).description('Content-ID value if you want to reference to this attachment from HTML formatted message')
33+
cid: Joi.string().empty('').max(255).description('Content-ID value if you want to reference to this attachment from HTML formatted message'),
34+
contentDisposition: Joi.string().empty('').trim().lowercase().valid('inline', 'attachment').description('Content Disposition')
3435
}).$_setFlag('objectName', 'Attachment');
3536

3637
const ReferenceWithAttachments = Joi.object({
@@ -51,6 +52,12 @@ const ReferenceWithAttachments = Joi.object({
5152
)
5253
}).$_setFlag('objectName', 'ReferenceWithAttachments');
5354

55+
const ReferenceWithoutAttachments = Joi.object({
56+
mailbox: mailboxId,
57+
id: messageId,
58+
action: Joi.string().valid('reply', 'replyAll', 'forward').required().description('Either reply, replyAll or forward')
59+
}).$_setFlag('objectName', 'Reference');
60+
5461
const Bimi = Joi.object({
5562
domain: Joi.string().domain().required().description('Domain name for the BIMI record. It does not have to be the same as the From address.'),
5663
selector: Joi.string().empty('').max(255).description('Optional BIMI selector')
@@ -63,5 +70,6 @@ module.exports = {
6370
Header,
6471
Attachment,
6572
ReferenceWithAttachments,
66-
Bimi
73+
Bimi,
74+
ReferenceWithoutAttachments
6775
};

0 commit comments

Comments
 (0)