mirror of
https://github.com/dreamhunter2333/cloudflare_temp_email.git
synced 2026-06-03 06:30:38 +08:00
feat: add EMAIL_KV_BLACK_LIST (#394)
This commit is contained in:
16
worker/src/email/black_list.ts
Normal file
16
worker/src/email/black_list.ts
Normal 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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user