Skip to content

Commit 70ebdbc

Browse files
committed
messages.js finish with GET endpoints, addition to API doc generation
1 parent 9234b0d commit 70ebdbc

File tree

1 file changed

+171
-32
lines changed

1 file changed

+171
-32
lines changed

Diff for: lib/api/messages.js

+171-32
Original file line numberDiff line numberDiff line change
@@ -1393,14 +1393,41 @@ module.exports = (db, server, messageHandler, userHandler, storageHandler, setti
13931393
);
13941394

13951395
server.get(
1396-
{ name: 'raw', path: '/users/:user/mailboxes/:mailbox/messages/:message/message.eml' },
1396+
{
1397+
name: 'raw',
1398+
path: '/users/:user/mailboxes/:mailbox/messages/:message/message.eml',
1399+
summary: 'Get Message source',
1400+
description: 'This method returns the full RFC822 formatted source of the stored message',
1401+
validationObjs: {
1402+
pathParams: {
1403+
user: userId,
1404+
mailbox: mailboxId,
1405+
message: messageId
1406+
},
1407+
queryParams: {
1408+
sess: sessSchema,
1409+
ip: sessIPSchema
1410+
},
1411+
requestBody: {},
1412+
response: {
1413+
200: {
1414+
description: 'Success',
1415+
model: Joi.object({
1416+
success: Joi.object({}).description('Success')
1417+
})
1418+
}
1419+
}
1420+
},
1421+
responseType: 'message/rfc822',
1422+
tags: ['Messages']
1423+
},
13971424
tools.responseWrapper(async (req, res) => {
1398-
const schema = Joi.object().keys({
1399-
user: Joi.string().hex().lowercase().length(24).required(),
1400-
mailbox: Joi.string().hex().lowercase().length(24).required(),
1401-
message: Joi.number().min(1).required(),
1402-
sess: sessSchema,
1403-
ip: sessIPSchema
1425+
const { pathParams, queryParams, requestBody } = req.route.spec.validationObjs;
1426+
1427+
const schema = Joi.object({
1428+
...pathParams,
1429+
...queryParams,
1430+
...requestBody
14041431
});
14051432

14061433
const result = schema.validate(req.params, {
@@ -1489,16 +1516,43 @@ module.exports = (db, server, messageHandler, userHandler, storageHandler, setti
14891516
);
14901517

14911518
server.get(
1492-
{ name: 'attachment', path: '/users/:user/mailboxes/:mailbox/messages/:message/attachments/:attachment' },
1519+
{
1520+
name: 'attachment',
1521+
path: '/users/:user/mailboxes/:mailbox/messages/:message/attachments/:attachment',
1522+
summary: 'Download Attachment',
1523+
description: 'This method returns attachment file contents in binary form',
1524+
validationObjs: {
1525+
queryParams: {},
1526+
pathParams: {
1527+
user: userId,
1528+
mailbox: mailboxId,
1529+
message: messageId,
1530+
attachment: Joi.string()
1531+
.regex(/^ATT\d+$/i)
1532+
.uppercase()
1533+
.required()
1534+
.description('ID of the Attachment')
1535+
},
1536+
requestBody: {},
1537+
response: {
1538+
200: {
1539+
description: 'Success',
1540+
model: Joi.object({
1541+
success: Joi.binary()
1542+
})
1543+
}
1544+
}
1545+
},
1546+
responseType: 'application/octet-stream',
1547+
tags: ['Messages']
1548+
},
14931549
tools.responseWrapper(async (req, res) => {
1494-
const schema = Joi.object().keys({
1495-
user: Joi.string().hex().lowercase().length(24).required(),
1496-
mailbox: Joi.string().hex().lowercase().length(24).required(),
1497-
message: Joi.number().min(1).required(),
1498-
attachment: Joi.string()
1499-
.regex(/^ATT\d+$/i)
1500-
.uppercase()
1501-
.required()
1550+
const { requestBody, queryParams, pathParams } = req.route.spec.validationObjs;
1551+
1552+
const schema = Joi.object({
1553+
...requestBody,
1554+
...queryParams,
1555+
...pathParams
15021556
});
15031557

15041558
const result = schema.validate(req.params, {
@@ -2882,25 +2936,110 @@ module.exports = (db, server, messageHandler, userHandler, storageHandler, setti
28822936
);
28832937

28842938
server.get(
2885-
{ name: 'archived', path: '/users/:user/archived/messages' },
2939+
{
2940+
name: 'archived',
2941+
path: '/users/:user/archived/messages',
2942+
summary: 'List archived messages',
2943+
description: 'Archive contains all recently deleted messages besides Drafts etc.',
2944+
validationObjs: {
2945+
pathParams: {
2946+
user: userId
2947+
},
2948+
queryParams: {
2949+
limit: Joi.number().empty('').default(20).min(1).max(250).description('How many records to return'),
2950+
next: nextPageCursorSchema,
2951+
previous: previousPageCursorSchema,
2952+
order: Joi.any().empty('').allow('asc', 'desc').default('desc').description('Ordering of the records by insert date'),
2953+
includeHeaders: Joi.string()
2954+
.max(1024)
2955+
.trim()
2956+
.empty('')
2957+
.example('List-ID, MIME-Version')
2958+
.description('Comma separated list of header keys to include in the response'),
2959+
page: pageNrSchema,
2960+
sess: sessSchema,
2961+
ip: sessIPSchema
2962+
},
2963+
requestBody: {},
2964+
response: {
2965+
200: {
2966+
description: 'Success',
2967+
model: Joi.object({
2968+
success: booleanSchema.description('Indicates successful response').required(),
2969+
total: Joi.number().description('How many results were found').required(),
2970+
page: Joi.number().description('Current page number. Derived from page query argument').required(),
2971+
previousCursor: Joi.alternatives()
2972+
.try(Joi.string(), booleanSchema)
2973+
.description('Either a cursor string or false if there are not any previous results')
2974+
.required(),
2975+
nextCursor: Joi.alternatives()
2976+
.try(Joi.string(), booleanSchema)
2977+
.description('Either a cursor string or false if there are not any next results')
2978+
.required(),
2979+
specialUse: Joi.string().description('Special use. If available').required(),
2980+
results: Joi.array()
2981+
.items(
2982+
Joi.object({
2983+
id: Joi.number().required().description('ID of the Message'),
2984+
mailbox: Joi.string().required().description('ID of the Mailbox'),
2985+
thread: Joi.string().required().description('ID of the Thread'),
2986+
threadMessageCount: Joi.number().description(
2987+
'Amount of messages in the Thread. Included if threadCounters query argument was true'
2988+
),
2989+
from: Address.description('Sender in From: field'),
2990+
to: Joi.array().items(Address).required().description('Recipients in To: field'),
2991+
cc: Joi.array().items(Address).required().description('Recipients in Cc: field'),
2992+
bcc: Joi.array().items(Address).required().description('Recipients in Bcc: field. Usually only available for drafts'),
2993+
messageId: Joi.string().required().description('Message ID'),
2994+
subject: Joi.string().required().description('Message subject'),
2995+
date: Joi.date().required().description('Date string from header'),
2996+
idate: Joi.date().description('Date string of receive time'),
2997+
intro: Joi.string().required().description('First 128 bytes of the message'),
2998+
attachments: booleanSchema.required().description('Does the message have attachments'),
2999+
size: Joi.number().required().description('Message size in bytes'),
3000+
seen: booleanSchema.required().description('Is this message alread seen or not'),
3001+
deleted: booleanSchema
3002+
.required()
3003+
.description(
3004+
'Does this message have a Deleted flag (should not have as messages are automatically deleted once this flag is set)'
3005+
),
3006+
flagged: booleanSchema.required().description('Does this message have a Flagged flag'),
3007+
draft: booleanSchema.required().description('is this message a draft'),
3008+
answered: booleanSchema.required().description('Does this message have a Answered flag'),
3009+
forwarded: booleanSchema.required().description('Does this message have a $Forwarded flag'),
3010+
references: Joi.array().items(ReferenceWithAttachments).required().description('References'),
3011+
bimi: Bimi.required().description(
3012+
'Marks BIMI verification as passed for a domain. NB! BIMI record and logo files for the domain must be valid.'
3013+
),
3014+
contentType: Joi.object({
3015+
value: Joi.string().required().description('MIME type of the message, eg. "multipart/mixed"'),
3016+
params: Joi.object().required().description('An object with Content-Type params as key-value pairs')
3017+
})
3018+
.$_setFlag('objectName', 'ContentType')
3019+
.required()
3020+
.description('Parsed Content-Type header. Usually needed to identify encrypted messages and such'),
3021+
encrypted: booleanSchema.description('Specifies whether the message is encrypted'),
3022+
metaData: Joi.object().description('Custom metadata value. Included if metaData query argument was true'),
3023+
headers: Joi.object().description('Header object keys requested with the includeHeaders argument')
3024+
}).$_setFlag('objectName', 'GetMessagesResult')
3025+
)
3026+
.required()
3027+
.description('Message listing')
3028+
})
3029+
}
3030+
}
3031+
},
3032+
tags: ['Archive']
3033+
},
28863034
tools.responseWrapper(async (req, res) => {
28873035
res.charSet('utf-8');
28883036

2889-
const schema = Joi.object().keys({
2890-
user: Joi.string().hex().lowercase().length(24).required(),
2891-
limit: Joi.number().empty('').default(20).min(1).max(250),
2892-
next: nextPageCursorSchema,
2893-
previous: previousPageCursorSchema,
2894-
order: Joi.any().empty('').allow('asc', 'desc').default('desc'),
2895-
includeHeaders: Joi.string()
2896-
.max(1024)
2897-
.trim()
2898-
.empty('')
2899-
.example('List-ID, MIME-Version')
2900-
.description('Comma separated list of header keys to include in the response'),
2901-
page: pageNrSchema,
2902-
sess: sessSchema,
2903-
ip: sessIPSchema
3037+
const { pathParams, queryParams, requestBody } = req.route.spec.validationObjs;
3038+
3039+
const schema = Joi.object({
3040+
...pathParams,
3041+
...queryParams,
3042+
...requestBody
29043043
});
29053044

29063045
const result = schema.validate(req.params, {

0 commit comments

Comments
 (0)