Skip to content

Commit

Permalink
Use unified message reference schema
Browse files Browse the repository at this point in the history
  • Loading branch information
andris9 committed Oct 23, 2024
1 parent 11ae775 commit 5e44df2
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 98 deletions.
50 changes: 49 additions & 1 deletion lib/schemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -1477,6 +1477,53 @@ const outboxEntrySchema = Joi.object({
}).label('OutboxEntryProgress')
}).label('OutboxEntry');

const messageReferenceSchema = Joi.object({
message: Joi.string()
.base64({ paddingRequired: false, urlSafe: true })
.max(256)
.required()
.example('AAAAAQAACnA')
.description("The EmailEngine-specific ID of the referenced message. Note: This is not the Message-ID found in the email's headers"),
action: Joi.string()
.lowercase()
.valid('forward', 'reply')
.example('reply')
.default('reply')
.description("Specifies the action to perform on the referenced message. Possible values are 'reply' or 'forward'"),
inline: Joi.boolean()
.truthy('Y', 'true', '1')
.falsy('N', 'false', 0)
.default(false)
.description('When set to `true`, includes the original email content as blockquoted text in the reply')
.label('InlineReply'),
forwardAttachments: Joi.boolean()
.truthy('Y', 'true', '1')
.falsy('N', 'false', 0)
.default(false)
.description('When set to `true`, includes attachments from the original email in the forwarded message')
.when('action', {
is: 'forward',
then: Joi.optional(),
otherwise: Joi.forbidden()
})
.label('ForwardAttachments'),
ignoreMissing: Joi.boolean()
.truthy('Y', 'true', '1')
.falsy('N', 'false', 0)
.default(false)
.description('When set to `true`, processes the email even if the original referenced message is no longer available.')
.label('IgnoreMissing'),
messageId: Joi.string()
.max(996)
.example('<[email protected]>')
.description(
"Specifies the expected Message-ID of the referenced email. When set, the reference action (such as 'reply' or 'forward') will only proceed if the Message-ID of the referenced email matches this value. If the Message-IDs do not match, an error is returned. This ensures that the action is applied to the correct email."
),
documentStore: documentStoreSchema.default(false).meta({ swaggerHidden: true })
})
.description('Contains information needed when replying to or forwarding an email')
.label('MessageReference');

module.exports = {
ADDRESS_STRATEGIES,

Expand Down Expand Up @@ -1513,7 +1560,8 @@ module.exports = {
fromAddressSchema,
outboxEntrySchema,
googleProjectIdSchema,
googleWorkspaceAccountsSchema
googleWorkspaceAccountsSchema,
messageReferenceSchema
};

/*
Expand Down
101 changes: 4 additions & 97 deletions workers/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ const {
fromAddressSchema,
outboxEntrySchema,
googleProjectIdSchema,
googleWorkspaceAccountsSchema
googleWorkspaceAccountsSchema,
messageReferenceSchema
} = require('../lib/schemas');

const listMessageFolderPathDescription =
Expand Down Expand Up @@ -4163,54 +4164,7 @@ const init = async () => {
flags: Joi.array().items(Joi.string().max(128)).example(['\\Seen', '\\Draft']).default([]).description('Message flags').label('Flags'),
internalDate: Joi.date().iso().example('2021-07-08T07:06:34.336Z').description('Sets the internal date for this message'),

reference: Joi.object({
message: Joi.string()
.base64({ paddingRequired: false, urlSafe: true })
.max(256)
.required()
.example('AAAAAQAACnA')
.description(
"The EmailEngine-specific ID of the referenced message. Note: This is not the Message-ID found in the email's headers"
),
action: Joi.string()
.lowercase()
.valid('forward', 'reply')
.example('reply')
.default('reply')
.description("Specifies the action to perform on the referenced message. Possible values are 'reply' or 'forward'"),
inline: Joi.boolean()
.truthy('Y', 'true', '1')
.falsy('N', 'false', 0)
.default(false)
.description('When set to `true`, includes the original email content as blockquoted text in the reply')
.label('InlineReply'),
forwardAttachments: Joi.boolean()
.truthy('Y', 'true', '1')
.falsy('N', 'false', 0)
.default(false)
.description('When set to `true`, includes attachments from the original email in the forwarded message')
.when('action', {
is: 'forward',
then: Joi.optional(),
otherwise: Joi.forbidden()
})
.label('ForwardAttachments'),
ignoreMissing: Joi.boolean()
.truthy('Y', 'true', '1')
.falsy('N', 'false', 0)
.default(false)
.description('When set to `true`, processes the email even if the original referenced message is no longer available.')
.label('IgnoreMissing'),
messageId: Joi.string()
.max(996)
.example('<[email protected]>')
.description(
"Specifies the expected Message-ID of the referenced email. When set, the reference action (such as 'reply' or 'forward') will only proceed if the Message-ID of the referenced email matches this value. If the Message-IDs do not match, an error is returned. This ensures that the action is applied to the correct email."
),
documentStore: documentStoreSchema.default(false).meta({ swaggerHidden: true })
})
.description('Contains information needed when replying to or forwarding an email')
.label('MessageReference'),
reference: messageReferenceSchema,

raw: Joi.string()
.base64()
Expand Down Expand Up @@ -5285,54 +5239,7 @@ const init = async () => {
}),

payload: Joi.object({
reference: Joi.object({
message: Joi.string()
.base64({ paddingRequired: false, urlSafe: true })
.max(256)
.required()
.example('AAAAAQAACnA')
.description(
"The EmailEngine-specific ID of the referenced message. Note: This is not the Message-ID found in the email's headers"
),
action: Joi.string()
.lowercase()
.valid('forward', 'reply')
.example('reply')
.default('reply')
.description("Specifies the action to perform on the referenced message. Possible values are 'reply' or 'forward'"),
inline: Joi.boolean()
.truthy('Y', 'true', '1')
.falsy('N', 'false', 0)
.default(false)
.description('When set to `true`, includes the original email content as blockquoted text in the reply')
.label('InlineReply'),
forwardAttachments: Joi.boolean()
.truthy('Y', 'true', '1')
.falsy('N', 'false', 0)
.default(false)
.description('When set to `true`, includes attachments from the original email in the forwarded message')
.when('action', {
is: 'forward',
then: Joi.optional(),
otherwise: Joi.forbidden()
})
.label('ForwardAttachments'),
ignoreMissing: Joi.boolean()
.truthy('Y', 'true', '1')
.falsy('N', 'false', 0)
.default(false)
.description('When set to `true`, processes the email even if the original referenced message is no longer available.')
.label('IgnoreMissing'),
messageId: Joi.string()
.max(996)
.example('<[email protected]>')
.description(
"Specifies the expected Message-ID of the referenced email. When set, the reference action (such as 'reply' or 'forward') will only proceed if the Message-ID of the referenced email matches this value. If the Message-IDs do not match, an error is returned. This ensures that the action is applied to the correct email."
),
documentStore: documentStoreSchema.default(false).meta({ swaggerHidden: true })
})
.description('Contains information needed when replying to or forwarding an email')
.label('MessageReference'),
reference: messageReferenceSchema,

envelope: Joi.object({
from: Joi.string().email().allow('').example('[email protected]'),
Expand Down

0 comments on commit 5e44df2

Please sign in to comment.