Commit ab4f429b ab4f429b4d79da1c9f0fb5d133f02e096ab0ffd1 by Sergey Poznyakoff

Automatic mail responder for use with guimb.

1 parent 24f9160f
1 ;;;; GNU mailutils - a suite of utilities for electronic mail
2 ;;;; Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
3 ;;;;
4 ;;;; This program is free software; you can redistribute it and/or modify
5 ;;;; it under the terms of the GNU General Public License as published by
6 ;;;; the Free Software Foundation; either version 2, or (at your option)
7 ;;;; any later version.
8 ;;;;
9 ;;;; This program is distributed in the hope that it will be useful,
10 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ;;;; GNU General Public License for more details.
13 ;;;;
14 ;;;; You should have received a copy of the GNU General Public License
15 ;;;; along with this program; if not, write to the Free Software
16 ;;;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 ;;; This is a simple Guile program that generates automatic reply to
19 ;;; incoming mail messages.
20 ;;;
21 ;;; usage: to your /etc/aliases add:
22 ;;;
23 ;;; username: "|/usr/local/bin/guimb -f <path>/reply.scm"
24 ;;;
25 ;;; and adjust variables below to your liking.
26 ;;; Any message to the address username@your.host will be responded
27 ;;; and (optionally) saved in a mailbox.
28
29 (define indent-prefix "> ")
30 (define save-mailbox #f)
31 (define reply-text
32 "Sorry, I am not here to attend your message. I will do\n\
33 it as soon as I come back.\n\n\
34 Kind regards\n")
35
36 ;; Reply to the incoming message
37 (define (reply in-msg)
38 (let* ((out-msg (mu-message-create))
39 (inbody (mu-message-get-body in-msg))
40 (outbody (mu-message-get-body out-msg)))
41 (mu-message-set-header out-msg "To"
42 (mu-message-get-header in-msg "From"))
43 (mu-message-set-header out-msg "Cc"
44 (mu-message-get-header in-msg "Cc"))
45 (mu-message-set-header out-msg "Subject"
46 (string-append
47 "Re: "
48 (mu-message-get-header in-msg "Subject")))
49
50 (mu-body-write outbody reply-text)
51
52 (mu-body-write outbody "\n\nOriginal message:\n")
53 (do ((hdr (mu-message-get-header-fields in-msg) (cdr hdr)))
54 ((null? hdr) #f)
55 (let ((s (car hdr)))
56 (mu-body-write outbody (string-append indent-prefix
57 (car s) ": " (cdr s) "\n"))))
58 (mu-body-write outbody (string-append indent-prefix "\n"))
59 (do ((line (mu-body-read-line inbody) (mu-body-read-line inbody)))
60 ((eof-object? line) #f)
61 (mu-body-write outbody (string-append indent-prefix line)))
62
63 (mu-message-send out-msg)))
64
65 ;;; Upon receiving a message, store it away in the save mailbox and
66 ;;; reply to the sender.
67 (let ((mbox (and save-mailbox (mu-mailbox-open save-mailbox "cw")))
68 (msg (mu-mailbox-get-message current-mailbox 1)))
69 (cond
70 (mbox
71 (mu-mailbox-append-message mbox msg)
72 (mu-mailbox-close mbox)))
73 (reply msg))
74
75
76
...\ No newline at end of file ...\ No newline at end of file