feat: add EMAIL_KV_BLACK_LIST (#394)

This commit is contained in:
Dream Hunter
2024-08-11 20:34:10 +08:00
committed by GitHub
parent c733d3bf4d
commit ac31042e69
8 changed files with 48 additions and 8 deletions

View File

@@ -0,0 +1,16 @@
import { CONSTANTS } from "../constants";
import { Bindings } from "../types";
export const isBlocked = async (from: string, env: Bindings): Promise<boolean> => {
if (env.BLACK_LIST && env.BLACK_LIST.split(",").some(word => from.includes(word))) {
return true;
}
if (!env.KV) {
return false;
}
const blockList = await env.KV.get<string[]>(CONSTANTS.EMAIL_KV_BLACK_LIST, 'json') || [];
if (blockList.some(word => from.includes(word))) {
return true;
}
return false;
}

View File

@@ -5,11 +5,12 @@ import { sendMailToTelegram } from "../telegram_api";
import { Bindings, HonoCustomType } from "../types";
import { auto_reply } from "./auto_reply";
import { trigerWebhook } from "../mails_api/webhook_settings";
import { isBlocked } from "./black_list";
async function email(message: ForwardableEmailMessage, env: Bindings, ctx: ExecutionContext) {
if (env.BLACK_LIST && env.BLACK_LIST.split(",").some(word => message.from.includes(word))) {
message.setReject("Missing from address");
if (await isBlocked(message.from, env)) {
message.setReject("Reject from address");
console.log(`Reject message from ${message.from} to ${message.to}`);
return;
}