feat: |UI| add JUNK_MAIL_FORCE_PASS_LIST (#539)

This commit is contained in:
Dream Hunter
2024-12-30 18:38:33 +08:00
committed by GitHub
parent 8a03d3e57f
commit c964d77a59
7 changed files with 37 additions and 18 deletions
+1
View File
@@ -5,6 +5,7 @@
- feat: |Github Action| 增加自动更新并部署功能 - feat: |Github Action| 增加自动更新并部署功能
- feat: |UI| admin 用户设置,支持 oauth2 配置的删除 - feat: |UI| admin 用户设置,支持 oauth2 配置的删除
- feat: 增加垃圾邮件检测必须通过的列表 `JUNK_MAIL_FORCE_PASS_LIST` 配置
## v0.8.2 ## v0.8.2
+2
View File
@@ -132,6 +132,8 @@ ENABLE_AUTO_REPLY = false
# FRONTEND_URL = "https://xxxx.xxx" # FRONTEND_URL = "https://xxxx.xxx"
# Enable check junk mail # Enable check junk mail
# ENABLE_CHECK_JUNK_MAIL = false # ENABLE_CHECK_JUNK_MAIL = false
# junk mail force check pass list, if no status or status is not pass, will be marked as junk mail
# JUNK_MAIL_FORCE_PASS_LIST = ["spf", "dkim", "dmarc"]
[[d1_databases]] [[d1_databases]]
binding = "DB" binding = "DB"
+3 -1
View File
@@ -102,8 +102,10 @@ ENABLE_AUTO_REPLY = false
# FORWARD_ADDRESS_LIST = ["xxx@xxx.com"] # FORWARD_ADDRESS_LIST = ["xxx@xxx.com"]
# 前端地址,用于发送 webhook 的邮件 url # 前端地址,用于发送 webhook 的邮件 url
# FRONTEND_URL = "https://xxxx.xxx" # FRONTEND_URL = "https://xxxx.xxx"
# 是否启用垃圾邮件检查 # 是否启用垃圾邮件检查,默认任何一项存在配置且不通过则被判定为垃圾邮件
# ENABLE_CHECK_JUNK_MAIL = false # ENABLE_CHECK_JUNK_MAIL = false
# 垃圾邮件检查配置, 任何一项不存在或者不通过则被判定为垃圾邮件
# JUNK_MAIL_FORCE_PASS_LIST = ["spf", "dkim", "dmarc"]
# D1 数据库的名称和 ID 可以在 cloudflare 控制台查看 # D1 数据库的名称和 ID 可以在 cloudflare 控制台查看
[[d1_databases]] [[d1_databases]]
+1
View File
@@ -42,6 +42,7 @@ export default {
"DISABLE_SHOW_GITHUB": !getBooleanValue(c.env.DISABLE_SHOW_GITHUB), "DISABLE_SHOW_GITHUB": !getBooleanValue(c.env.DISABLE_SHOW_GITHUB),
"DISABLE_ADMIN_PASSWORD_CHECK": getBooleanValue(c.env.DISABLE_ADMIN_PASSWORD_CHECK), "DISABLE_ADMIN_PASSWORD_CHECK": getBooleanValue(c.env.DISABLE_ADMIN_PASSWORD_CHECK),
"ENABLE_CHECK_JUNK_MAIL": getBooleanValue(c.env.ENABLE_CHECK_JUNK_MAIL), "ENABLE_CHECK_JUNK_MAIL": getBooleanValue(c.env.ENABLE_CHECK_JUNK_MAIL),
"JUNK_MAIL_FORCE_PASS_LIST": getStringArray(c.env.JUNK_MAIL_FORCE_PASS_LIST),
}) })
} }
} }
+24 -14
View File
@@ -1,5 +1,5 @@
import { Bindings } from "../types"; import { Bindings } from "../types";
import { getBooleanValue } from "../utils"; import { getBooleanValue, getStringArray } from "../utils";
import { commonParseMail } from "../common"; import { commonParseMail } from "../common";
export const check_if_junk_mail = async ( export const check_if_junk_mail = async (
@@ -11,34 +11,44 @@ export const check_if_junk_mail = async (
} }
const parsedEmail = await commonParseMail(raw_mail); const parsedEmail = await commonParseMail(raw_mail);
if (!parsedEmail?.headers) return false; if (!parsedEmail?.headers) return false;
const forcePassList = getStringArray(env.JUNK_MAIL_FORCE_PASS_LIST);
const passedList: string[] = [];
const headers = parsedEmail.headers; const headers = parsedEmail.headers;
for (const header of headers) { for (const header of headers) {
if (!header["key"]) continue; if (!header["key"]) continue;
if (!header["value"]) continue; if (!header["value"]) continue;
// check spf // check spf
if (header["key"].toLowerCase() == "received-spf" if (header["key"].toLowerCase() == "received-spf") {
&& if (!header["value"].toLowerCase().includes("pass")) {
!header["value"].toLowerCase().includes("pass")
) {
return true; return true;
} }
passedList.push("spf");
}
// check dkim and dmarc // check dkim and dmarc
if (header["key"].toLowerCase() == "authentication-results") { if (header["key"].toLowerCase() == "authentication-results") {
if (header["value"].toLowerCase().includes("dkim=") if (header["value"].toLowerCase().includes("dkim=")) {
&& if (!header["value"].toLowerCase().includes("dkim=pass")) {
!header["value"].toLowerCase().includes("dkim=pass")
) {
return true; return true;
} }
if (header["value"].toLowerCase().includes("dmarc=") passedList.push("dkim");
&& }
!header["value"].toLowerCase().includes("dmarc=pass") if (header["value"].toLowerCase().includes("dmarc=")) {
) { if (!header["value"].toLowerCase().includes("dmarc=pass")) {
return true; return true;
} }
passedList.push("dmarc");
} }
} }
return false; }
if (forcePassList?.length == 0) return false;
// check force pass list
return forcePassList.some(
(checkName) => !passedList.includes(checkName.toLowerCase())
);
} }
+1
View File
@@ -43,6 +43,7 @@ export type Bindings = {
FORWARD_ADDRESS_LIST: string | string[] | undefined FORWARD_ADDRESS_LIST: string | string[] | undefined
ENABLE_CHECK_JUNK_MAIL: string | boolean | undefined ENABLE_CHECK_JUNK_MAIL: string | boolean | undefined
JUNK_MAIL_FORCE_PASS_LIST: string | string[] | undefined
// s3 config // s3 config
S3_ENDPOINT: string | undefined S3_ENDPOINT: string | undefined
+2
View File
@@ -74,6 +74,8 @@ ENABLE_AUTO_REPLY = false
# FRONTEND_URL = "https://xxxx.xxx" # FRONTEND_URL = "https://xxxx.xxx"
# Enable check junk mail # Enable check junk mail
# ENABLE_CHECK_JUNK_MAIL = false # ENABLE_CHECK_JUNK_MAIL = false
# junk mail force check pass list, if no status or status is not pass, will be marked as junk mail
# JUNK_MAIL_FORCE_PASS_LIST = ["spf", "dkim", "dmarc"]
[[d1_databases]] [[d1_databases]]
binding = "DB" binding = "DB"