Goodby, procmail. Hello, scmail.
長年お世話になった procmail を捨てて、scmail に移行しました。
scmail は Scheme で書かれていて、ルールも Scheme で書ける素敵な MDA です。
lambda and or regexp を並べていくだけなので非常に直感的。[作者の高林さんによる素晴しい紹介/説明ページもあります。
(add-filter-rule! (lambda (mail) (or (and (mail 'from "bank.example.com") (mail 'subject "ATM") (refile mail ".notifications.example-bank")) (and (mail 'from "no-reply@exmaple.com") (mail 'subject "購読対象") (refile mail ".notifications.microblog")))))
こんなに快適だったなんて……もっとはやく移行してしまえば良かったです ;)
もちろん「From: に "string" が含まれるだけ」などの単一条件なら lambda 不要。
(add-filter-rule! '(from ("foryou@amazon.co.jp" ".newsletters.amazon") ("new-music.itunes.com" ".newsletters.apple.itunes") ("ana.co.jp" ".newsletters.ana") ("news@twitter.com" ".newsletters.twitter")))
複数箇所に現れる文字列は define してしまいましょう。今後の変更も楽々です。*1。
(define elim/cell "elim@mobile.example.com") (add-filter-rule! ;; ;; Cell phone. ;; (lambda (mail) (and (or (mail 'to elim/cell) (mail 'from elim/cell)) (refile mail ".cell-phone.elim"))))
当然 regexp で match した個所を取り出してフォルダ名を作ることもできます。
;; ;; 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"))http://0xcc.net/scmail/
procmail の複雑怪奇なルールに疲れた方、一度 scmail を試されてはいかがでしょうか。