5  User Filters

The filter is located in the user’s  /.hato/filter file. It is evaluated as Scheme script in a restricted environment with various procedures acting on a default (current-mail) object. The final result should be either a string or list or strings indicating mail destinations.

If the final result is false or undefined the mail is delivered to (default-folder). Likewise if any errors occur they will be caught, logged, and the mail delivered to (default-folder).

You may return a result immediately with the escape continuation bound to ’return’.

During execution of the filter anything written to (current-output-port) is logged to  /.hato/filter.log.

If the user’s  /.hato/filter is not found, then processing proceeds to the user’s  /.forward. This may either be an /etc/aliases list of addresses to forward to, or an RFC 3028 Sieve filter script. To enable the latter, first line should be a # comment including the word “Sieve” (this is compatible with the Exim implementation). See http://www.faqs.org/rfcs/rfc3028.html for more details.

5.1  Filter Language

Currently the filter environment includes all of R5RS (except LOAD, TRANSCRIPT-ON/OFF and the default environments), and is specifically case-insensitive, even if the host Scheme implementation defaults to case-sensitive. In addition, the following utilities are provided:

5.2  A Sample Filter

;; initial duplicate & spam checks
(cond
  ((is-duplicate?)
   (print "discarding duplicate: " (Message-Id))
   (discard))
  ((not (white-list?))
   (cond
     ((not (domain-key-verify))    (refuse))
     ((> (spam-probability) 0.90)  (refuse))
     ((> (spam-probability) 0.60)  (return "spam"))
     (else (white-list)))))

;; manual filtering & folder handling, etc.
(cond
  ((To? "my-mail-list@nosuchdomain.comm") "my-mail-list")
  (else (auto-list)))

Note in the above filter the To? test is redundant if the List-Id header uses my-mail-list as the local part. If you’re using auto-list then the only reason to manually filter lists is if you want to specify alternate mailbox names.