Merge remote-tracking branch 'misskey-dev/develop' into io

This commit is contained in:
まっちゃとーにゅ 2024-01-23 04:10:51 +09:00
commit 8aa76868b3
No known key found for this signature in database
GPG key ID: 143DE582A97FE052
266 changed files with 20375 additions and 6619 deletions

View file

@ -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) {
validated = await validateEmail({
@ -187,27 +194,37 @@ export class EmailService {
if (validated.valid && meta.enableTruemailApi && meta.truemailInstance && meta.truemailAuthKey != null) {
validated = await this.trueMail(meta.truemailInstance, emailAddress, meta.truemailAuthKey);
}
} 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 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,
};
}
@ -224,7 +241,8 @@ export class EmailService {
},
});
const json = (await res.json()) as {
const json = (await res.json()) as Partial<{
message: string;
block: boolean;
catch_all: boolean;
deliverable_email: boolean;
@ -239,8 +257,15 @@ export class EmailService {
mx_priority: { [key: string]: number };
privacy: boolean;
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) {
return {
valid: false,
@ -283,13 +308,14 @@ export class EmailService {
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
Authorization: truemailAuthKey
Authorization: truemailAuthKey,
},
});
const json = (await res.json()) as {
email: string;
success: boolean;
error?: string;
errors?: {
list_match?: string;
regex?: string;
@ -298,10 +324,10 @@ export class EmailService {
} | null;
};
if (json.email === undefined || (json.email !== undefined && json.errors?.regex)) {
if (json.email === undefined || json.errors?.regex) {
return {
valid: false,
reason: 'format',
valid: false,
reason: 'format',
};
}
if (json.errors?.smtp) {