![Postfix header_checks 不起作用:前面的正则表达式无效](https://linux22.com/image/745394/Postfix%20header_checks%20%E4%B8%8D%E8%B5%B7%E4%BD%9C%E7%94%A8%EF%BC%9A%E5%89%8D%E9%9D%A2%E7%9A%84%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F%E6%97%A0%E6%95%88.png)
我在使用 Postfix 时遇到了问题。最近我们收到的邮件带有格式错误的“发件人:”标头,如下所示:
From: "Name Surname <[email protected]>" <[email protected]>
From: "[email protected]" <[email protected]>
最终得到了基于 PCRE 标头检查的解决方案,使用以下两个正则表达式:
/^From:.+(".+<(.*@+.*)>").*<((?!\2).*)>$/ REJECT
/^From:.+("([^<>]*@+[^<>]*)").*<((?!\2).*)>$/ REJECT
完毕
postmap /etc/postfix/header_checks
并重新加载后缀。
看起来运行正常,并且 POstfix 显然可以毫无问题地处理 PCRE:
postmap -q 'From: "Name Surname <[email protected]>" <[email protected]>' pcre:/etc/postfix/header_checks
REJECT
postmap -q 'From: "[email protected]" <[email protected]>' pcre:/etc/postfix/header_checks
REJECT
但实际使用中邮件并没有被拦截。日志中有以下(重复的)错误:
Nov 22 10:52:19 mx1 postfix/cleanup[32087]: warning: regexp map /etc/postfix/header_checks, line 497: Invalid preceding regular expression
Nov 22 10:52:19 mx1 postfix/cleanup[32087]: warning: regexp map /etc/postfix/header_checks, line 498: Invalid preceding regular expression
/etc/postfix/header_checks文件内容如下(前496行是注释):
/^From:.+(".+<(.*@+.*)>").*<((?!\2).*)>$/ REJECT
/^From:.+("([^<>]*@+[^<>]*)").*<((?!\2).*)>$/ REJECT
/^Subject:/ WARN
附加信息:
- There are no receive_override_options: the file is used as the subject are correctly logged in logfile (last line). And the errors too shows the file is handled by postfix.
- Tested the two regexp with multiple online services and they seems correct: also the postmap -q tests shows they are working correctly.
- Postfix 2.10.1 and PCRE 8.32 on a CentOS 7.7
任何想法?