;;;; -*- scheme -*- ;;;; maidag-example.scm -- an example filter script for distributing ;;;; incoming mail ;;;; ;;;; Copyright (C) 2002-2004, 2006-2007, 2009-2012 Free Software ;;;; Foundation, Inc. ;;;; ;;;; maidag-example.scm is free software; you can redistribute it ;;;; and/or modify it under the terms of the GNU General Public ;;;; License as published by the Free Software Foundation; either ;;;; version 3, or (at your option) any later version. ;;;; ;;;; maidag-example.scm is distributed in the hope that it will be useful, ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;;; GNU General Public License for more details. ;;;; ;;;; For a copy of the GNU General Public License, see ;;;; . ;;;; ;;;; Load the GNU Mailutils library -- a must! (use-modules (mailutils mailutils)) ;;;; This script is meant to be called on a per-email basis from the ;;;; GNU Mailutils mail delivery agent program 'maidag'. This script ;;;; defines all the utility functions first -- the real work is done ;;;; in 'mailutils-check-message' at the end (define (construct-folder-path sender-title) "Insert a piece into a file path, the resulting path to the file is expected to already exist on the file system, but the file itself needn't." (if sender-title (string-append "mbox:///home/chris/mail/mailboxes/" sender-title "/mBoX-MeSsAgEs") #f)) ;; An association list mapping incoming email 'From:' headers to a ;; piece of a file path (define sender-folders '(("Ars Technica " . "RSS/ArsTechnica") ("\"Deutsche Welle: DW-WORLD.DE\" " . "RSS/DWelle") ("\"Master Feed : The Atlantic\" " . "RSS/Atlantic") ("" . "") ("" . ""))) (define (determine-target-folder message-from) "Select a piece of a file path based on the incoming message's 'From:' header" (cond ;; These guys include the author's name in the From, so just check first bit ((string=? "\"The Register:" (substring message-from 0 14)) "RSS/The Register") (else (assoc-ref sender-folders message-from)))) (define (mailutils-check-message message) "Here is where the work gets done. Based on the 'From:' header of the incoming message, we try to build a file system path to a target mailbox. If that succeeds, we try to open the file at the end of the path, creating it if necessary. And if that succeeds, we try to append the incoming message to it, and flag the message as 'deleted'." (let* ((message-origin (mu-message-get-header message "From")) (target-mailbox-name (and message-origin (construct-folder-path (determine-target-folder message-origin))))) (let ((target-mailbox (and target-mailbox-name (mu-mailbox-open target-mailbox-name "cw")))) (when target-mailbox (mu-mailbox-append-message target-mailbox message) (mu-mailbox-close target-mailbox) (mu-message-delete message)))))