*** empty log message ***
[bpt/emacs.git] / lisp / mail / mailpost.el
1 ;;; mailpost.el --- RMAIL coupler to /usr/uci/post mailer
2
3 ;; Author: Gary Delp <delp@huey.Udel.Edu>
4 ;; Maintainer: FSF
5 ;; Created: 13 Jan 1986
6 ;; Last-Modified: 30 May 1992
7 ;; Keywords: mail
8
9 ;; This is in the public domain
10 ;; since Delp distributed it without a copyright notice in 1986.
11
12 ;;; Commentary:
13
14 ;; Yet another mail interface. this for the rmail system to provide
15 ;; the missing sendmail interface on systems without /usr/lib/sendmail,
16 ;; but with /usr/uci/post.
17
18 ;;; Code:
19
20 ;; (setq send-mail-function 'post-mail-send-it)
21
22 (defun post-mail-send-it ()
23 "The MH -post interface for `rmail-mail' to call.
24 To use it, include \"(setq send-mail-function 'post-mail-send-it)\" in
25 site-init."
26 (let ((errbuf (if mail-interactive
27 (generate-new-buffer " post-mail errors")
28 0))
29 (temfile "/tmp/,rpost")
30 (tembuf (generate-new-buffer " post-mail temp"))
31 (case-fold-search nil)
32 delimline
33 (mailbuf (current-buffer)))
34 (unwind-protect
35 (save-excursion
36 (set-buffer tembuf)
37 (erase-buffer)
38 (insert-buffer-substring mailbuf)
39 (goto-char (point-max))
40 ;; require one newline at the end.
41 (or (= (preceding-char) ?\n)
42 (insert ?\n))
43 ;; Change header-delimiter to be what post-mail expects.
44 (goto-char (point-min))
45 (search-forward (concat "\n" mail-header-separator "\n"))
46 (replace-match "\n\n")
47 (backward-char 1)
48 (setq delimline (point-marker))
49 (if mail-aliases
50 (expand-mail-aliases (point-min) delimline))
51 (goto-char (point-min))
52 ;; ignore any blank lines in the header
53 (while (and (re-search-forward "\n\n\n*" delimline t)
54 (< (point) delimline))
55 (replace-match "\n"))
56 ;; Find and handle any FCC fields.
57 (let ((case-fold-search t))
58 (goto-char (point-min))
59 (if (re-search-forward "^FCC:" delimline t)
60 (mail-do-fcc delimline))
61 ;; If there is a From and no Sender, put it a Sender.
62 (goto-char (point-min))
63 (and (re-search-forward "^From:" delimline t)
64 (not (save-excursion
65 (goto-char (point-min))
66 (re-search-forward "^Sender:" delimline t)))
67 (progn
68 (forward-line 1)
69 (insert "Sender: " (user-login-name) "\n")))
70 ;; don't send out a blank subject line
71 (goto-char (point-min))
72 (if (re-search-forward "^Subject:[ \t]*\n" delimline t)
73 (replace-match ""))
74 (if mail-interactive
75 (save-excursion
76 (set-buffer errbuf)
77 (erase-buffer))))
78 (write-file (setq temfile (make-temp-name temfile)))
79 (set-file-modes temfile 384)
80 (apply 'call-process
81 (append (list (if (boundp 'post-mail-program)
82 post-mail-program
83 "/usr/uci/lib/mh/post")
84 nil errbuf nil
85 "-nofilter" "-msgid")
86 (if mail-interactive '("-watch") '("-nowatch"))
87 (list temfile)))
88 (if mail-interactive
89 (save-excursion
90 (set-buffer errbuf)
91 (goto-char (point-min))
92 (while (re-search-forward "\n\n* *" nil t)
93 (replace-match "; "))
94 (if (not (zerop (buffer-size)))
95 (error "Sending...failed to %s"
96 (buffer-substring (point-min) (point-max)))))))
97 (kill-buffer tembuf)
98 (if (bufferp errbuf)
99 (switch-to-buffer errbuf)))))
100
101 ;;; mailpost.el ends here