feat: add email forwrading white list config

This commit is contained in:
oiov
2025-08-05 10:25:19 +08:00
parent 5335834809
commit f96c3d4f7e
7 changed files with 140 additions and 11 deletions

View File

@@ -36,6 +36,7 @@ export default function AppConfigs({}: {}) {
const [notification, setNotification] = useState("");
const [catchAllEmails, setCatchAllEmails] = useState("");
const [forwardEmailTargets, setForwardEmailTargets] = useState("");
const [forwardEmailWhiteList, setForwardEmailWhiteList] = useState("");
const [emailSuffix, setEmailSuffix] = useState("");
const [tgBotToken, setTgBotToken] = useState("");
const [tgChatId, setTgChatId] = useState("");
@@ -54,6 +55,7 @@ export default function AppConfigs({}: {}) {
setTgTemplate(configs?.tg_email_template);
setTgWhiteList(configs?.tg_email_target_white_list);
setForwardEmailTargets(configs?.email_forward_targets);
setForwardEmailWhiteList(configs?.email_forward_white_list);
}
if (!isLoading) {
@@ -404,6 +406,48 @@ export default function AppConfigs({}: {}) {
)}
</CollapsibleTrigger>
<CollapsibleContent className="mt-4 space-y-4 rounded-md border p-4 shadow-md">
<div className="flex flex-col items-start justify-start gap-3">
<div className="space-y-1 leading-none">
<p className="font-medium">
{t("Email Forward White List")}
</p>
<p className="text-xs text-muted-foreground">
{t(
"Set email forward white list, split by comma, such as: a-wrdo,b-wrdo",
)}
</p>
</div>
{configs && (
<div className="flex w-full items-start gap-2">
<Textarea
className="h-16 max-h-32 min-h-9 resize-y bg-white dark:bg-neutral-700"
placeholder="example1@wr.do,example2@wr.do"
rows={5}
value={forwardEmailWhiteList}
onChange={(e) =>
setForwardEmailWhiteList(e.target.value)
}
/>
<Button
className="h-9 text-nowrap"
disabled={
isPending ||
forwardEmailWhiteList ===
configs.email_forward_white_list
}
onClick={() =>
handleChange(
forwardEmailWhiteList,
"email_forward_white_list",
"STRING",
)
}
>
{t("Save")}
</Button>
</div>
)}
</div>
<div className="flex flex-col items-start justify-start gap-3">
<div className="space-y-1 leading-none">
<p className="font-medium">
@@ -421,7 +465,6 @@ export default function AppConfigs({}: {}) {
className="h-16 max-h-32 min-h-9 resize-y bg-white dark:bg-neutral-700"
placeholder="example1@wr.do,example2@wr.do"
rows={5}
// defaultValue={configs.catch_all_emails}
value={catchAllEmails}
disabled={!configs.enable_email_catch_all}
onChange={(e) => setCatchAllEmails(e.target.value)}
@@ -483,6 +526,48 @@ export default function AppConfigs({}: {}) {
)}
</CollapsibleTrigger>
<CollapsibleContent className="mt-4 space-y-4 rounded-md border p-4 shadow-md">
<div className="flex flex-col items-start justify-start gap-3">
<div className="space-y-1 leading-none">
<p className="font-medium">
{t("Email Forward White List")}
</p>
<p className="text-xs text-muted-foreground">
{t(
"Set email forward white list, split by comma, such as: a-wrdo,b-wrdo",
)}
</p>
</div>
{configs && (
<div className="flex w-full items-start gap-2">
<Textarea
className="h-16 max-h-32 min-h-9 resize-y bg-white dark:bg-neutral-700"
placeholder="example1@wr.do,example2@wr.do"
rows={5}
value={forwardEmailWhiteList}
onChange={(e) =>
setForwardEmailWhiteList(e.target.value)
}
/>
<Button
className="h-9 text-nowrap"
disabled={
isPending ||
forwardEmailWhiteList ===
configs.email_forward_white_list
}
onClick={() =>
handleChange(
forwardEmailWhiteList,
"email_forward_white_list",
"STRING",
)
}
>
{t("Save")}
</Button>
</div>
)}
</div>
<div className="flex flex-col items-start justify-start gap-3">
<div className="space-y-1 leading-none">
<p className="font-medium">{t("Forward Email Targets")}</p>

View File

@@ -36,6 +36,7 @@ export async function GET(req: NextRequest) {
"enable_subdomain_status_email_pusher",
"enable_email_forward",
"email_forward_targets",
"email_forward_white_list",
]);
return Response.json(configs, { status: 200 });

View File

@@ -20,6 +20,7 @@ export async function POST(req: Request) {
"tg_email_target_white_list",
"enable_email_forward",
"email_forward_targets",
"email_forward_white_list",
]);
// 处理邮件转发和保存
@@ -44,7 +45,7 @@ export async function POST(req: Request) {
}
async function handleEmailForwarding(data: OriginalEmail, configs: any) {
const actions = determineEmailActions(configs);
const actions = determineEmailActions(data, configs);
const promises: Promise<void>[] = [];
@@ -72,18 +73,27 @@ async function handleEmailForwarding(data: OriginalEmail, configs: any) {
}
}
function determineEmailActions(configs: any): string[] {
function determineEmailActions(data: OriginalEmail, configs: any): string[] {
const actions: string[] = [];
// 检查是否配置了任何转发功能
const hasAnyForward =
configs.enable_email_catch_all || configs.enable_email_forward;
// 检查转发白名单
const isInForwardWhiteList = checkForwardWhiteList(
data.to,
configs.email_forward_white_list,
);
if (configs.enable_email_catch_all) {
// 检查是否配置了任何转发功能并且在白名单中
const hasCatchAllForward =
configs.enable_email_catch_all && isInForwardWhiteList;
const hasExternalForward =
configs.enable_email_forward && isInForwardWhiteList;
const hasAnyForward = hasCatchAllForward || hasExternalForward;
if (hasCatchAllForward) {
actions.push("CATCH_ALL");
}
if (configs.enable_email_forward) {
if (hasExternalForward) {
actions.push("EXTERNAL_FORWARD");
}
@@ -95,6 +105,20 @@ function determineEmailActions(configs: any): string[] {
return actions;
}
// 新增:检查邮箱是否在转发白名单中
function checkForwardWhiteList(
toEmail: string,
whiteListString: string,
): boolean {
// 如果没有配置白名单,则允许所有邮箱(保持向后兼容)
if (!whiteListString || whiteListString.trim() === "") {
return true;
}
const whiteList = parseAndValidateEmails(whiteListString);
return whiteList.includes(toEmail);
}
async function handleCatchAllEmail(data: OriginalEmail, configs: any) {
const validEmails = parseAndValidateEmails(configs.catch_all_emails);

View File

@@ -653,6 +653,8 @@
"Email Forwarding": "Email Forwarding",
"If enabled, forward all received emails to other platform email addresses (Send with Resend)": "If enabled, forward all received emails to other platform email addresses (Send with Resend)",
"Forward Email Targets": "Forward Email Targets",
"Set forward email address targets, split by comma if more than one, such as: 1@a-com,2@b-com, Only works when email forwarding is enabled": "Set forward email address targets, split by comma if more than one, such as: 1@a.com,2@b.com, Only works when email forwarding is enabled"
"Set forward email address targets, split by comma if more than one, such as: 1@a-com,2@b-com, Only works when email forwarding is enabled": "Set forward email address targets, split by comma if more than one, such as: 1@a.com,2@b.com, Only works when email forwarding is enabled",
"Email Forward White List": "Email Forward White List",
"Set email forward white list, split by comma, such as: a-wrdo,b-wrdo": "Set email forward white list (Catch-All and Email Forwarding are both enabled), split by comma, such as: a@wr.do,b@wr.do; If not set, will forward all emails"
}
}

View File

@@ -653,6 +653,8 @@
"Email Forwarding": "邮件转发",
"If enabled, forward all received emails to other platform email addresses (Send with Resend)": "如果启用,则将所有收到的电子邮件转发到其他平台邮箱 (使用 Resend 发送)",
"Forward Email Targets": "目标收件箱",
"Set forward email address targets, split by comma if more than one, such as: 1@a-com,2@b-com, Only works when email forwarding is enabled": "设置转发目标邮箱多个邮件地址请用逗号分隔例如1@a.com,2@b.com仅在启用邮件转发时生效"
"Set forward email address targets, split by comma if more than one, such as: 1@a-com,2@b-com, Only works when email forwarding is enabled": "设置转发目标邮箱多个邮件地址请用逗号分隔例如1@a.com,2@b.com仅在启用邮件转发时生效",
"Email Forward White List": "转发邮箱白名单",
"Set email forward white list, split by comma, such as: a-wrdo,b-wrdo": "设置转发邮箱白名单(Catch-All 和 Email Forwarding 同时生效)多个邮箱地址请用逗号分隔例如a@wr.do,b@wr.do; 若不设置,则转发所有邮件"
}
}

View File

@@ -0,0 +1,15 @@
INSERT INTO "system_configs"
(
"key",
"value",
"type",
"description"
)
VALUES
(
'email_forward_white_list',
'',
'STRING',
'邮件转发白名单,以逗号分隔'
);

File diff suppressed because one or more lines are too long