[fix] white list

This commit is contained in:
zhhe committed 2026-11-17 07:33:51 +08:00
1 parent e9cce46046
commit 1fcf56e3dd
8 files changed
+60 -57

No files matched your search

+6 -26
View File
@@ -14,24 +14,6 @@ export function createPolicy(addresses) {
export function isAllowed(policy, address) {
return policy.has(normalizeAddress(address));
}
function headerText(mail, name) {
const value = mail.headers.get(name);
if (typeof value === 'string')
return value;
if (Array.isArray(value))
return value.filter(item => typeof item === 'string').join(', ');
return '';
}
/** 拦截自动回复 / 批量邮件,避免邮件环。 */
export function isAutoReply(mail) {
const autoSubmitted = headerText(mail, 'auto-submitted').toLowerCase();
if (autoSubmitted && autoSubmitted !== 'no')
return true;
const precedence = headerText(mail, 'precedence').toLowerCase();
if (/(^|[\s,;])(bulk|junk|list)([\s,;]|$)/.test(precedence))
return true;
return false;
}
function decodeEntities(text) {
return text
.replace(/ /gi, ' ')
@@ -73,8 +55,8 @@ function referencesOf(mail) {
return all.length ? all.join(' ') : undefined;
}
/**
* 一次解析完成准入判断与字段提取:发件地址只解析一次,
* 不在白名单或命中自动流量时返回 null(静默丢弃)。
* 一次解析完成准入判断与字段提取:发件地址只解析一次。
* 唯一的准入条件是白名单;取不到发件地址时无法建立会话与回信,返回 null。
*/
export function toJob(policy, mail) {
const sender = mail.from?.value?.[0]?.address;
@@ -83,14 +65,12 @@ export function toJob(policy, mail) {
const from = normalizeAddress(sender);
if (!isAllowed(policy, from))
return null;
if (isAutoReply(mail))
return null;
const text = bodyText(mail);
if (!text)
return null;
const subject = mail.subject?.trim() || '(无主题)';
// 正文为空(纯图片 / 无文本部分)也照常投递,不再静默丢弃。
const text = bodyText(mail) || `主题:${subject}`;
return {
from,
subject: mail.subject?.trim() || '(无主题)',
subject,
text,
messageId: mail.messageId,
references: referencesOf(mail),