snapshot of https://github.com/RocketChat/Rocket.Chat.git (develop, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s
This commit is contained in:
258
apps/meteor/server/api/v1/email-inbox.ts
Normal file
258
apps/meteor/server/api/v1/email-inbox.ts
Normal file
@@ -0,0 +1,258 @@
|
||||
import type { IEmailInbox } from '@rocket.chat/core-typings';
|
||||
import { EmailInbox, Users } from '@rocket.chat/models';
|
||||
import {
|
||||
ajv,
|
||||
isEmailInboxList,
|
||||
isEmailInbox,
|
||||
isEmailInboxSearch,
|
||||
validateBadRequestErrorResponse,
|
||||
validateForbiddenErrorResponse,
|
||||
validateNotFoundErrorResponse,
|
||||
validateUnauthorizedErrorResponse,
|
||||
} from '@rocket.chat/rest-typings';
|
||||
|
||||
import { sendTestEmailToInbox } from '../../features/EmailInbox/EmailInbox_Outgoing';
|
||||
import { API } from '../api';
|
||||
import { findEmailInboxes, insertOneEmailInbox, removeEmailInbox, updateEmailInbox } from '../lib/emailInbox';
|
||||
import { getPaginationItems } from '../lib/getPaginationItems';
|
||||
|
||||
const paginatedEmailInboxesResponseSchema = ajv.compile<{ emailInboxes: IEmailInbox[]; total: number; count: number; offset: number }>({
|
||||
type: 'object',
|
||||
properties: {
|
||||
emailInboxes: { type: 'array', items: { $ref: '#/components/schemas/IEmailInbox' } },
|
||||
total: { type: 'number' },
|
||||
count: { type: 'number' },
|
||||
offset: { type: 'number' },
|
||||
success: { type: 'boolean', enum: [true] },
|
||||
},
|
||||
required: ['emailInboxes', 'total', 'count', 'offset', 'success'],
|
||||
additionalProperties: false,
|
||||
});
|
||||
|
||||
API.v1.get(
|
||||
'email-inbox.list',
|
||||
{
|
||||
authRequired: true,
|
||||
permissionsRequired: ['manage-email-inbox'],
|
||||
query: isEmailInboxList,
|
||||
response: {
|
||||
200: paginatedEmailInboxesResponseSchema,
|
||||
400: validateBadRequestErrorResponse,
|
||||
401: validateUnauthorizedErrorResponse,
|
||||
403: validateForbiddenErrorResponse,
|
||||
},
|
||||
},
|
||||
async function action() {
|
||||
const { offset, count } = await getPaginationItems(this.queryParams);
|
||||
const { sort, query } = await this.parseJsonQuery();
|
||||
const emailInboxes = await findEmailInboxes({ query, pagination: { offset, count, sort } });
|
||||
|
||||
return API.v1.success(emailInboxes);
|
||||
},
|
||||
);
|
||||
|
||||
API.v1.post(
|
||||
'email-inbox',
|
||||
{
|
||||
authRequired: true,
|
||||
permissionsRequired: ['manage-email-inbox'],
|
||||
body: isEmailInbox,
|
||||
response: {
|
||||
200: ajv.compile<{ _id: string }>({
|
||||
type: 'object',
|
||||
properties: { _id: { type: 'string' }, success: { type: 'boolean', enum: [true] } },
|
||||
required: ['_id', 'success'],
|
||||
additionalProperties: false,
|
||||
}),
|
||||
400: ajv.compile({
|
||||
type: 'object',
|
||||
properties: { success: { type: 'boolean', enum: [false] }, error: { type: 'string' } },
|
||||
required: ['success', 'error'],
|
||||
additionalProperties: false,
|
||||
}),
|
||||
401: validateUnauthorizedErrorResponse,
|
||||
403: validateForbiddenErrorResponse,
|
||||
},
|
||||
},
|
||||
async function action() {
|
||||
const body = this.bodyParams;
|
||||
const maxRetries =
|
||||
'maxRetries' in body.imap && typeof (body.imap as { maxRetries?: number }).maxRetries === 'number'
|
||||
? (body.imap as { maxRetries: number }).maxRetries
|
||||
: 5;
|
||||
const emailInboxParams = {
|
||||
...body,
|
||||
imap: {
|
||||
...body.imap,
|
||||
maxRetries,
|
||||
},
|
||||
};
|
||||
|
||||
let _id: string;
|
||||
|
||||
if (!emailInboxParams?._id) {
|
||||
const { insertedId } = await insertOneEmailInbox(this.userId, emailInboxParams);
|
||||
|
||||
if (!insertedId) {
|
||||
return API.v1.failure('Failed to create email inbox');
|
||||
}
|
||||
|
||||
_id = insertedId;
|
||||
} else {
|
||||
const emailInbox = await updateEmailInbox({ ...emailInboxParams, _id: emailInboxParams._id });
|
||||
|
||||
if (!emailInbox?._id) {
|
||||
return API.v1.failure('Failed to update email inbox');
|
||||
}
|
||||
|
||||
_id = emailInbox._id;
|
||||
}
|
||||
|
||||
return API.v1.success({ _id });
|
||||
},
|
||||
);
|
||||
|
||||
API.v1.get(
|
||||
'email-inbox/:_id',
|
||||
{
|
||||
authRequired: true,
|
||||
permissionsRequired: ['manage-email-inbox'],
|
||||
response: {
|
||||
200: ajv.compile<IEmailInbox | null>({
|
||||
oneOf: [
|
||||
{
|
||||
allOf: [
|
||||
{ $ref: '#/components/schemas/IEmailInbox' },
|
||||
{
|
||||
type: 'object',
|
||||
properties: {
|
||||
success: { type: 'boolean', enum: [true] },
|
||||
},
|
||||
required: ['success'],
|
||||
},
|
||||
],
|
||||
},
|
||||
{ type: 'null' },
|
||||
],
|
||||
}),
|
||||
401: validateUnauthorizedErrorResponse,
|
||||
403: validateForbiddenErrorResponse,
|
||||
404: validateNotFoundErrorResponse,
|
||||
},
|
||||
},
|
||||
async function action() {
|
||||
const { _id } = this.urlParams;
|
||||
if (!_id) {
|
||||
throw new Error('error-invalid-param');
|
||||
}
|
||||
const emailInbox = await EmailInbox.findOneById(_id);
|
||||
|
||||
if (!emailInbox) {
|
||||
return API.v1.notFound();
|
||||
}
|
||||
|
||||
return API.v1.success(emailInbox);
|
||||
},
|
||||
);
|
||||
|
||||
API.v1.delete(
|
||||
'email-inbox/:_id',
|
||||
{
|
||||
authRequired: true,
|
||||
permissionsRequired: ['manage-email-inbox'],
|
||||
response: {
|
||||
200: ajv.compile<{ _id: string }>({
|
||||
type: 'object',
|
||||
properties: { _id: { type: 'string' }, success: { type: 'boolean', enum: [true] } },
|
||||
required: ['_id', 'success'],
|
||||
additionalProperties: false,
|
||||
}),
|
||||
401: validateUnauthorizedErrorResponse,
|
||||
403: validateForbiddenErrorResponse,
|
||||
404: validateNotFoundErrorResponse,
|
||||
},
|
||||
},
|
||||
async function action() {
|
||||
const { _id } = this.urlParams;
|
||||
if (!_id) {
|
||||
throw new Error('error-invalid-param');
|
||||
}
|
||||
|
||||
const { deletedCount } = await removeEmailInbox(_id);
|
||||
|
||||
if (!deletedCount) {
|
||||
return API.v1.notFound();
|
||||
}
|
||||
|
||||
return API.v1.success({ _id });
|
||||
},
|
||||
);
|
||||
|
||||
API.v1.get(
|
||||
'email-inbox.search',
|
||||
{
|
||||
authRequired: true,
|
||||
permissionsRequired: ['manage-email-inbox'],
|
||||
query: isEmailInboxSearch,
|
||||
response: {
|
||||
200: ajv.compile<{ emailInbox: IEmailInbox | null }>({
|
||||
type: 'object',
|
||||
properties: {
|
||||
emailInbox: { oneOf: [{ $ref: '#/components/schemas/IEmailInbox' }, { type: 'null' }] },
|
||||
success: { type: 'boolean', enum: [true] },
|
||||
},
|
||||
required: ['emailInbox', 'success'],
|
||||
additionalProperties: false,
|
||||
}),
|
||||
400: validateBadRequestErrorResponse,
|
||||
401: validateUnauthorizedErrorResponse,
|
||||
403: validateForbiddenErrorResponse,
|
||||
},
|
||||
},
|
||||
async function action() {
|
||||
const { email } = this.queryParams;
|
||||
|
||||
const emailInbox = await EmailInbox.findByEmail(email);
|
||||
|
||||
return API.v1.success({ emailInbox });
|
||||
},
|
||||
);
|
||||
|
||||
API.v1.post(
|
||||
'email-inbox.send-test/:_id',
|
||||
{
|
||||
authRequired: true,
|
||||
permissionsRequired: ['manage-email-inbox'],
|
||||
response: {
|
||||
200: ajv.compile<{ _id: string }>({
|
||||
type: 'object',
|
||||
properties: { _id: { type: 'string' }, success: { type: 'boolean', enum: [true] } },
|
||||
required: ['_id', 'success'],
|
||||
additionalProperties: false,
|
||||
}),
|
||||
401: validateUnauthorizedErrorResponse,
|
||||
403: validateForbiddenErrorResponse,
|
||||
404: validateNotFoundErrorResponse,
|
||||
},
|
||||
},
|
||||
async function action() {
|
||||
const { _id } = this.urlParams;
|
||||
if (!_id) {
|
||||
throw new Error('error-invalid-param');
|
||||
}
|
||||
const emailInbox = await EmailInbox.findOneById(_id);
|
||||
|
||||
if (!emailInbox) {
|
||||
return API.v1.notFound();
|
||||
}
|
||||
|
||||
const user = await Users.findOneById(this.userId);
|
||||
if (!user) {
|
||||
return API.v1.notFound();
|
||||
}
|
||||
|
||||
await sendTestEmailToInbox(emailInbox, user);
|
||||
|
||||
return API.v1.success({ _id });
|
||||
},
|
||||
);
|
||||
Reference in New Issue
Block a user