- 论坛徽章:
- 1
|
目标:
为防止假冒发件人,比如abc冒充老总发邮件,要求实现
1、发邮件必须认证
2、认证信息与邮件头中的发件人信息必须一致,否则警告并通知系统管理员。
1. sasl 即可,有很多參考資料,可自己找
2. 思路:
* Envelope From (Mail From: <>)
在 filter, filter_begin, filter_end 抓取 $Sender 變量即可得知
* Header From (From: <xxx@yy.com>
filter 參數解釋
For each leaf part of the mail message, filter is called with four arguments: entity, a MIME::Entity object; fname, the suggested filename taken from the MIME Content-Disposition header; ext, the file extension, and type, the MIME Content-Type value. For each non-leaf part of the mail message, filter_multipart is called with the same four arguments as filter. A non-leaf part of a message is a part that contains nested parts. Such a part has no useful body, but you should still perform filename checks to check for viruses that use malformed MIME to masquerade as non-leaf parts (like message/rfc822). In general, any action you perform in filter_multipart applies to the part itself and any contained parts.
- #/etc/mail/mimedefang
- sub filter {
- my($entity, $fname, $ext, $type) = @_;
- my $head = $entity->head;
- my $from = $head->get('From); # 取得郵件表頭中的 From
复制代码
* SMTP AUTH mech (SMTP 認證部份)
這個部份在 mimedefang 較費事些,首先你的 mimedefang 啟動參數要有
-a auth_authen,auth_type 之類的參數
- if (defined($SendmailMacros{'auth_authen'})) { # 如果有認證通過
- # ...
复制代码
=======
所以,全部大意即為:
- sub filter {
- my($entity, $fname, $ext, $type) = @_;
- read_commands_file(); # 重要,如果要讀取 SendmailMacro 時需要
- my $head = $entity->head;
- my $from = $head->get('From); # 取得郵件表頭中的 From
- $from=~s/[<> ]//g; # 去除 <> 和多餘的空白 (SPace)
- $Sender=~s/[<> ]//g;
- if ($Sender ne $from) {
- md_syslog("info","$MsgID: Envelope From: $Sender != Header From: $from");
- #return action_bouce(); # 退信
- #return action_quarantine(); # 隔離
- #add_recipient('me@mydomain.com'); # 問題郵件備到別的帳號一份
- }
- if ($Sender !~ /^$SendmailMacros{'auth_authen'}\@/i) { # 比對 Sender 的 username 部份是否和認證同
- md_syslog('info',"MsgID: Envelope From: $Sender != Auth Authen SendmailMacros{'auth_authen'}");
- } # md_syslog 是系統記錄的寫法,你要存資料庫的話自己寫個如 log_mysql ...之類的 function 來處理
复制代码
大概是這樣的思路,其他的細節你自己處理,所有的 code 都是直接寫上來未經測試,可能少部份有語法上的錯誤
[ 本帖最后由 abel 于 2009-10-21 09:58 编辑 ] |
|