mirror of
https://github.com/dreamhunter2333/cloudflare_temp_email.git
synced 2026-09-05 07:27:27 +08:00
feat: |UI| add JUNK_MAIL_FORCE_PASS_LIST (#539)
This commit is contained in:
@@ -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
|
||||||
|
|
||||||
|
|||||||
@@ -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"
|
||||||
|
|||||||
@@ -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]]
|
||||||
|
|||||||
@@ -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),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
passedList.push("dkim");
|
||||||
}
|
}
|
||||||
if (header["value"].toLowerCase().includes("dmarc=")
|
if (header["value"].toLowerCase().includes("dmarc=")) {
|
||||||
&&
|
if (!header["value"].toLowerCase().includes("dmarc=pass")) {
|
||||||
!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())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+1
@@ -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
|
||||||
|
|||||||
@@ -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"
|
||||||
|
|||||||
Reference in New Issue
Block a user