0
|
1 ;;; mailpost.el --- RMAIL coupler to /usr/uci/post mailer
|
|
2
|
|
3 ;; This is in the public domain
|
|
4 ;; since Delp distributed it without a copyright notice in 1986.
|
|
5
|
|
6 ;; Author: Gary Delp <delp@huey.Udel.Edu>
|
|
7 ;; Maintainer: FSF
|
|
8 ;; Created: 13 Jan 1986
|
|
9 ;; Keywords: mail
|
|
10
|
2
|
11 ;; This file is part of XEmacs.
|
|
12
|
|
13 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
14 ;; under the terms of the GNU General Public License as published by
|
|
15 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
16 ;; any later version.
|
|
17
|
|
18 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
19 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
21 ;; General Public License for more details.
|
|
22
|
|
23 ;; You should have received a copy of the GNU General Public License
|
|
24 ;; along with XEmacs; see the file COPYING. If not, write to the Free
|
|
25 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
26 ;; 02111-1307, USA.
|
|
27
|
|
28 ;;; Synched up with: FSF 19.34.
|
|
29
|
0
|
30 ;;; Commentary:
|
|
31
|
|
32 ;; Yet another mail interface. this for the rmail system to provide
|
|
33 ;; the missing sendmail interface on systems without /usr/lib/sendmail,
|
|
34 ;; but with /usr/uci/post.
|
|
35
|
|
36 ;;; Code:
|
|
37
|
|
38 ;(require 'mailalias) ;; not in XEmacs
|
|
39 (require 'sendmail)
|
|
40
|
|
41 ;; (setq send-mail-function 'post-mail-send-it)
|
|
42
|
|
43 (defun post-mail-send-it ()
|
|
44 "The MH -post interface for `rmail-mail' to call.
|
|
45 To use it, include \"(setq send-mail-function 'post-mail-send-it)\" in
|
|
46 site-init."
|
|
47 (let ((errbuf (if mail-interactive
|
|
48 (generate-new-buffer " post-mail errors")
|
|
49 0))
|
|
50 (temfile "/tmp/,rpost")
|
|
51 (tembuf (generate-new-buffer " post-mail temp"))
|
|
52 (case-fold-search nil)
|
|
53 delimline
|
|
54 (mailbuf (current-buffer)))
|
|
55 (unwind-protect
|
|
56 (save-excursion
|
|
57 (set-buffer tembuf)
|
|
58 (erase-buffer)
|
|
59 (insert-buffer-substring mailbuf)
|
|
60 (goto-char (point-max))
|
|
61 ;; require one newline at the end.
|
|
62 (or (= (preceding-char) ?\n)
|
|
63 (insert ?\n))
|
|
64 ;; Change header-delimiter to be what post-mail expects.
|
|
65 (goto-char (point-min))
|
|
66 (search-forward (concat "\n" mail-header-separator "\n"))
|
|
67 (replace-match "\n\n")
|
|
68 (backward-char 1)
|
|
69 (setq delimline (point-marker))
|
|
70 ;; XEmacs: expand-mail-aliases doesn't exist.
|
|
71 (if (and mail-aliases (fboundp 'expand-mail-aliases))
|
|
72 (expand-mail-aliases (point-min) delimline))
|
|
73 (goto-char (point-min))
|
|
74 ;; ignore any blank lines in the header
|
|
75 (while (and (re-search-forward "\n\n\n*" delimline t)
|
|
76 (< (point) delimline))
|
|
77 (replace-match "\n"))
|
|
78 ;; Find and handle any FCC fields.
|
|
79 (let ((case-fold-search t))
|
|
80 (goto-char (point-min))
|
|
81 (if (re-search-forward "^FCC:" delimline t)
|
|
82 (mail-do-fcc delimline))
|
|
83 ;; If there is a From and no Sender, put it a Sender.
|
|
84 (goto-char (point-min))
|
|
85 (and (re-search-forward "^From:" delimline t)
|
|
86 (not (save-excursion
|
|
87 (goto-char (point-min))
|
|
88 (re-search-forward "^Sender:" delimline t)))
|
|
89 (progn
|
|
90 (forward-line 1)
|
|
91 (insert "Sender: " (user-login-name) "\n")))
|
|
92 ;; don't send out a blank subject line
|
|
93 (goto-char (point-min))
|
|
94 (if (re-search-forward "^Subject:[ \t]*\n" delimline t)
|
|
95 (replace-match ""))
|
|
96 (if mail-interactive
|
|
97 (save-excursion
|
|
98 (set-buffer errbuf)
|
|
99 (erase-buffer))))
|
|
100 (write-file (setq temfile (make-temp-name temfile)))
|
|
101 (set-file-modes temfile 384)
|
|
102 (apply 'call-process
|
|
103 (append (list (if (boundp 'post-mail-program)
|
|
104 post-mail-program
|
|
105 "/usr/uci/lib/mh/post")
|
|
106 nil errbuf nil
|
|
107 "-nofilter" "-msgid")
|
|
108 (if mail-interactive '("-watch") '("-nowatch"))
|
|
109 (list temfile)))
|
|
110 (if mail-interactive
|
|
111 (save-excursion
|
|
112 (set-buffer errbuf)
|
|
113 (goto-char (point-min))
|
|
114 (while (re-search-forward "\n\n* *" nil t)
|
|
115 (replace-match "; "))
|
|
116 (if (not (zerop (buffer-size)))
|
|
117 (error "Sending...failed to %s"
|
|
118 (buffer-substring (point-min) (point-max)))))))
|
|
119 (kill-buffer tembuf)
|
|
120 (if (bufferp errbuf)
|
|
121 (switch-to-buffer errbuf)))))
|
|
122
|
|
123 ;;; mailpost.el ends here
|