What's scmail?
scmail is a mail filter written in Scheme. scmail can filter an incoming mail when it is received and filter mails in a mailbox. A bayesian spam filter called scbayes is also included.
What's new?
- 2004-07-27: scmail 1.3 Released!
- Multiple occurrences of fields having the same name are now supported (ex. Delivered-To:).
- Other small modifications have been also made.
- 2004-03-11: scmail 1.2 Released!
- New option --dry-run (-n) for scmail-refile/scmail-deliver is added. (it works just like make -n)
- Short command line options are now supported.
- 2004-02-05: scmail 1.0 Released!
- A spam filter called scbayes is now included
- scbayes is developed by Shiro Kawai.
- Names of configuration files are changed.
You can keep using old names but I recomend you to rename them.
- ~/.scmailrc -> ~/.scmail/config
- ~/.scmailrc-deliver -> ~/.scmail/deliver-rules
- ~/.scmailrc-refile -> ~/.scmail/refile-rules
- ~/.scmail-log -> ~/.scmail/log
- Writing a rule using lambda becomes easy.
- Please see a sample code in dot.scmail/deliver-rules.sample.
- Many codes are rearranged.
- A test suite is prepared (make check)
- A spam filter called scbayes is now included
- 2002-10-24: scmail 0.1 Released!
Requirements
- Gauche 0.7.4.1 or later
Characteristics
- Written simply in Scheme.
- spam filter scbayes is included. (now testing)
- scmail supports MH and Maildir mailboxes.
- Simple filtering rules can be written in S-expressions.
- Advanced filtering rules can be written in Scheme programs.
- scmail can filter an incoming mail when it is received (like procmail).
- scmail can filter mails in a mailbox.
Installation
To install scmail, run the following commands.
% gzip -dc scmail-1.3.tar.gz | tar xvf - % cd scmail-1.3 Password: (enter root's password) # make # make install
Components
- scmail-deliver: a command to filter an incoming mail when it is received.
- scmail-refile: a command to filter mails in a mailbox.
- scbayes: a command to learn spam and nonspam mails for spam filtering.
Configuration
Copy a sample file (~/dot.scmail/config.sample) to ~/.scmail/config and edit it.
;; -*- scheme -*- ( :smtp-host "localhost" :log-file "~/.scmail/log" :umask #o077 ;; for usual mail filtering :refile-rules "~/.scmail/refile-rules" :deliver-rules "~/.scmail/deliver-rules" ;; for spam filtering :token-table "~/.scmail/token-table.dbm" :digest "~/.scmail/digest.dbm" ;; for MH :mailbox "~/Mail" :inbox "inbox" :spam "spam" ; a folder for spam mails :mailbox-type mh ;; for Maildir ;; :mailbox "~/Maildir" ;; :inbox "" ;; :spam ".spam" ; a folder for spam mails ;; :mailbox-type maildir )
Using scmail-deliver
scmail-deliver is a command to filter an incoming mail when it is received. scmail-deliver uses Filtering rules defined in ~/.scmail/deliver-rules. You can copy a sample file (dot.scmail/deliver-rules.sample) to ~/.scmail/deliver-rules.
If your mail server is Sendmail or Postfix, you can put the following ~/.forward file to filter an incoming mail when it is received.
| /usr/local/bin/scmail-deliver
If you are using fetchmail to fetch mails from a POP server, you can add the following code into your ~/.fetchmailrc file to use scmailrc-deliver.
poll pop3.example.org protocol apop user satoru mda "/usr/local/bin/scmail-deliver" no mimedecode
Using scmail-refile
scmail-refile is a command to filter mails in a mailbox. scmail-refile uses Filtering rules defined in ~/.scmail/refile-rules. You can copy a sample file (dot.scmail/refile-rules.sample) to ~/.scmail/refile-rules.
To use scmail-refile, run it on the command line like the following:
% scmail-refile refile: inbox/93 -> ml/enkai@coboler/57 refile: inbox/94 -> ml/linux-zaurus/218 refile: inbox/98 -> ml/linux-zaurus/219 refile: inbox/99 -> ml/ming/42
In this example, the first line in the output messages shows a mail 93 in inbox folder is refiled to ml/enkai@colber as a mail 57. ~/.scmail/log file contains the same report with time information.
% tail -5 ~/.scmail/log 2002-09-26T12:49:31: refile: inbox/93 -> ml/enkai@coboler/57 2002-09-26T12:49:31: refile: inbox/94 -> ml/linux-zaurus/218 2002-09-26T12:49:31: refile: inbox/98 -> ml/linux-zaurus/219 2002-09-26T12:49:31: refile: inbox/99 -> ml/ming/42
Filtering rules
You can edit sample files.
dot.scmail/deliver-rules.sample
;; -*- scheme -*- ;; ;; Copy all mails to "inbox-all" folder for backup. ;; (add-filter-rule! (lambda (mail) (copy mail "inbox-all"))) (add-filter-rule! ;; ;; Forward a mail from "[email protected]" to "[email protected]". ;; (a copy of mail remains) ;; '(from ("[email protected]" (forward "[email protected]"))) ;; ;; Redirect a mail from "[email protected]" to "[email protected]". ;; (a copy of mail doesn't remain) ;; '(from ("[email protected]" (redirect "[email protected]"))) ;; ;; Drop a mail writtein in unreadable charcodes to "spam". ;; For people who cannot read a mail written in Chinese and Korean. ;; '(content-type (#/gb2312|euc-kr|big5|gbk|ks_c_5601/i "spam")) ;; ;; Drop a Japanese spam mail to "spam" folder. ;; '(subject ((#/[未末]承[認諾]広告[**※]/ #/[!!]広告[!!]/) "spam"))) ;; ;; Drop a mail containing "viagra" in Subject: and "text/html" in the body ;; to "spam" folder. ;; (add-filter-rule! (lambda (mail) (and (mail 'subject "viagra") (mail 'body "text/html") (refile mail "spam")))) ;; Filter spam mails. ;; Please use scbayes to learn spam and nonspam mails beforehand. ;; (add-bayesian-filter-rule!) ;; Filter spam mails using a white list. ;; (use srfi-1) ;; (use scmail.bayesian-filter) ;; (define white-list ;; (list "[email protected]" ;; "[email protected]")) ;; (add-filter-rule! ;; (lambda (mail) ;; (and (not (any (cut mail 'from <>) white-list)) ;; (mail-is-spam? mail) ;; (refile mail "spam"))))
dot.scmail/refile-rules.sample
;; -*- scheme -*- (add-filter-rule! ;; ;; Refile a mail from "[email protected]" to "from/foo" folder. ;; '(from ("[email protected]" "from/foo")) ;; ;; Refile a mail to "[email protected]" to "admin" folder. ;; '(to/cc ("[email protected]" "admin")) ;; ;; Refile a mail from a mailing list according to List-Id header. ;; e.g. "List-Id: <ml.example.jp>" => "ml/ml.example.jp" ;; '(list-id (#/<([-.\w]+)>/ "ml/\\1")) ;; ;; Refile a mail from a mailing list according to X-ML-Name header. ;; e.g. "X-ML-Name: foo-ml" => "ml/foo-ml" ;; '(x-ml-name (#/([-.\w]+)/ "ml/\\1")) ;; ;; Refile a mail from [email protected] or [email protected] ;; to "from/satoru" folder. ;; '(from (("[email protected]" "[email protected]") "from/satoru"))) ;; Replace unsafe characters with `-' in match data. (set-match-data-replace-rule! '(#/[^a-zA-Z0-9_-]/ "-")) ;; Filter spam mails ;; (add-bayesian-filter-rule!)
Using a spam filter
Please see scbayes's documentation.
FAQ
How does scmail handle a huge mail?
Since scmail handles a mail on memory entirely, a huge mail which cannot fit in memory is not supported. So, scmail-deliver perhaps loses an incoming huge mail.
What happens if a rule file has syntax errors?
scmail uses rules read correctly and broken rules are ignored. Messages of syntax errors are reported in ~/.scmail/log.
Download
scmail is a free software with ABSOLUTELY NO WARRANTY under so called "BSD licence".
References
- Simon Cozens: Filtering Mail with Mail::Audit and News::Gateway,
The Perl Journal, Vol. 5, No. 2. (2000)
- Describing a mail filter written in Perl. It starts with a strong message: "Let's face it. procmail is horrid."
Links
- procmail: A popular mail filter with an abnormal syntax.
- maildrop: A mail filter with a C-like syntax.
- Sieve: A standard language for mail filtering. Although it is an RFC, its syntax is not so good (IMHO). Various implementations are available.
- MH: A traditional Unix mailer. slocal command filters an incoming mail when it is received, and pick and refile commands filter mails in a mailbox respectively.
- spamassasin: A mail filter to identify spam.
- ifile: A machine-learning-based mail filter.
- bsfilter A bayesian spam filter written in Ruby.
- Bogofilter A bayesian spam filter written in C.
- Yample Yet Another Mail Processing Language
- freshmeat.net: scmail