annotate lisp/utils/mailpost.el @ 2:ac2d302a0011 r19-15b2

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