annotate lisp/utils/mailpost.el @ 0:376386a54a3c r19-14

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