;;; e-mail-filter.mhtml: -*- Meta-HTML -*-  Filter an E-mail message.
;;; 
;;;  Copyright (c) 1998 Brian J. Fox
;;;  Author: Brian J. Fox (bfox@ai.mit.edu) Tue Aug 11 11:42:12 1998.
;;;
;;; This code could be the target of an E-mail alias.
;;; It expects the message to arrive on the standard-input, reads and parses
;;; the message, and then, (in our trivial example) formats the message to
;;; a file in /tmp.  Of course, it could conditionally re-send the message
;;; to another recipient, or to a mailing list, or what have you.

<set-var mhc::explicit-output-only = true>

;;; Get the message from stdin.
<with-open-stream s *standard-input*>
  <stream-get-contents s message>
</with-open-stream>

;;; Parse the message into its components, and save them in an
;;; association list.
<set-var message-alist = <e-mail::parse-message message>>

;;; Format the message to a file.
<with-open-stream s /tmp/e-mail-filter.output mode=write-create>
  <stream-put s "Message received on: <date>\n">
  <stream-put s "From: <alist-get-var message-alist hdr_FROM>\n">
  <stream-put s "  To: <alist-get-var message-alist hdr_TO>\n">
  <stream-put s "\n --- BODY ---\n">
  <stream-put s <alist-get-var message-alist body>>
  <stream-put s "\n --- /BODY ---\n">
</with-open-stream>

