四、过虑
header_checks参数可以扫描邮件头,header_checks查找表规则表达式为: parttern action 注:parttern是对字段头进行匹配的规则表达式,action是当parttern符合时候采取的动作,包括REJECT(将该信件退回给发信者)、WARN(将信件收下来,但是将该信件的基本资料记录在登录档内)、DISCARD(将该信件丢弃,并不给予原发信者回应)。
1.在/etc/postfix/main.cf中启用header_checks文件头(将注释符#去掉)
|
1
|
546 header_checks = regexp:/etc/postfix/header_checks |
2.同时,在/etc/postfix/header_checks文件开始处添加以下一行内容:
|
1
|
/sex/ REJECT Sexy information is disabled. |
注:正则表达式 动作 返回信息(可不写)。表示邮件标题里带“sexy”这个词的邮件都被拒绝发送,系统管理员向发件人返回的信息提示是“Sexy information is disabled.”
3.测试
Root向sqing发送一封邮件标题为sexy girl的邮件,
[root@zero ~]# mail sqing
Subject: sexy girl
ssssssssssssssssssssssssss
.
EOT
Root收到退信邮件,
[root@zero ~]# mail
Heirloom Mail version 12.4 7/29/08. Type ? for help.
"/var/spool/mail/root": 1 message 1 new
>N 1 Mail Delivery System Wed May 22 05:36 70/2166 "Undelivered Mail Retu"
& 1
Message 1:
From MAILER-DAEMON Wed May 22 05:36:50 2013
Return-Path: <>
X-Original-To: root@sq.com
Delivered-To: root@sq.com
Date: Wed, 22 May 2013 05:36:50 +0800 (CST)
From: MAILER-DAEMON@sq.com (Mail Delivery System)
Subject: Undelivered Mail Returned to Sender
To: root@sq.com
Auto-Submitted: auto-replied
Content-Type: multipart/report; report-type=delivery-status;
boundary="4947A60D7B.1369172210/zero.sq.com"
Status: R
Part 1:
Content-Description: Notification
Content-Type: text/plain; charset=us-ascii
This is the mail system at host zero.sq.com.
I'm sorry to have to inform you that your message could not
be delivered to one or more recipients. It's attached below.
For further assistance, please send mail to postmaster.
If you do so, please include this problem report. You can
delete your own text from the attached returned message.
The mail system
<sqing@sq.com> (expanded from <sqing>): Sexy information is disabled.
Part 2:
Content-Description: Delivery report
Content-Type: message/delivery-status
Part 3:
Content-Description: Undelivered Message Headers
Content-Type: text/rfc822-headers
Return-Path: <root@sq.com>
Received: by zero.sq.com (Postfix, from userid 0)
id 4947A60D7B; Wed, 22 May 2013 05:36:50 +0800 (CST)
Date: Wed, 22 May 2013 05:36:50 +0800
To: sqing@sq.com
Subject: sexy girl
User-Agent: Heirloom mailx 12.4 7/29/08
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Message-Id: <20130521213650.4947A60D7B@zero.sq.com>
From: root@sq.com (root)
&
从邮箱系统管理员返回的结果显示,该邮件由于存在敏感字“sexy”而被拒绝了。
邮件标题为“asexya”的邮件同样也被拦截。
如果是要针对邮件内容过滤,在主配文件中,增加一个body_checks文件头(这里加在header_checks文件头下面)
|
1
2
|
546 header_checks = regexp:/etc/postfix/header_checks547 body_checks = regexp:/etc/postfix/body_checks |
同时,在etc/postfix中以header_checks为模块,创建一个body_checks文件。
[root@zero ~]# cp -p /etc/postfix/header_checks /etc/postfix/body_checks
编辑body_checks内容时,其过虑关键字的格式与header_checks一样。
