Skip to content

Commit 82133df

Browse files
authored
fix(api-submit): Added submission api endpoint to api docs generation (#676)
1 parent 10be9e6 commit 82133df

File tree

1 file changed

+105
-104
lines changed

1 file changed

+105
-104
lines changed

lib/api/submit.js

+105-104
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@ const tools = require('../tools');
1212
const Maildropper = require('../maildropper');
1313
const roles = require('../roles');
1414
const Transform = require('stream').Transform;
15-
const { sessSchema, sessIPSchema, booleanSchema } = require('../schemas');
15+
const { sessSchema, sessIPSchema, booleanSchema, metaDataSchema } = require('../schemas');
1616
const { preprocessAttachments } = require('../data-url');
17+
const { userId, mailboxId } = require('../schemas/request/general-schemas');
18+
const { AddressOptionalName, AddressOptionalNameArray, Header, Attachment, ReferenceWithAttachments } = require('../schemas/request/messages-schemas');
19+
const { successRes } = require('../schemas/response/general-schemas');
1720

1821
class StreamCollect extends Transform {
1922
constructor() {
@@ -620,113 +623,111 @@ module.exports = (db, server, messageHandler, userHandler, settingsHandler) => {
620623
const submitMessageWrapper = util.promisify(submitMessage);
621624

622625
server.post(
623-
{ name: 'send', path: '/users/:user/submit' },
626+
{
627+
name: 'send',
628+
path: '/users/:user/submit',
629+
tags: ['Submission'],
630+
summary: 'Submit a Message for Delivery',
631+
description: 'Use this method to send emails from a user account',
632+
validationObjs: {
633+
requestBody: {
634+
mailbox: mailboxId,
635+
from: AddressOptionalName.description('Addres for the From: header'),
636+
replyTo: AddressOptionalName.description('Address for the Reply-To: header'),
637+
to: Joi.array()
638+
.items(
639+
Joi.object({
640+
name: Joi.string().empty('').max(255).description('Name of the sender'),
641+
address: Joi.string().email({ tlds: false }).failover('').required().description('Address of the sender')
642+
}).$_setFlag('objectName', 'AddressOptionalName')
643+
)
644+
.description('Addresses for the To: header'),
645+
646+
cc: AddressOptionalNameArray.description('Addresses for the Cc: header'),
647+
648+
bcc: AddressOptionalNameArray.description('Addresses for the Bcc: header'),
649+
650+
headers: Joi.array()
651+
.items(Header)
652+
.description(
653+
'Custom headers for the message. If reference message is set then In-Reply-To and References headers are set automatically'
654+
),
655+
subject: Joi.string()
656+
.empty('')
657+
.max(2 * 1024)
658+
.description('Message subject. If not then resolved from Reference message'),
659+
text: Joi.string()
660+
.empty('')
661+
.max(1024 * 1024)
662+
.description('Plaintext message'),
663+
html: Joi.string()
664+
.empty('')
665+
.max(1024 * 1024)
666+
.description('HTML formatted message'),
667+
attachments: Joi.array().items(Attachment).description('Attachments for the message'),
668+
669+
meta: metaDataSchema.label('metaData').description('Optional metadata, must be an object or JSON formatted string'),
670+
sess: sessSchema,
671+
ip: sessIPSchema,
672+
reference: ReferenceWithAttachments.description(
673+
'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'
674+
),
675+
// if true then treat this message as a draft
676+
isDraft: booleanSchema.default(false).description('Is the message a draft or not'),
677+
// if set then this message is based on a draft that should be deleted after processing
678+
draft: Joi.object()
679+
.keys({
680+
mailbox: mailboxId,
681+
id: Joi.number().required().description('Message ID')
682+
})
683+
.description('Draft message to base this one on'),
684+
sendTime: Joi.date().description('Send time'),
685+
uploadOnly: booleanSchema.default(false).description('If true only uploads the message but does not send it'),
686+
envelope: Joi.object()
687+
.keys({
688+
from: AddressOptionalName.description('Addres for the From: header'),
689+
to: Joi.array().items(
690+
Joi.object()
691+
.keys({
692+
name: Joi.string().empty('').max(255).description('Name of the sender'),
693+
address: Joi.string().email({ tlds: false }).required().description('Address of the sender')
694+
})
695+
.description('Addresses for the To: header')
696+
)
697+
})
698+
.description('Optional envelope')
699+
},
700+
queryParams: {},
701+
pathParams: {
702+
user: userId
703+
},
704+
response: {
705+
200: {
706+
description: 'Success',
707+
model: Joi.object({
708+
success: successRes,
709+
message: Joi.object({
710+
mailbox: Joi.string().required().description('Mailbox ID the message was stored to'),
711+
id: Joi.number().description('Message ID in the Mailbox').required(),
712+
queueId: Joi.string().required().description('Queue ID in MTA')
713+
})
714+
.required()
715+
.description('Information about submitted Message')
716+
.$_setFlag('objectName', 'MessageWithQueueId')
717+
})
718+
}
719+
}
720+
}
721+
},
624722
tools.responseWrapper(async (req, res) => {
625723
res.charSet('utf-8');
626724

627-
const schema = Joi.object().keys({
628-
user: Joi.string().hex().lowercase().length(24).required(),
629-
630-
mailbox: Joi.string().hex().lowercase().length(24),
631-
632-
reference: Joi.object().keys({
633-
mailbox: Joi.string().hex().lowercase().length(24).required(),
634-
id: Joi.number().required(),
635-
action: Joi.string().valid('reply', 'replyAll', 'forward').required()
636-
}),
637-
638-
// if true then treat this message as a draft
639-
isDraft: booleanSchema.default(false),
640-
641-
// if set then this message is based on a draft that should be deleted after processing
642-
draft: Joi.object().keys({
643-
mailbox: Joi.string().hex().lowercase().length(24).required(),
644-
id: Joi.number().required()
645-
}),
646-
647-
uploadOnly: booleanSchema.default(false),
725+
const { pathParams, requestBody, queryParams } = req.route.spec.validationObjs;
648726

649-
sendTime: Joi.date(),
650-
651-
envelope: Joi.object().keys({
652-
from: Joi.object().keys({
653-
name: Joi.string().empty('').max(255),
654-
address: Joi.string().email({ tlds: false }).required()
655-
}),
656-
to: Joi.array().items(
657-
Joi.object().keys({
658-
name: Joi.string().empty('').max(255),
659-
address: Joi.string().email({ tlds: false }).required()
660-
})
661-
)
662-
}),
663-
664-
from: Joi.object().keys({
665-
name: Joi.string().empty('').max(255),
666-
address: Joi.string().email({ tlds: false }).required()
667-
}),
668-
669-
replyTo: Joi.object().keys({
670-
name: Joi.string().empty('').max(255),
671-
address: Joi.string().email({ tlds: false }).required()
672-
}),
673-
674-
to: Joi.array().items(
675-
Joi.object().keys({
676-
name: Joi.string().empty('').max(255),
677-
address: Joi.string().email({ tlds: false }).required()
678-
})
679-
),
680-
681-
cc: Joi.array().items(
682-
Joi.object().keys({
683-
name: Joi.string().empty('').max(255),
684-
address: Joi.string().email({ tlds: false }).required()
685-
})
686-
),
687-
688-
bcc: Joi.array().items(
689-
Joi.object().keys({
690-
name: Joi.string().empty('').max(255),
691-
address: Joi.string().email({ tlds: false }).required()
692-
})
693-
),
694-
695-
headers: Joi.array().items(
696-
Joi.object().keys({
697-
key: Joi.string().empty('').max(255),
698-
value: Joi.string()
699-
.empty('')
700-
.max(100 * 1024)
701-
})
702-
),
703-
704-
subject: Joi.string()
705-
.empty('')
706-
.max(2 * 1024),
707-
text: Joi.string()
708-
.empty('')
709-
.max(1024 * 1024),
710-
html: Joi.string()
711-
.empty('')
712-
.max(1024 * 1024),
713-
714-
attachments: Joi.array().items(
715-
Joi.object().keys({
716-
filename: Joi.string().empty('').max(255),
717-
718-
contentType: Joi.string().empty('').max(255),
719-
contentTransferEncoding: Joi.string().empty('').trim().lowercase(),
720-
contentDisposition: Joi.string().empty('').trim().lowercase().valid('inline', 'attachment'),
721-
cid: Joi.string().empty('').max(255),
722-
723-
encoding: Joi.string().empty('').default('base64'),
724-
content: Joi.string().required()
725-
})
726-
),
727-
meta: Joi.object().unknown(true),
728-
sess: sessSchema,
729-
ip: sessIPSchema
727+
const schema = Joi.object({
728+
...pathParams,
729+
...requestBody,
730+
...queryParams
730731
});
731732

732733
// extract embedded attachments from HTML

0 commit comments

Comments
 (0)