mirror of
https://github.com/dreamhunter2333/cloudflare_temp_email.git
synced 2026-06-06 08:00:57 +08:00
feat: |UI| add JUNK_MAIL_FORCE_PASS_LIST (#539)
This commit is contained in:
@@ -42,6 +42,7 @@ export default {
|
||||
"DISABLE_SHOW_GITHUB": !getBooleanValue(c.env.DISABLE_SHOW_GITHUB),
|
||||
"DISABLE_ADMIN_PASSWORD_CHECK": getBooleanValue(c.env.DISABLE_ADMIN_PASSWORD_CHECK),
|
||||
"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 { getBooleanValue } from "../utils";
|
||||
import { getBooleanValue, getStringArray } from "../utils";
|
||||
import { commonParseMail } from "../common";
|
||||
|
||||
export const check_if_junk_mail = async (
|
||||
@@ -11,34 +11,44 @@ export const check_if_junk_mail = async (
|
||||
}
|
||||
const parsedEmail = await commonParseMail(raw_mail);
|
||||
if (!parsedEmail?.headers) return false;
|
||||
|
||||
const forcePassList = getStringArray(env.JUNK_MAIL_FORCE_PASS_LIST);
|
||||
const passedList: string[] = [];
|
||||
|
||||
const headers = parsedEmail.headers;
|
||||
for (const header of headers) {
|
||||
if (!header["key"]) continue;
|
||||
if (!header["value"]) continue;
|
||||
|
||||
// check spf
|
||||
if (header["key"].toLowerCase() == "received-spf"
|
||||
&&
|
||||
!header["value"].toLowerCase().includes("pass")
|
||||
) {
|
||||
return true;
|
||||
if (header["key"].toLowerCase() == "received-spf") {
|
||||
if (!header["value"].toLowerCase().includes("pass")) {
|
||||
return true;
|
||||
}
|
||||
passedList.push("spf");
|
||||
}
|
||||
|
||||
// check dkim and dmarc
|
||||
if (header["key"].toLowerCase() == "authentication-results") {
|
||||
if (header["value"].toLowerCase().includes("dkim=")
|
||||
&&
|
||||
!header["value"].toLowerCase().includes("dkim=pass")
|
||||
) {
|
||||
return true;
|
||||
if (header["value"].toLowerCase().includes("dkim=")) {
|
||||
if (!header["value"].toLowerCase().includes("dkim=pass")) {
|
||||
return true;
|
||||
}
|
||||
passedList.push("dkim");
|
||||
}
|
||||
if (header["value"].toLowerCase().includes("dmarc=")
|
||||
&&
|
||||
!header["value"].toLowerCase().includes("dmarc=pass")
|
||||
) {
|
||||
return true;
|
||||
if (header["value"].toLowerCase().includes("dmarc=")) {
|
||||
if (!header["value"].toLowerCase().includes("dmarc=pass")) {
|
||||
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
worker/src/types.d.ts
vendored
1
worker/src/types.d.ts
vendored
@@ -43,6 +43,7 @@ export type Bindings = {
|
||||
FORWARD_ADDRESS_LIST: string | string[] | undefined
|
||||
|
||||
ENABLE_CHECK_JUNK_MAIL: string | boolean | undefined
|
||||
JUNK_MAIL_FORCE_PASS_LIST: string | string[] | undefined
|
||||
|
||||
// s3 config
|
||||
S3_ENDPOINT: string | undefined
|
||||
|
||||
@@ -74,6 +74,8 @@ ENABLE_AUTO_REPLY = false
|
||||
# FRONTEND_URL = "https://xxxx.xxx"
|
||||
# Enable check junk mail
|
||||
# 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]]
|
||||
binding = "DB"
|
||||
|
||||
Reference in New Issue
Block a user