fix: Some fixes for #12850 (#12862)

- refinement the error message when trueMail validation fails
- the settings of trueMail are not displayed after saving
- changing how `Active Email Validation` is saved
This commit is contained in:
AsukaMari 2024-01-19 17:48:30 +08:00 committed by GitHub
parent 8be977b32b
commit b17eb8e537
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 63 additions and 32 deletions

View file

@ -20,6 +20,7 @@
### General ### General
- Feat: [mCaptcha](https://github.com/mCaptcha/mCaptcha)のサポートを追加 - Feat: [mCaptcha](https://github.com/mCaptcha/mCaptcha)のサポートを追加
- Fix: リストライムラインの「リノートを表示」が正しく機能しない問題を修正 - Fix: リストライムラインの「リノートを表示」が正しく機能しない問題を修正
- Feat: Add support for TrueMail
### Client ### Client
- Feat: 新しいゲームを追加 - Feat: 新しいゲームを追加

View file

@ -165,10 +165,17 @@ export class EmailService {
email: emailAddress, email: emailAddress,
}); });
if (exist !== 0) {
return {
available: false,
reason: 'used',
};
}
let validated: { let validated: {
valid: boolean, valid: boolean,
reason?: string | null, reason?: string | null,
}; } = { valid: true, reason: null };
if (meta.enableActiveEmailValidation) { if (meta.enableActiveEmailValidation) {
if (meta.enableVerifymailApi && meta.verifymailAuthKey != null) { if (meta.enableVerifymailApi && meta.verifymailAuthKey != null) {
@ -185,27 +192,37 @@ export class EmailService {
validateSMTP: false, // 日本だと25ポートが殆どのプロバイダーで塞がれていてタイムアウトになるので validateSMTP: false, // 日本だと25ポートが殆どのプロバイダーで塞がれていてタイムアウトになるので
}); });
} }
} else { }
validated = { valid: true, reason: null };
if (!validated.valid) {
const formatReason: Record<string, 'format' | 'disposable' | 'mx' | 'smtp' | 'network' | 'blacklist' | undefined> = {
regex: 'format',
disposable: 'disposable',
mx: 'mx',
smtp: 'smtp',
network: 'network',
blacklist: 'blacklist',
};
return {
available: false,
reason: validated.reason ? formatReason[validated.reason] ?? null : null,
};
} }
const emailDomain: string = emailAddress.split('@')[1]; const emailDomain: string = emailAddress.split('@')[1];
const isBanned = this.utilityService.isBlockedHost(meta.bannedEmailDomains, emailDomain); const isBanned = this.utilityService.isBlockedHost(meta.bannedEmailDomains, emailDomain);
const available = exist === 0 && validated.valid && !isBanned; if (isBanned) {
return {
available: false,
reason: 'banned',
};
}
return { return {
available, available: true,
reason: available ? null : reason: 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,
}; };
} }
@ -222,7 +239,8 @@ export class EmailService {
}, },
}); });
const json = (await res.json()) as { const json = (await res.json()) as Partial<{
message: string;
block: boolean; block: boolean;
catch_all: boolean; catch_all: boolean;
deliverable_email: boolean; deliverable_email: boolean;
@ -237,8 +255,15 @@ export class EmailService {
mx_priority: { [key: string]: number }; mx_priority: { [key: string]: number };
privacy: boolean; privacy: boolean;
related_domains: string[]; related_domains: string[];
}; }>;
/* api error: when there is only one `message` attribute in the returned result */
if (Object.keys(json).length === 1 && Reflect.has(json, 'message')) {
return {
valid: false,
reason: null,
};
}
if (json.email_address === undefined) { if (json.email_address === undefined) {
return { return {
valid: false, valid: false,
@ -281,13 +306,14 @@ export class EmailService {
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
Accept: 'application/json', Accept: 'application/json',
Authorization: truemailAuthKey Authorization: truemailAuthKey,
}, },
}); });
const json = (await res.json()) as { const json = (await res.json()) as {
email: string; email: string;
success: boolean; success: boolean;
error?: string;
errors?: { errors?: {
list_match?: string; list_match?: string;
regex?: string; regex?: string;
@ -296,10 +322,10 @@ export class EmailService {
} | null; } | null;
}; };
if (json.email === undefined || (json.email !== undefined && json.errors?.regex)) { if (json.email === undefined || json.errors?.regex) {
return { return {
valid: false, valid: false,
reason: 'format', reason: 'format',
}; };
} }
if (json.errors?.smtp) { if (json.errors?.smtp) {

View file

@ -71,27 +71,28 @@ SPDX-License-Identifier: AGPL-3.0-only
<div class="_gaps_m"> <div class="_gaps_m">
<span>{{ i18n.ts.activeEmailValidationDescription }}</span> <span>{{ i18n.ts.activeEmailValidationDescription }}</span>
<MkSwitch v-model="enableActiveEmailValidation" @update:modelValue="save"> <MkSwitch v-model="enableActiveEmailValidation">
<template #label>Enable</template> <template #label>Enable</template>
</MkSwitch> </MkSwitch>
<MkSwitch v-model="enableVerifymailApi" @update:modelValue="save"> <MkSwitch v-model="enableVerifymailApi">
<template #label>Use Verifymail.io API</template> <template #label>Use Verifymail.io API</template>
</MkSwitch> </MkSwitch>
<MkInput v-model="verifymailAuthKey" @update:modelValue="save"> <MkInput v-model="verifymailAuthKey">
<template #prefix><i class="ti ti-key"></i></template> <template #prefix><i class="ti ti-key"></i></template>
<template #label>Verifymail.io API Auth Key</template> <template #label>Verifymail.io API Auth Key</template>
</MkInput> </MkInput>
<MkSwitch v-model="enableTruemailApi" @update:modelValue="save"> <MkSwitch v-model="enableTruemailApi">
<template #label>Use TrueMail API</template> <template #label>Use TrueMail API</template>
</MkSwitch> </MkSwitch>
<MkInput v-model="truemailInstance" @update:modelValue="save"> <MkInput v-model="truemailInstance">
<template #prefix><i class="ti ti-key"></i></template> <template #prefix><i class="ti ti-key"></i></template>
<template #label>TrueMail API Instance</template> <template #label>TrueMail API Instance</template>
</MkInput> </MkInput>
<MkInput v-model="truemailAuthKey" @update:modelValue="save"> <MkInput v-model="truemailAuthKey">
<template #prefix><i class="ti ti-key"></i></template> <template #prefix><i class="ti ti-key"></i></template>
<template #label>TrueMail API Auth Key</template> <template #label>TrueMail API Auth Key</template>
</MkInput> </MkInput>
<MkButton primary @click="save"><i class="ti ti-device-floppy"></i> {{ i18n.ts.save }}</MkButton>
</div> </div>
</MkFolder> </MkFolder>
@ -192,7 +193,10 @@ async function init() {
enableActiveEmailValidation.value = meta.enableActiveEmailValidation; enableActiveEmailValidation.value = meta.enableActiveEmailValidation;
enableVerifymailApi.value = meta.enableVerifymailApi; enableVerifymailApi.value = meta.enableVerifymailApi;
verifymailAuthKey.value = meta.verifymailAuthKey; 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() { function save() {