From a2d2027969aeec6e5cf10378e83422168be55b8d Mon Sep 17 00:00:00 2001 From: MarryDream <2037177696@qq.com> Date: Sun, 31 Dec 2023 03:27:25 +0800 Subject: [PATCH] fix: Some fixes for #12850 - refinement the error message when trueMail validation fails - the settings of trueMail are not displayed after saving - changing how `Active Email Validation` is saved --- CHANGELOG.md | 3 + packages/backend/src/core/EmailService.ts | 76 +++++++++++++------ .../frontend/src/pages/admin/security.vue | 18 +++-- .../misskey-js/src/autogen/apiClientJSDoc.ts | 5 +- packages/misskey-js/src/autogen/endpoint.ts | 4 +- packages/misskey-js/src/autogen/entities.ts | 4 +- packages/misskey-js/src/autogen/models.ts | 4 +- packages/misskey-js/src/autogen/types.ts | 12 ++- 8 files changed, 81 insertions(+), 45 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ea34fa9ef7f0..37671b42b1df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,9 @@ ## 202x.x.x (Unreleased) +### General +- Feat: Add support for TrueMail + ### Client - Enhance: ハッシュタグ入力時に、本文の末尾の行に何も書かれていない場合は新たにスペースを追加しないように diff --git a/packages/backend/src/core/EmailService.ts b/packages/backend/src/core/EmailService.ts index 7e812b4df243..8400517a0dc1 100644 --- a/packages/backend/src/core/EmailService.ts +++ b/packages/backend/src/core/EmailService.ts @@ -156,7 +156,7 @@ export class EmailService { @bindThis public async validateEmailForAccount(emailAddress: string): Promise<{ available: boolean; - reason: null | 'used' | 'format' | 'disposable' | 'mx' | 'smtp' | 'banned' | 'network' | 'blacklist'; + reason: null | string; }> { const meta = await this.metaService.fetch(); @@ -165,10 +165,17 @@ export class EmailService { email: emailAddress, }); + if (exist !== 0) { + return { + available: false, + reason: 'used', + }; + } + let validated: { valid: boolean, reason?: string | null, - }; + } = { valid: true, reason: null }; if (meta.enableActiveEmailValidation) { if (meta.enableVerifymailApi && meta.verifymailAuthKey != null) { @@ -185,33 +192,38 @@ export class EmailService { validateSMTP: false, // 日本だと25ポートが殆どのプロバイダーで塞がれていてタイムアウトになるので }); } - } else { - validated = { valid: true, reason: null }; + } + + if (!validated.valid) { + let reason = validated.reason ?? null; + if (reason === 'regex') { + reason = 'format'; + } + return { + available: false, + reason, + }; } const emailDomain: string = emailAddress.split('@')[1]; const isBanned = this.utilityService.isBlockedHost(meta.bannedEmailDomains, emailDomain); - const available = exist === 0 && validated.valid && !isBanned; + if (isBanned) { + return { + available: false, + reason: 'banned', + }; + } return { - available, - reason: available ? null : - exist !== 0 ? 'used' : - isBanned ? 'banned' : - validated.reason === 'regex' ? 'format' : - validated.reason === 'disposable' ? 'disposable' : - validated.reason === 'mx' ? 'mx' : - validated.reason === 'smtp' ? 'smtp' : - validated.reason === 'network' ? 'network' : - validated.reason === 'blacklist' ? 'blacklist' : - null, + available: true, + reason: null, }; } private async verifyMail(emailAddress: string, verifymailAuthKey: string): Promise<{ valid: boolean; - reason: 'used' | 'format' | 'disposable' | 'mx' | 'smtp' | null; + reason: 'used' | 'format' | 'disposable' | 'mx' | 'smtp' | 'key' | null; }> { const endpoint = 'https://verifymail.io/api/' + emailAddress + '?key=' + verifymailAuthKey; const res = await this.httpRequestService.send(endpoint, { @@ -223,6 +235,7 @@ export class EmailService { }); const json = (await res.json()) as { + message?: string; block: boolean; catch_all: boolean; deliverable_email: boolean; @@ -239,6 +252,12 @@ export class EmailService { related_domains: string[]; }; + if (json.message) { + return { + valid: false, + reason: 'key', + }; + } if (json.email_address === undefined) { return { valid: false, @@ -272,7 +291,7 @@ export class EmailService { private async trueMail(truemailInstance: string, emailAddress: string, truemailAuthKey: string): Promise<{ valid: boolean; - reason: 'used' | 'format' | 'blacklist' | 'mx' | 'smtp' | 'network' | T | null; + reason: 'key' | 'used' | 'format' | 'blacklist' | 'mx' | 'smtp' | 'network' | T | null; }> { const endpoint = truemailInstance + '?email=' + emailAddress; try { @@ -284,22 +303,29 @@ export class EmailService { Authorization: truemailAuthKey }, }); - + const json = (await res.json()) as { email: string; success: boolean; - errors?: { + error?: string; + errors?: { list_match?: string; regex?: string; mx?: string; smtp?: string; } | null; }; - - if (json.email === undefined || (json.email !== undefined && json.errors?.regex)) { + + if (json.error) { return { - valid: false, - reason: 'format', + valid: false, + reason: 'key', + }; + } + if (json.email === undefined || json.errors?.regex) { + return { + valid: false, + reason: 'format', }; } if (json.errors?.smtp) { @@ -320,7 +346,7 @@ export class EmailService { reason: json.errors?.list_match as T || 'blacklist', }; } - + return { valid: true, reason: null, diff --git a/packages/frontend/src/pages/admin/security.vue b/packages/frontend/src/pages/admin/security.vue index 8d79dea20ff7..0e9b5182f550 100644 --- a/packages/frontend/src/pages/admin/security.vue +++ b/packages/frontend/src/pages/admin/security.vue @@ -70,27 +70,28 @@ SPDX-License-Identifier: AGPL-3.0-only
{{ i18n.ts.activeEmailValidationDescription }} - + - + - + - + - + - + + {{ i18n.ts.save }}
@@ -188,7 +189,10 @@ async function init() { enableActiveEmailValidation.value = meta.enableActiveEmailValidation; enableVerifymailApi.value = meta.enableVerifymailApi; verifymailAuthKey.value = meta.verifymailAuthKey; - bannedEmailDomains.value = meta.bannedEmailDomains.join('\n'); + enableTruemailApi.value = meta.enableTruemailApi; + truemailInstance.value = meta.truemailInstance; + truemailAuthKey.value = meta.truemailAuthKey; + bannedEmailDomains.value = meta.bannedEmailDomains?.join('\n') || ""; } function save() { diff --git a/packages/misskey-js/src/autogen/apiClientJSDoc.ts b/packages/misskey-js/src/autogen/apiClientJSDoc.ts index 758beaf3a022..949ab0772977 100644 --- a/packages/misskey-js/src/autogen/apiClientJSDoc.ts +++ b/packages/misskey-js/src/autogen/apiClientJSDoc.ts @@ -1,6 +1,6 @@ /* - * version: 2023.12.0 - * generatedAt: 2023-12-26T23:35:09.494Z + * version: 2023.12.2 + * generatedAt: 2024-01-02T13:38:55.847Z */ import type { SwitchCaseResponseType } from '../api.js'; @@ -33,7 +33,6 @@ declare module '../api.js' { /** * No description provided. * - * **Internal Endpoint**: This endpoint is an API for the misskey mainframe and is not intended for use by third parties. * **Credential required**: *No* */ request( diff --git a/packages/misskey-js/src/autogen/endpoint.ts b/packages/misskey-js/src/autogen/endpoint.ts index 2ed76a22f964..d77b21c70c79 100644 --- a/packages/misskey-js/src/autogen/endpoint.ts +++ b/packages/misskey-js/src/autogen/endpoint.ts @@ -1,6 +1,6 @@ /* - * version: 2023.12.0 - * generatedAt: 2023-12-26T23:35:09.491Z + * version: 2023.12.2 + * generatedAt: 2024-01-02T13:38:55.835Z */ import type { diff --git a/packages/misskey-js/src/autogen/entities.ts b/packages/misskey-js/src/autogen/entities.ts index c857e8e37006..13ae1aa224ad 100644 --- a/packages/misskey-js/src/autogen/entities.ts +++ b/packages/misskey-js/src/autogen/entities.ts @@ -1,6 +1,6 @@ /* - * version: 2023.12.0 - * generatedAt: 2023-12-26T23:35:09.489Z + * version: 2023.12.2 + * generatedAt: 2024-01-02T13:38:55.831Z */ import { operations } from './types.js'; diff --git a/packages/misskey-js/src/autogen/models.ts b/packages/misskey-js/src/autogen/models.ts index c5b81a6b41ca..82594d0799be 100644 --- a/packages/misskey-js/src/autogen/models.ts +++ b/packages/misskey-js/src/autogen/models.ts @@ -1,6 +1,6 @@ /* - * version: 2023.12.0 - * generatedAt: 2023-12-26T23:35:09.485Z + * version: 2023.12.2 + * generatedAt: 2024-01-02T13:38:55.818Z */ import { components } from './types.js'; diff --git a/packages/misskey-js/src/autogen/types.ts b/packages/misskey-js/src/autogen/types.ts index 94bb2639809f..9b3bc7e40e09 100644 --- a/packages/misskey-js/src/autogen/types.ts +++ b/packages/misskey-js/src/autogen/types.ts @@ -2,8 +2,8 @@ /* eslint @typescript-eslint/no-explicit-any: 0 */ /* - * version: 2023.12.0 - * generatedAt: 2023-12-26T23:35:09.389Z + * version: 2023.12.2 + * generatedAt: 2024-01-02T13:38:55.207Z */ /** @@ -40,7 +40,6 @@ export type paths = { * admin/accounts/create * @description No description provided. * - * **Internal Endpoint**: This endpoint is an API for the misskey mainframe and is not intended for use by third parties. * **Credential required**: *No* */ post: operations['admin/accounts/create']; @@ -4456,6 +4455,9 @@ export type operations = { enableActiveEmailValidation: boolean; enableVerifymailApi: boolean; verifymailAuthKey: string | null; + enableTruemailApi: boolean; + truemailInstance: string | null; + truemailAuthKey: string | null; enableChartsForRemoteUser: boolean; enableChartsForFederatedInstances: boolean; enableServerMachineStats: boolean; @@ -4620,7 +4622,6 @@ export type operations = { * admin/accounts/create * @description No description provided. * - * **Internal Endpoint**: This endpoint is an API for the misskey mainframe and is not intended for use by third parties. * **Credential required**: *No* */ 'admin/accounts/create': { @@ -8247,6 +8248,9 @@ export type operations = { enableActiveEmailValidation?: boolean; enableVerifymailApi?: boolean; verifymailAuthKey?: string | null; + enableTruemailApi?: boolean; + truemailInstance?: string | null; + truemailAuthKey?: string | null; enableChartsForRemoteUser?: boolean; enableChartsForFederatedInstances?: boolean; enableServerMachineStats?: boolean;