Last Modified: 2003-03-21 (Since: 2002-10-24)
scmail is a mail filter written in Scheme. scmail can filter an incoming mail when it is received and filter mails in a mailbox.
To install scmail, run the following commands.
% gzip -dc scmail-0.2.tar.gz | tar xvf - % cd scmail-0.2 Password: (enter root's password) # make # make install
Copy a sample file (scmailrc.sample) to ~/.scmailrc and edit it.
;; -*- scheme -*- ( :log-file "~/.scmail-log" :smtp-host "mailhost" ; for mail forwarding ;; for MH :mailbox "~/Mail" :inbox "inbox" :mailbox-type mh ;; for Maildir ;; :mailbox "~/Maildir" ;; :inbox "" ;; :mailbox-type maildir )
scmail-deliver is a command to filter an incoming mail when it is received. scmail-deliver uses Filtering rules defined in ~/.scmailrc-deliver. You can copy a sample file (scmailrc-deliver.sample) to ~/.scmailrc-deliver.
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
scmail-refile is a command to filter mails in a mailbox. scmail-refile uses Filtering rules defined in ~/.scmailrc-refile. You can copy a sample file (scmailrc-refile.sample) to ~/.scmailrc-refile.
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
You can edit sample files.
;; -*- scheme -*- ;; ;; This sample file cointains Japanese EUC-JP characters. ;; Please remove unreadable rules if you don't want Japanese rules. ;; ;; ;; Copy all mails to "inbox-all" folder for backup. ;; (add-filter-rule! (lambda (config mail) (command-copy config mail "inbox-all"))) (add-filter-rule! ;; ;; Forward a mail from "partner@example.net" to "mobile@example.com". ;; '(from ("partner@example.net" (forward "mobile@example.com"))) ;; ;; Drop a mail writtein in unreadable charcodes to "junk". ;; For people who cannot read a mail written in Chinese and Korean. ;; '(content-type (#/gb2312|euc-kr|big5|gbk|ks_c_5601/i "junk")) ;; ;; Drop a Japanese junk mail to "junk" folder. ;; '(subject ((#/[̤Ëö]¾µ[ǧÂú]¹¹ð[*¡ö¢¨]/ #/[¡ª!]¹¹ð[¡ª!]/) "junk"))) ;; ;; Drop a mail containing junk words in Subject: and "text/html" in the body ;; to "junk" folder. ;; (define junk-words '("money" "adult" "sex" "viagra")) (use srfi-13) ; string-contains-ci (use srfi-1) ; find (add-filter-rule! (lambda (config mail) (if (and (find (lambda (word) (string-contains-ci (mail-query mail 'subject) word)) junk-words) (string-contains-ci (mail-query mail 'body) "text/html")) (command-refile config mail "junk") :next)))
;; -*- scheme -*- (add-filter-rule! ;; ;; Refile a mail from "foo@example.jp" to "from/foo" folder. ;; '(from ("foo@example.jp" "from/foo")) ;; ;; Refile a mail to "admin@example.com" to "admin" folder. ;; '(to/cc ("admin@example.com" "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 satoru@example.jp or satoru@example.org ;; to "from/satoru" folder. ;; '(from (("satoru@example.jp" "satoru@example.org") "from/satoru"))) ;; Replace unsafe characters with `-' in match data. (set-match-data-replace-rule! '(#/[^a-zA-Z0-9_-]/ "-"))
spammer@example.com nasty-guy@example.net virus-sender@example.org
scmail handle a broken rule file as an empty rule file. Messages of syntax errors are reported in ~/.scmail-log.
scmail is a free software with ABSOLUTELY NO WARRANTY under the terms of the GNU Lesser General Public License.