#! @GOSH@
;;; -*- scheme -*-
;;;
;;; scmail - a mail filter written in Scheme
;;;
;;; Copyright (C) 2002-2004 Satoru Takabayashi <satoru@namazu.org> 
;;;     All rights reserved.
;;;     This is free software with ABSOLUTELY NO WARRANTY.
;;;
;;; Permission to use, copy, modify, distribute this software and
;;; accompanying documentation for any purpose is hereby granted,
;;; provided that existing copyright notices are retained in all
;;; copies and that this notice is included verbatim in all
;;; distributions.
;;; This software is provided as is, without express or implied
;;; warranty.  In no circumstances the author(s) shall be liable
;;; for any damages arising out of the use of this software.
;;;

(use scmail)
(use scmail.config)
(use scmail.mail)
(use scmail.mailbox)
(use file.util)

(define (main-process mailbox target-folder dry-run-mode)
  (for-each (lambda (file)
              (if (file-exists? file)
                  (let* ((mailbox-type (ref (scmail-config) 'mailbox-type))
                         (mail (make-scmail-mail mailbox-type
                                                 :file file
                                                 :mailbox mailbox
                                                 :dry-run-mode dry-run-mode)))
                    (scmail-filter mail))))
            (scmail-mailbox-mail-list mailbox target-folder)))


(define (main args)
  (scmail-main args main-process 'refile-rules #f)
  0)
