summaryrefslogtreecommitdiff
path: root/packages/backend/src/core
diff options
context:
space:
mode:
authorMomentQYC <62551256+MomentQYC@users.noreply.github.com>2023-12-29 17:23:29 +0800
committerGitHub <noreply@github.com>2023-12-29 18:23:29 +0900
commit7948018e6a4735fc32d61e8690319802e38baf3a (patch)
treefef4bb1664b9e5a5d0b86bd329d3aa29411f1764 /packages/backend/src/core
parentenhance(frontend): ハッシュタグ入力時に、本文の末尾の行に... (diff)
downloadsharkey-7948018e6a4735fc32d61e8690319802e38baf3a.tar.gz
sharkey-7948018e6a4735fc32d61e8690319802e38baf3a.tar.bz2
sharkey-7948018e6a4735fc32d61e8690319802e38baf3a.zip
feat: Add support for TrueMail (#12850)
Co-authored-by: MarryDream <2190758465@qq.com>
Diffstat (limited to 'packages/backend/src/core')
-rw-r--r--packages/backend/src/core/EmailService.ts69
1 files changed, 68 insertions, 1 deletions
diff --git a/packages/backend/src/core/EmailService.ts b/packages/backend/src/core/EmailService.ts
index 7fc7800783..7e812b4df2 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';
+ reason: null | 'used' | 'format' | 'disposable' | 'mx' | 'smtp' | 'banned' | 'network' | 'blacklist';
}> {
const meta = await this.metaService.fetch();
@@ -173,6 +173,8 @@ export class EmailService {
if (meta.enableActiveEmailValidation) {
if (meta.enableVerifymailApi && meta.verifymailAuthKey != null) {
validated = await this.verifyMail(emailAddress, meta.verifymailAuthKey);
+ } else if (meta.enableTruemailApi && meta.truemailInstance && meta.truemailAuthKey != null) {
+ validated = await this.trueMail(meta.truemailInstance, emailAddress, meta.truemailAuthKey);
} else {
validated = await validateEmail({
email: emailAddress,
@@ -201,6 +203,8 @@ export class EmailService {
validated.reason === 'disposable' ? 'disposable' :
validated.reason === 'mx' ? 'mx' :
validated.reason === 'smtp' ? 'smtp' :
+ validated.reason === 'network' ? 'network' :
+ validated.reason === 'blacklist' ? 'blacklist' :
null,
};
}
@@ -265,4 +269,67 @@ export class EmailService {
reason: null,
};
}
+
+ private async trueMail<T>(truemailInstance: string, emailAddress: string, truemailAuthKey: string): Promise<{
+ valid: boolean;
+ reason: 'used' | 'format' | 'blacklist' | 'mx' | 'smtp' | 'network' | T | null;
+ }> {
+ const endpoint = truemailInstance + '?email=' + emailAddress;
+ try {
+ const res = await this.httpRequestService.send(endpoint, {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ Accept: 'application/json',
+ Authorization: truemailAuthKey
+ },
+ });
+
+ const json = (await res.json()) as {
+ email: string;
+ success: boolean;
+ errors?: {
+ list_match?: string;
+ regex?: string;
+ mx?: string;
+ smtp?: string;
+ } | null;
+ };
+
+ if (json.email === undefined || (json.email !== undefined && json.errors?.regex)) {
+ return {
+ valid: false,
+ reason: 'format',
+ };
+ }
+ if (json.errors?.smtp) {
+ return {
+ valid: false,
+ reason: 'smtp',
+ };
+ }
+ if (json.errors?.mx) {
+ return {
+ valid: false,
+ reason: 'mx',
+ };
+ }
+ if (!json.success) {
+ return {
+ valid: false,
+ reason: json.errors?.list_match as T || 'blacklist',
+ };
+ }
+
+ return {
+ valid: true,
+ reason: null,
+ };
+ } catch (error) {
+ return {
+ valid: false,
+ reason: 'network',
+ };
+ }
+ }
}