feat: add email blacklist filtering
This commit is contained in:
@@ -24,7 +24,10 @@ export async function email(message, env, ctx) {
|
||||
ruleEmail,
|
||||
ruleType,
|
||||
r2Domain,
|
||||
noRecipient
|
||||
noRecipient,
|
||||
blackSubject,
|
||||
blackContent,
|
||||
blackFrom
|
||||
} = await settingService.query({ env });
|
||||
|
||||
if (receive === settingConst.receive.CLOSE) {
|
||||
@@ -32,7 +35,6 @@ export async function email(message, env, ctx) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
const reader = message.raw.getReader();
|
||||
let content = '';
|
||||
|
||||
@@ -44,6 +46,14 @@ export async function email(message, env, ctx) {
|
||||
|
||||
const email = await PostalMime.parse(content);
|
||||
|
||||
|
||||
const blockFlag = checkBlock(blackSubject, blackContent, blackFrom, email);
|
||||
|
||||
if (blockFlag) {
|
||||
message.setReject('Message rejected');
|
||||
return;
|
||||
}
|
||||
|
||||
const account = await accountService.selectByEmailIncludeDel({ env: env }, message.to);
|
||||
|
||||
if (!account && noRecipient === settingConst.noRecipient.CLOSE) {
|
||||
@@ -169,3 +179,31 @@ export async function email(message, env, ctx) {
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
function checkBlock(blackSubjectStr, blackContentStr, blackFromStr, email) {
|
||||
|
||||
const blackFromList = blackFromStr ? blackFromStr.split(',') : []
|
||||
const blackContentList = blackContentStr ? blackContentStr.split(',') : []
|
||||
const blackSubjectList = blackSubjectStr ? blackSubjectStr.split(',') : []
|
||||
|
||||
for (const blackSubject of blackSubjectList) {
|
||||
if (email.subject?.includes(blackSubject)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
for (const blackContent of blackContentList) {
|
||||
if (email.html?.includes(blackContent) || email.text?.includes(blackContent)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
for (const blackFrom of blackFromList) {
|
||||
if (email.from.address.includes(blackFrom)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user