annotate lisp/mail/mailpost.el @ 182:35ea4993d08c

*** empty log message ***
author Jim Blandy <jimb@redhat.com>
date Sat, 02 Feb 1991 12:41:08 +0000
parents 504879714b38
children d1d8765cc35e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 ;;
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2 ;; P O S T . E L
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3 ;;
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4 ;; Yet another mail interface. this for the rmail system to provide
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 ;; the missing sendmail interface on systems without /usr/lib/sendmail,
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 ;; but with /usr/uci/post.
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 ;;
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 ;; created by: Gary Delp <delp at huey.Udel.Edu>
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 ;; Mon Jan 13 14:45:12 1986
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10 ;;
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;;
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; (setq send-mail-function 'post-mail-send-it)
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 (defun post-mail-send-it ()
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 "\
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 the MH -post interface for rmail-mail to call.
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 to use it, include (setq send-mail-function 'post-mail-send-it) in site-init."
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 (let ((errbuf (if mail-interactive
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 (generate-new-buffer " post-mail errors")
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 0))
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 (temfile "/tmp/,rpost")
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 (tembuf (generate-new-buffer " post-mail temp"))
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24 (case-fold-search nil)
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 delimline
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 (mailbuf (current-buffer)))
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 (unwind-protect
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 (save-excursion
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 (set-buffer tembuf)
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 (erase-buffer)
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 (insert-buffer-substring mailbuf)
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 (goto-char (point-max))
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 ;; require one newline at the end.
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 (or (= (preceding-char) ?\n)
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 (insert ?\n))
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 ;; Change header-delimiter to be what post-mail expects.
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 (goto-char (point-min))
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 (search-forward (concat "\n" mail-header-separator "\n"))
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 (replace-match "\n\n")
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 (backward-char 1)
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 (setq delimline (point-marker))
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 (if mail-aliases
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 (expand-mail-aliases (point-min) delimline))
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 (goto-char (point-min))
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 ;; ignore any blank lines in the header
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 (while (and (re-search-forward "\n\n\n*" delimline t)
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 (< (point) delimline))
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 (replace-match "\n"))
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 ;; Find and handle any FCC fields.
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 (let ((case-fold-search t))
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 (goto-char (point-min))
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 (if (re-search-forward "^FCC:" delimline t)
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 (mail-do-fcc delimline))
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 ;; If there is a From and no Sender, put it a Sender.
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 (goto-char (point-min))
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 (and (re-search-forward "^From:" delimline t)
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 (not (save-excursion
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 (goto-char (point-min))
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 (re-search-forward "^Sender:" delimline t)))
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 (progn
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 (forward-line 1)
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 (insert "Sender: " (user-login-name) "\n")))
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 ;; don't send out a blank subject line
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 (goto-char (point-min))
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 (if (re-search-forward "^Subject:[ \t]*\n" delimline t)
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 (replace-match ""))
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 (if mail-interactive
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 (save-excursion
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 (set-buffer errbuf)
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 (erase-buffer))))
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 (write-file (setq temfile (make-temp-name temfile)))
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 (set-file-modes temfile 384)
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 (apply 'call-process
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 (append (list (if (boundp 'post-mail-program)
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 post-mail-program
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 "/usr/uci/lib/mh/post")
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 nil errbuf nil
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 "-nofilter" "-msgid")
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 (if mail-interactive '("-watch") '("-nowatch"))
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 (list temfile)))
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 (if mail-interactive
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 (save-excursion
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 (set-buffer errbuf)
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 (goto-char (point-min))
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 (while (re-search-forward "\n\n* *" nil t)
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 (replace-match "; "))
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 (if (not (zerop (buffer-size)))
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 (error "Sending...failed to %s"
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 (buffer-substring (point-min) (point-max)))))))
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 (kill-buffer tembuf)
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 (if (bufferp errbuf)
504879714b38 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 (switch-to-buffer errbuf)))))