A.13. 豁免转发邮件

在 SMTP 事务中添加所有这些检查之后,我们可能会发现自己间接地制造了附带垃圾邮件,这是由于拒绝了来自受信任来源(例如邮件列表和其他站点上的邮件帐户)转发的邮件(有关详细信息,请参阅关于转发邮件的讨论)。我们现在需要将这些主机加入白名单,以便豁免它们于 SMTP 拒绝——至少是那些由我们的垃圾邮件和/或病毒过滤引起的拒绝。

在此示例中,我们将针对每个 RCPT TO: 命令查询两个文件

如果您的邮件用户没有本地用户帐户和主目录,您可能需要修改文件路径和/或查找机制,以使其更适合您的系统(例如,数据库查找或 LDAP 查询)。

如果在其中一个白名单中找到发送主机,我们将单词 "accept" 保存在$acl_m0中,并清除$acl_m1的内容,如前一节关于选择性延迟中所述。这将表明我们不应在后续语句中拒绝邮件。

acl_rcpt_to 中,我们在验证收件人地址之后,但在任何accept语句之前插入以下语句,这些语句与来自远程主机到本地用户的未经验证的传递有关(即,在任何灰名单检查、信封签名检查等之前)

  # Accept the mail if the sending host is matched in the global
  # whitelist file.  Temporarily set $acl_m9 to point to this  file. 
  # If the host is found, set a flag in $acl_m0 and clear $acl_m1 to 
  # indicate that we should not reject this mail later.
  # 
  accept
    set acl_m9  = /etc/mail/whitelist-hosts
    hosts       = ${if exists {$acl_m9}{$acl_m9}}
    set acl_m0  = accept
    set acl_m1  = 


  # Accept the mail if the sending host is matched in the ".forwarders" 
  # file in the recipient's home directory.  Temporarily set $acl_m9 to
  # point to this file.  If the host is found, set a flag in $acl_m0 and
  # clear $acl_m1 to indicate that we should not reject this mail later.
  #
  accept
    domains     = +local_domains
    set acl_m9  = /home/${extract{1}{=}{${lc:$local_part}}}/.forwarders
    hosts       = ${if exists {$acl_m9}{$acl_m9}} 
    set acl_m0  = accept
    set acl_m1  = 

acl_data ACL 中的各种语句中,我们检查$acl_m0的内容,以避免由于缺少 RFC2822 标头而拒绝来自白名单主机的邮件,如果如上所述设置了此项

  deny
    message     = Your message does not conform to RFC2822 standard
    log_message = missing header lines
    !hosts      = +relay_from_hosts
    !senders    = : postmaster@*
    condition   = ${if !eq {$acl_m0}{accept}{true}}
    condition   = ${if or {{!def:h_Message-ID:}\
                           {!def:h_Date:}\
                           {!def:h_Subject:}} {true}{false}}

适当的检查嵌入在最终 ACL 中,接下来。