- 论坛徽章:
- 1
|
這東西你用 mimedefang 解即可
只是個範例,隨手寫而以, 你自己參考看看
- foreach my $recip (@Recipients) {
- $recip=~/<(\S)@(\S)>$/;
- my ($localpart,$domainpart)=($1,$2);
- next if (! ismydomain($domainpart)); # 不是自己的域名不做 expand 解釋
- next if ( !ismyaliases($localpart)); # 不在 mysql aliases 中
- delete_recipient($recip) if (is_local_user($localpart) && ismyaliases($localpart) ); # 如果 aliases 同 user 帳號,則 user 帳號會不在收件人之列
- foreach my $element (expand($localpart)) {
- add_recipient($element);
- }
- }
- sub ismydomain($)
- {
- my $domain;
- # 讀取 local-host-names 判斷,或以 $local-host-names 變數判斷
- open(LHN,"< /etc/mail/local-host-names");
- $lhn=<LHN>;
- $local_host_names=join('',@lhn);
- if ($domain=~/$local_host_names/i) { # 本機的 user/aliases
- return 1;
- } else {
- return 0;
- }
- }
- $alasies="all rd fae services " #aliases 列表,可程式自動生成,這裏只是舉例故用變數代表
- sub ismyaliases($)
- {
- my $user;
- ($user=~/$aliases/i) ? return 1:return 0;
- }
- sub expand($)
- {
- my $exp;
- # DBI select DB ...
- $sth = $dbh->prepare("select user from aliases where aliases_name='$exp'");
- $sth->execute;
- $rows = $sth->rows;
- return $exp if ($rows==0);
- return (@expand_list); # 自己處理一下 mysql select 結果
- }
复制代码 |
|