Update FSF's address.
[bpt/emacs.git] / lisp / gnus-mh.el
CommitLineData
41487370 1;;; gnus-mh.el --- mh-e interface for Gnus
b578f267 2
41487370
LMI
3;; Copyright (C) 1994,95 Free Software Foundation, Inc.
4
5;; Author: Masanobu UMEDA <umerin@flab.flab.fujitsu.junet>
6;; Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
7;; Keywords: news
8
9;; This file is part of GNU Emacs.
10
11;; GNU Emacs is free software; you can redistribute it and/or modify
12;; it under the terms of the GNU General Public License as published by
13;; the Free Software Foundation; either version 2, or (at your option)
14;; any later version.
15
16;; GNU Emacs is distributed in the hope that it will be useful,
17;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19;; GNU General Public License for more details.
20
21;; You should have received a copy of the GNU General Public License
b578f267
EN
22;; along with GNU Emacs; see the file COPYING. If not, write to the
23;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24;; Boston, MA 02111-1307, USA.
41487370
LMI
25
26;;; Commentary:
27
28;;; Send mail using mh-e.
29
30;; The following mh-e interface is all cooperative works of
31;; tanaka@flab.fujitsu.CO.JP (TANAKA Hiroshi), kawabe@sra.CO.JP
32;; (Yoshikatsu Kawabe), and shingu@casund.cpr.canon.co.jp (Toshiaki
33;; SHINGU).
34
35;;; Code:
36
37(require 'mh-e)
38(require 'mh-comp)
39(require 'gnus)
40(require 'gnus-msg)
41
42(defun gnus-summary-save-article-folder (&optional arg)
43 "Append the current article to an mh folder.
44If N is a positive number, save the N next articles.
45If N is a negative number, save the N previous articles.
46If N is nil and any articles have been marked with the process mark,
47save those articles instead."
48 (interactive "P")
49 (let ((gnus-default-article-saver 'gnus-summary-save-in-folder))
50 (gnus-summary-save-article arg)))
51
52(defun gnus-summary-save-in-folder (&optional folder)
53 "Save this article to MH folder (using `rcvstore' in MH library).
54Optional argument FOLDER specifies folder name."
55 ;; Thanks to yuki@flab.Fujitsu.JUNET and ohm@kaba.junet.
56 (mh-find-path)
57 (let ((folder
58 (or folder
59 (mh-prompt-for-folder
60 "Save article in"
61 (funcall gnus-folder-save-name gnus-newsgroup-name
62 gnus-current-headers gnus-newsgroup-last-folder)
63 t)))
64 (errbuf (get-buffer-create " *Gnus rcvstore*")))
65 (gnus-eval-in-buffer-window
66 gnus-article-buffer
67 (save-restriction
68 (widen)
69 (unwind-protect
70 (call-process-region (point-min) (point-max)
71 (expand-file-name "rcvstore" mh-lib)
72 nil errbuf nil folder)
73 (set-buffer errbuf)
74 (if (zerop (buffer-size))
75 (message "Article saved in folder: %s" folder)
76 (message "%s" (buffer-string)))
77 (kill-buffer errbuf))))
78 (setq gnus-newsgroup-last-folder folder)))
79
80(defun gnus-mail-reply-using-mhe (&optional yank)
81 "Compose reply mail using mh-e.
82Optional argument YANK means yank original article.
83The command \\[mh-yank-cur-msg] yank the original message into current buffer."
84 (let (from cc subject date to reply-to to-userid orig-to
85 references message-id
86 (config (current-window-configuration))
87 buffer)
88 (pop-to-buffer gnus-article-buffer)
89 (setq buffer (current-buffer))
90 (save-excursion
91 (save-restriction
92 (or gnus-user-login-name ; we need this
93 (setq gnus-user-login-name (or (getenv "USER")
94 (getenv "LOGNAME"))))
95
96 (gnus-article-show-all-headers);; so colors are happy
97 ;; lots of junk to avoid mh-send deleting other windows
98 (setq from (or (gnus-fetch-field "from") "")
99 subject (let ((subject (or (gnus-fetch-field "subject")
100 "(None)")))
101 (if (and subject
102 (not (string-match "^[Rr][Ee]:.+$" subject)))
103 (concat "Re: " subject) subject))
104 reply-to (gnus-fetch-field "reply-to")
105 cc (gnus-fetch-field "cc")
106 orig-to (or (gnus-fetch-field "to") "")
107 date (gnus-fetch-field "date")
108 references (gnus-fetch-field "references")
109 message-id (gnus-fetch-field "message-id"))
110 (setq to (or reply-to from))
111 (setq to-userid (mail-strip-quoted-names orig-to))
112 (if (or (string-match "," orig-to)
113 (not (string-match (substring to-userid 0
114 (string-match "@" to-userid))
115 gnus-user-login-name)))
116 (setq cc (concat (if cc (concat cc ", ") "") orig-to)))
117 ;; mh-yank-cur-msg needs to have mh-show-buffer set in the
118 ;; *Article* buffer
119 (setq mh-show-buffer buffer)))
120
121 (mh-find-path)
122 (mh-send-sub (or to "") (or cc "")
123 (or subject "(None)") config);; Erik Selberg 1/23/94
124
125 (let ((draft (current-buffer))
126 (gnus-mail-buffer (current-buffer))
127 mail-buf)
128 (if (not yank)
129 (gnus-configure-windows 'reply 'force)
130 (gnus-configure-windows 'reply-yank 'force))
131 (setq mail-buf gnus-mail-buffer)
132 (pop-to-buffer mail-buf);; always in the display, so won't have window probs
133 (switch-to-buffer draft))
134
135 ;; (mh-send to (or cc "") subject);; shouldn't use according to mhe
136
137 ;; note - current buffer is now draft!
138 (save-excursion
139 (mh-insert-fields
140 "In-reply-to:"
141 (concat
142 (substring from 0 (string-match " *at \\| *@ \\| *(\\| *<" from))
143 "'s message of " date))
144 (nnheader-insert-references references message-id))
145
146 ;; need this for mh-yank-cur-msg
147 (setq mh-sent-from-folder buffer)
148 (setq mh-sent-from-msg 1)
149 (setq mh-show-buffer buffer)
150 (setq mh-previous-window-config config))
151
152 ;; Then, yank original article if requested.
153 (if yank
154 (let ((last (point)))
155 (mh-yank-cur-msg)
156 (goto-char last)))
157
158 (run-hooks 'gnus-mail-hook))
159
160
161;; gnus-mail-forward-using-mhe is contributed by Jun-ichiro Itoh
162;; <itojun@ingram.mt.cs.keio.ac.jp>
163
164(defun gnus-mail-forward-using-mhe (&optional buffer)
165 "Forward the current message to another user using mh-e."
166 ;; First of all, prepare mhe mail buffer.
167 (let* ((to (read-string "To: "))
168 (cc (read-string "Cc: "))
169 (buffer (or buffer gnus-article-buffer))
170 (config (current-window-configuration));; need to add this - erik
171 (subject (gnus-forward-make-subject buffer)))
172 (setq mh-show-buffer buffer)
173 (mh-find-path)
174 (mh-send-sub to (or cc "") (or subject "(None)") config);; Erik Selberg 1/23/94
175 (let ((draft (current-buffer))
176 (gnus-mail-buffer (current-buffer))
177 mail-buf)
178 (gnus-configure-windows 'reply-yank 'force)
179 (setq mail-buf (eval (cdr (assq 'mail gnus-window-to-buffer))))
180 (pop-to-buffer mail-buf);; always in the display, so won't have window probs
181 (switch-to-buffer draft)
182 )
183 (save-excursion
184 (goto-char (point-max))
185 (insert "\n------- Forwarded Message\n\n")
186 (insert-buffer buffer)
187 (goto-char (point-max))
188 (insert "\n------- End of Forwarded Message\n")
189 (setq mh-sent-from-folder buffer)
190 (setq mh-sent-from-msg 1)
191 (setq mh-previous-window-config config)
192 (run-hooks 'gnus-mail-hook)
193 )))
194
195(defun gnus-mail-other-window-using-mhe ()
196 "Compose mail other window using mh-e."
197 (let ((to (read-string "To: "))
198 (cc (read-string "Cc: "))
199 (subject (read-string "Subject: ")))
200 (gnus-article-show-all-headers) ;I don't think this is really needed.
201 (setq mh-show-buffer (current-buffer))
202 (mh-find-path)
203 (mh-send-other-window to cc subject)
204 (setq mh-sent-from-folder (current-buffer))
205 (setq mh-sent-from-msg 1)
206 (run-hooks 'gnus-mail-hook)))
207
208(defun gnus-Folder-save-name (newsgroup headers &optional last-folder)
209 "Generate folder name from NEWSGROUP, HEADERS, and optional LAST-FOLDER.
210If variable `gnus-use-long-file-name' is nil, it is +News.group.
211Otherwise, it is like +news/group."
212 (or last-folder
213 (concat "+"
214 (if gnus-use-long-file-name
215 (gnus-capitalize-newsgroup newsgroup)
216 (gnus-newsgroup-directory-form newsgroup)))))
217
218(defun gnus-folder-save-name (newsgroup headers &optional last-folder)
219 "Generate folder name from NEWSGROUP, HEADERS, and optional LAST-FOLDER.
220If variable `gnus-use-long-file-name' is nil, it is +news.group.
221Otherwise, it is like +news/group."
222 (or last-folder
223 (concat "+"
224 (if gnus-use-long-file-name
225 newsgroup
226 (gnus-newsgroup-directory-form newsgroup)))))
227
228;;; gnus-mh.el ends here