From 760d041f08ab9ad27f8c6fe1f4d883b270ed98af 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 --- packages/backend/src/core/EmailService.ts | 76 +++++++++++++------ .../frontend/src/pages/admin/security.vue | 18 +++-- packages/misskey-js/src/autogen/types.ts | 3 + 3 files changed, 65 insertions(+), 32 deletions(-) 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/types.ts b/packages/misskey-js/src/autogen/types.ts index 94bb2639809f..f3d82d2d457c 100644 --- a/packages/misskey-js/src/autogen/types.ts +++ b/packages/misskey-js/src/autogen/types.ts @@ -4456,6 +4456,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;