+ (loop mmsg received-messages)))))))
+
+(define (make-single-recipient-messages mmsg smtp-session config)
+ (map
+ (lambda (to stamp)
+ (print "making singleton messages: " to " " stamp)
+ (make-message to (multi-message-from mmsg)
+ (conc "Received: from " (smtp-session 'helo) "\n"
+ "\tby " (config-host config) "\n"
+ "\tfor " to ";\n"
+ "\t" (time-stamp) "\n"
+ (multi-message-text mmsg))
+ (multi-message-user mmsg)
+ (multi-message-password mmsg)
+ stamp))
+ (multi-message-tos mmsg)
+ (multi-message-stamps mmsg)))
+
+
+;;; Message stamping and validation
+;;
+
+(define (get-local-addresses config)
+ (map (lambda (p) (cons
+ (conc "<" (car p) "@" (config-host config) ">")
+ (cdr p)))
+ (map (lambda (file)
+ (list (pathname-file file) file
+ (let ((password-file (conc file ".auth")))
+ (if (file-exists? password-file)
+ (with-input-from-file password-file read-line)
+ #f))))
+ (filter directory-exists?
+ (glob (conc (config-spool-dir config) "/*"))))))
+
+(define (make-message-stamp to mmsg config)
+ (let* ((local-addresses (get-local-addresses config))
+ (local-dest (assoc to local-addresses))
+ (local-src (assoc (multi-message-from mmsg) local-addresses)))
+ (cond
+ (local-dest
+ (list #t 'local (cadr local-dest)))
+ (local-src
+ (let ((host-password (caddr local-src)))
+ (if (and (string=? (conc "<" (multi-message-user mmsg) "@" (config-host config) ">")
+ (multi-message-from mmsg))
+ host-password
+ (string=? (multi-message-password mmsg) host-password))
+ (list #t 'remote)
+ (begin
+ (print "Provided password " (multi-message-password mmsg))
+ (print "Host password " host-password)
+ (list #f 'remote)))))
+ (else
+ (list #f 'relay)))))